Protractor - Wait for a few items

I'm trying to wait for a few elements on a page, I don’t know how many there can be, but there will be at least one. I understand that one element is waiting, using the following, which works great.

var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceOf(element(by.css("h3[title='Test Form']"))), 10000);
    expect(element(by.css("h3[title='Test Form']")).isPresent()).toBeTruthy();

I wanted to change this a bit to wait for a few elements and therefore tried the following (adding .all to the element).

var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceOf(element.all(by.css("h3[title='Test Form']"))), 10000);
    expect(element.all(by.css("h3[title='Test Form']")).isPresent()).toBeTruthy();

Unfortunately, when I try to do this, I get

Cannot read property 'bind' of undefined

Any help on this would be greatly appreciated.

ps New to Protractor and his quirks.

+4
source share
1 answer

presenceOfexpects one element ( ElementFinder) to be passed.

. , , N . :

function waitForCount (elementArrayFinder, expectedCount) {
    return function () {
        return elementArrayFinder.count().then(function (actualCount) {
            return expectedCount === actualCount;  // or <= instead of ===, depending on the use case
        });
    };
};

:

var forms = element.all(by.css("h3[title='Test Form']"));
browser.wait(waitForCount(forms, 5), 10000);
+8

Source: https://habr.com/ru/post/1623320/


All Articles