简体   繁体   English

如何从Protractor中的browser.wait()返回ElementFinder?

[英]How to return ElementFinder from browser.wait() in Protractor?

In my test cases I'm trying to implement helper for check array of elements before return some items. 在我的测试用例中,我试图在返回一些项目之前为check元素数组实现帮助。 If array does not contains element - I need to wait (I have some troubles with performance of application, sometimes elements in lists are loading too long and synchronization not working). 如果数组不包含元素 - 我需要等待(我有一些应用程序性能的麻烦,有时列表中的元素加载太长而同步不起作用)。

Function in my helper: 我的助手的功能:

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;
    })
}

Then I use it: 然后我用它:

let row = helper.getElementFromArray(rowsCatalog, indexRow);
row.getText();

But I'm getting error, because browser.wait() returns ManagedPromise instead of ElementFinder . 但我收到错误,因为browser.wait()返回ManagedPromise而不是ElementFinder

I really do not want to use helpers functions as promises, because it will make the code is very complicated and unreadable (the example above - the simplest case). 我真的不想使用helpers函数作为promises,因为它会使代码非常复杂和不可读(上面的例子 - 最简单的情况)。

Not sure if this is applicable in your case, but you can return after the browser.wait() : 不确定这是否适用于您的情况,但您可以在browser.wait()之后返回:

getElementFromArray(array, elementIndex) {
    browser.wait(() => {
        return array.count((count) => {
            return count > elementIndex;
        });
    }, 10000);

    return array.get(elementIndex);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM