user2880391
user2880391

Reputation: 2791

Protractor - wait after switch to window or iframe

I'm trying to replace 'timeouts' or 'Sleeps' with 'wait' for the test to be faster. I was not able to find the right way to wait for switching to window or iframe that doesn't have identifier.

For example:

browser.sleep(5000);
browser.driver.switchTo().window(handles[0]).then(function() {
    // login.logout();
});

and:

flow.timeout(5000);

browser.switchTo().frame(0);

Upvotes: 1

Views: 2915

Answers (1)

alecxe
alecxe

Reputation: 473833

I've recently solved something quite similar with a custom Expected Condition that checks for a specified number of window handles:

function windowCount (count) {
    return function () {
        return browser.getAllWindowHandles().then(function (handles) {
            return handles.length === count;
        });
    };
}; 

Usage:

browser.wait(windowCount(2), 5000);

Upvotes: 3

Related Questions