有没有办法期望元素最终出现在页面上?例如一种方式
browser.wait(protractor.ExpectedConditions.presenceOf(element(by.partialLinkText('Continue'))), 1000, 'Unable to find continue link');
因预期错误而不是超时而失败?本质上是一种拥有isEventuallyPresent()
代替isPresent()
在下面一行
expect(element(by.partialLinkText('Continue')).isPresent()).toBe(true);
作为参考,我正在使用browser.ignoreSynchronization = true
即使它是一个 Angular 应用程序,并且使用 Jasmine(至少现在是这样)。
利用以下事实
browser.wait http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.wait返回一个 Promise,一旦条件函数返回 true,该 Promise 就会被解决;如果超时则被拒绝。
If expect https://github.com/angular/jasminewd#features传递了一个 Promise,它只在 Promise 得到解决时才运行期望
您可以创建一个函数来包装对browser.wait
function eventual(expectedCondition) {
return browser.wait(expectedCondition, 2000).then(function() {
return true;
}, function() {
return false;
});
}
然后创造一个期望
expect(eventual(protractor.ExpectedConditions.presenceOf(element(by.partialLinkText('Continue'))))).toBe(true);
或者,要使其在任何浏览器实例上工作,您可以对 Protractor 原型进行猴子修补
protractor.Protractor.prototype.eventual = function(expectedCondition) {
return this.wait(expectedCondition, 2000).then(function() {
return true;
}, function() {
return false;
});
}
并可以用作
expect(browser.eventual(protractor.ExpectedConditions.presenceOf(element(by.partialLinkText('Continue'))))).toBe(true);
为了避免超时,您必须确保超时传递给browser.wait
小于 Jasmine 异步测试超时,指定为jasmineNodeOpts: {defaultTimeoutInterval: timeout_in_millis} https://github.com/angular/protractor/blob/master/docs/timeouts.md#timeouts-from-jasmine在量角器配置文件中
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)