'Protractor browser.sleep() is not getting executed
In the below as you can see that the browser.sleep is supposed to be executed if the client is XYZ, but still it is not getting executed.
If i put any console.log after the browser.sleep statement, that statement is getting executed (i can see the statement) but the browser.sleep is not really waiting even though how much the sleep time i increase.
Why is the browser.sleep is not working? How do i make it wait if the client XYZ?
if (testproperties.client == 'ABC'){
browser.ignoreSynchronization = false;
browser.waitForAngular();
browser.ignoreSynchronization = true;
}
else if (testproperties.client == 'XYZ'){
browser.sleep('35000');
};
Solution 1:[1]
Do you passing int type as parameter? Seems like it is string. Try
browser.sleep(35000)
Also check why you might need such huge browser sleep? Maybe you want browser.wait() instead?
Solution 2:[2]
put await in front of browser and pass a parameter to sleep (time in ms).
await browser.sleep(5000);
Solution 3:[3]
Try resolving the promise.
browser.sleep(35000).then(
function(){
console.log("Waiting");
}
)
Or update protractor to the last version
npm install protractor@latest --save
Solution 4:[4]
Try following answer.
if (testproperties.client == 'ABC'){
browser.ignoreSynchronization = false;
browser.driver.sleep(2000);
browser.ignoreSynchronization = true;
}
else if (testproperties.client == 'XYZ'){
browser.driver.sleep(2000);
};
Hope this helps. :)
Solution 5:[5]
Please give it a try with below code sample .
//For none angular sites
browser.driver.ignoreSynchronization = true;
browser.waitForAngularEnabled(false);
//browser.get('url');
//If normal browser.sleep(7000); didnt work try
browser.driver.sleep(8000);
//click using ID instead of Javasctipt
element(by.id('next')).click()
Solution 6:[6]
If you launch protractor with headless parameter browser.sleep() cannot works.
Remove this parameter and enjoy.
Solution 7:[7]
browser.sleep() should be executed with sync mode instead of async
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xotabu4 |
| Solution 2 | Pranawa Mishra |
| Solution 3 | Oscar |
| Solution 4 | Manuli |
| Solution 5 | Sameera De Silva |
| Solution 6 | Arthur Beaucamp |
| Solution 7 | M András |
