简体   繁体   中英

Protractor not waiting for page load Angular4

I have been running protractor but have to put in a

browser.sleep(1000) and a browser.ignoreSynchronization = true to make it run, especially after a login or so, otherwise it doesn't get the page.

I know that browser.sleep isn't a recommended practice which is why I ask.

The problem with browser.sleep is when an action of your software needs more time then specified your test will fail. Another problem is if you're using a lot of browser.sleep s your test can be very slow, because the test is waiting for the whole time you have specified in browser.sleep . But there are of course situation where you need to use browser.sleep , but there are not many, in my opinion.

A better solution to wait for elements is the browser.wait function with Expected Conditions . browser.wait gets a method as argument, which would return true if a specific condition becomes true, and it waits as long as the function is not resolved or the timeout is reached.

Example:

var EC = protractor.ExpectedConditions;

var button = element(by.id('submitLogin'));
// Waits max. 10 seconds for the button to become clickable
browser.wait(EC.elementToBeClickable(button), 10000); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM