I write a short code for browser automation testing on my website, browse random part of the website and just basic navigation, i want a small delay between the navigation. But setTimeout(); aint gonna cut it because when browse(); it skipped all setTimeout(); in sequence and i cant get it to work.
function findError() {
if (window.find('Error')) {
window.location.reload();
}
}
function browse(url) {
window.location.assign(url);
}
function click (x,y) {
document.elementFromPoint(x,y).click();
}
var funcs = [
func1,
func2
]
function execute() {
var i = Math.floor(Math.random() * funcs.length)
funcs.splice(i-1, 1)[0]()
}
for ( var i = 0; i < 30; i++ ) {
function func1() {
browse('https://google.com')
setTimeout(function() {findError();}, 10000);
setTimeout(function() {click(420,540);}, 20000);
}
function func2() {
browse('https://netflix.com');
setTimeout(function() {findError();}, 10000);
setTimeout(function() {click(1210,310);}, 20000);
}
setTimeout(function() {execute();}, 40000);
}
I have tried to use this delay but it only work on top of body modules, not in another function
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
await sleep (ms);
Do you have any idea ? Please help me