mardi 5 avril 2016

Selenium : Handle a window that popups up ramdomly

We have a feature that collects customer feedback. For this , when the user logs out , a window popups up randomly - not every time for every customer. I want to handle this in my automation code.

Currently, at the log out, I'm expecting a window and switching to it and that code is failing when the popup window doesn't show up.

What's the best way to handle this .

This is what I have so far ...

    public static void waitForNumberOfWindowsToEqual(final int numberOfWindows) {


    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            return (driver.getWindowHandles().size() == numberOfWindows);
        }
    };

    WebDriverWait wait = new WebDriverWait(driver, BrowserFactory.explicitWait);


    wait.until(expectation);
}




Aucun commentaire:

Enregistrer un commentaire