我正在使用量角器进行e2e测试。目前,我正在使用很多工作流超时。我想用browser.wait
替换它。问题是我并不总是知道要等待什么。例如切换到其他画面时。
这个特定的问题是等待中继器元素显示。
这是我当前的代码:
flow.timeout(5000);
element.all(by.repeater('whatsNewItem in homePageWhatsNewItems')).count().then(function (firstCount) {
console.log("number of WhatsNew=" + firstCount);
expect(firstCount >= 5).toBeTruthy();
});
我想替换
flow.timeout
中的browser.wait(.....)
有任何想法吗?
最佳答案
如果您知道要等待的元素,则易于使用量角器的ExpectedConditions
来等待元素出现在页面上。这是如何做 -
var EC = protractor.ExpectedConditions;
var repeaterElement = element(by.repeater('whatsNewItem in homePageWhatsNewItems'));
//Wait up to 10 seconds for elements to be visible
browser.wait(EC.visibilityOf(repeaterElement), 10000)
.then(function(){
//Perform any operation that you want after waiting for the element to appear
});
如果您根本不知道要等待哪个元素,请始终检查最后加载的元素,然后等待该元素出现。通过这种方式,可以避免错误。希望能帮助到你。