我尝试使用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); }
但是如果气球不存在,我会收到错误消息:3117ms后等待超时而不是预期true为假(present_pri == false)
我试着写:
var EC = protractor.ExpectedConditions; browser.wait(EC.presenceOf(balloon_warning),3000); expect(balloon_warning.isPresent()).toBeTruthy();
但我总是有同样的错误.我做错了什么?
解决方法
您需要处理等待超时错误:
browser.wait(EC.presenceOf(balloon_warning),3000).then(function () { // success handler },function (error) { expect(true).toBe(false); });