简体   繁体   中英

How to wait browser on protractor e2e test?

I have a flaky test. Its about my loading screen. I use

await browser.wait(EC.invisibilityOf(...)); // It contains parameters.

await browser.sleep(2000);

But still sometimes it is work , it is not. I have a button. My test try button click on Loading screen therefore it fail. It must wait when loading screen was gone.(I tried using wait and sleep )

How I do resolve the problem. I need help.

It must wait when loading screen was gone

  1. Create a while loop.
  2. Check if the loading screen is gone
    • if true then do your thing
    • else wait
  3. Let the loop gets executed until the condition returns true

and by

if the loading screen is gone

You can check the CSS of the element of the loading screen. It can be

display: none;

or

visibility: hidden;

depends on how it is hidden.

Just because your loading screen is invisible does not mean the the next page has is ready to interact with. You can try waiting for the visibility of an element on the next page or try changing your sleep to await browser.driver.sleep(2000).

I would probably take an element from the page you expect to be loaded and try

await browser.wait(EC.presenceOf(reqElement), 5000,
   'reqElement not displayed on page after 5 seconds, loading screen may still be visible'
)

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