How to wait browser on protractor e2e test?

374 Views Asked by At

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.

2

There are 2 best solutions below

3
holydragon On BEST ANSWER

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.

0
DublinDev On

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'
)