简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM