Search code examples
javascripttestingprotractorwaitend-to-end

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

Solution

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