Protractor: 'wait' doesn't work with “element.all”

前端 未结 2 335
予麋鹿
予麋鹿 2021-01-12 02:08

I write Protractor automation tests and faced an issue. Wait command doesn\'t actually wait for one of the array elements. See the example below: I try to wait for the first

相关标签:
2条回答
  • 2021-01-12 02:26

    element.all(by.repeater('category in listCtrl.categories')).get(0) will ALWAYS throw an error if there are no elements to 'get' (source: element.js ElementArrayFinder.prototype.get)

    You can do:

    browser.wait(function() {
        return category.count().then(function(catCount) {
            if (catCount > 0) {
                return EC.visibilityOf(category.get(0));
            }
        }
    }, 20000);
    

    Or you could probably just wait until all the elements are visible, and it would do what you are asking it to do (because it will wait for the 'all' promise to resolve completely anyway, not just break out when it gets the first one):

    browser.wait(EC.visibilityOf(category), 20000);
    
    0 讨论(0)
  • 2021-01-12 02:39

    Make a custom Expected Condition to wait for count of elements in an array to be more than 0:

    function presenceOfAll(elementArrayFinder) {
        return function () {
            return elementArrayFinder.count(function (count) {
                return count > 0;
            });
        };
    }
    

    Usage:

    browser.wait(presenceOfAll(category), 10000);
    browser.wait(presenceOfAll(category2), 10000);
    

    Works for me.

    0 讨论(0)
提交回复
热议问题