Javascript 如何从量角器中的browser.wait()返回ElementFinder?
在我的测试用例中,我试图在返回一些项目之前实现检查元素数组的helper。若数组不包含元素—我需要等待(我对应用程序的性能有一些问题,有时列表中的元素加载太长,同步无法工作) “我的助手”中的函数:Javascript 如何从量角器中的browser.wait()返回ElementFinder?,javascript,angularjs,protractor,Javascript,Angularjs,Protractor,在我的测试用例中,我试图在返回一些项目之前实现检查元素数组的helper。若数组不包含元素—我需要等待(我对应用程序的性能有一些问题,有时列表中的元素加载太长,同步无法工作) “我的助手”中的函数: getElementFromArray(array, elementIndex) { return browser.wait(() => { return array.count((count) => { return count >
getElementFromArray(array, elementIndex) {
return browser.wait(() => {
return array.count((count) => {
return count > elementIndex;
});
}, 10000).then(() => {
return array.get(elementIndex);
}, () => {
console.log("Element in array does not exist.");
return null;
})
}
然后我用它:
let row = helper.getElementFromArray(rowsCatalog, indexRow);
row.getText();
但是我得到了错误,因为browser.wait()
返回ManagedPromise
而不是ElementFinder
我真的不想使用helpers函数作为承诺,因为它会使代码变得非常复杂和不可读(上面的示例是最简单的情况)。不确定这是否适用于您的情况,但您可以在
浏览器之后返回。wait()
:
不确定这是否适用于您的情况,但您可以在
浏览器之后返回。wait()
:
getElementFromArray(array, elementIndex) {
browser.wait(() => {
return array.count((count) => {
return count > elementIndex;
});
}, 10000);
return array.get(elementIndex);
}