简体   繁体   English

如何在量角器e2e测试中等待浏览器?

[英]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 ) 加载屏幕消失后必须等待。(我尝试使用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. 创建一个while循环。
  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. 您可以检查加载屏幕元素的CSS。 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). 您可以尝试等待下一页上某个元素的可见性,也可以尝试更改睡眠状态以等待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'
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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