【发布时间】:2015-10-27 23:21:00
【问题描述】:
我尝试使用 wait() 方法而不是 sleep(),但它不起作用。 我有代码:
browser.actions().click(filter_field).perform();
browser.sleep(3000);
if (baloon_info.isPresent()) { //some expections }
else { expect(true).toBe(false); }
现在我想做这样的事情:
var present_pri = browser.wait(function () {
return balloon_info.isPresent();
}, 3000);
if (present_pri) { //some expections }
else { expect(true).toBe(false); }
但如果气球不存在,我会收到错误消息:Wait timed out after 3117ms 而不是 expected true to be false (present_pri == false)
我试着写:
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(balloon_warning), 3000);
expect(balloon_warning.isPresent()).toBeTruthy();
但我总是有同样的错误。我做错了什么?
【问题讨论】:
-
第一种方法总是会失败,因为 browser.wait 返回的是一个承诺,而不是你所期望的布尔值。(阅读 API 文档了解更多信息)
标签: angularjs asynchronous timeout jasmine protractor