mightflypig
mightflypig

Reputation: 93

Protractor : How to wait for all elements to become invisible

I have a web application that I'm testing with Protractor. Unfortunately, when it's loading, various areas of the application can each display an overlapping loading spinner. So I want a wait that waits until all of the spinners become invisible before I continue. The spinners become invisible rather than disappearing from the DOM completely.

Here is what I have come up so far. Unfortunately it always runs until the wait times out.

function waitForAllElementsToDisappear(elementArray) {
    return function () {
        return elementArray.reduce(function (acc, elem) {
            if (acc == null) acc = true; 
            try {
                return elem.isDisplayed().then(function(displayValue) {
                    if (displayValue)  return false; 
                    else  return acc; 
                });
            }
            catch (err) {
                return acc;
            }
        });
    };
};

browser.wait(this.waitForAllElementsToDisappear(
    element.all(by.css('div[ng-if~="mmc.menuTree.showSpinner"]'))), 
    5000);

Hopefully this is just way too complicated and there is a nice elegant solution.

Thanks for the help.

Upvotes: 0

Views: 526

Answers (1)

yong
yong

Reputation: 13712

There are some wrong place in the function waitForAllElementsToDisappear:

function waitForAllElementsToDisappear(elementArray) {

    return elementArray.isDisplayed().then(function(arrs){
        // arrs is an array like [true, false, false, true]
        // when there is no true in the array, means all spinners are not visible
        // we can end the waiting now
        return arrs.includes(true) === false
    });

};

Upvotes: 1

Related Questions