browser.sleep()和browser.wait()方法之间有什么区别? [英] What is the difference between browser.sleep() and browser.wait() methods?

查看:109
本文介绍了browser.sleep()和browser.wait()方法之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

面对量角器的计时问题.有时我的量角器测试用例由于网络或性能问题而失败.我已经解决了browser.sleep()的现有问题.后来我才知道关于browser.wait().

Facing timing issue with protractor. sometimes my protractor test cases fails due to network or performance issues. I have solved existing issues with browser.sleep(). Later I came to know about browser.wait().

它们之间有什么区别,哪一个更适合解决网络或性能问题.

What is the difference between them and which one is better for solving network or performance issues.

推荐答案

当涉及到计时问题时,放置快速" browser.sleep()并继续前进是很诱人且容易的.

When it comes to dealing with timing issue, it is tempting and easy to put a "quick" browser.sleep() and move on.

问题是,有朝一日可能会失败.没有设置什么睡眠超时的黄金/通用规则,因此,在某些时候,由于网络,性能或其他问题,页面加载或元素可见可能需要更多时间.此外,大多数时间,您最终将比实际需要的更多.

The problem is, it would some day fail. There is no golden/generic rule on what sleep timeout to set and, hence, at some point due to network or performance or other issues, it might take more time for a page to load or element to become visible etc. Plus, most of the time, you would end up waiting more than you actually should.

另一边是

browser.wait()手的工作方式有所不同.您提供一个期望条件函数,以便Protractor/WebDriverJS执行并等待结果函数评估为真.量角器将连续执行该函数,并在函数结果评估为true或达到可配置的超时后停止.

browser.wait() on the other hand works differently. You provide an Expected Condition function for Protractor/WebDriverJS to execute and wait for the result of the function to evaluate to true. Protractor would continuously execute the function and stop once the result of the function evaluates to true or a configurable timeout has been reached.

有多个内置的预期条件,但您也可以创建和使用自定义条件(示例

There are multiple built-in Expected Conditions, but you can also create and use a custom one (sample here).

这篇关于browser.sleep()和browser.wait()方法之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆