Example usage for org.openqa.selenium.support.ui ExpectedConditions numberOfWindowsToBe

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions numberOfWindowsToBe

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions numberOfWindowsToBe.

Prototype

public static ExpectedCondition<Boolean> numberOfWindowsToBe(final int expectedNumberOfWindows) 

Source Link

Usage

From source file:io.github.bonigarcia.wdm.test.OpenNewTabChromeTest.java

License:Apache License

@Test
public void test() throws Exception {
    // Open URL in default tab
    driver.get("https://wikipedia.org/");

    // If Mac OS X, the key combination is CMD+t, otherwise is CONTROL+t
    int vkControl = IS_OS_MAC ? KeyEvent.VK_META : KeyEvent.VK_CONTROL;
    Robot robot = new Robot();
    robot.keyPress(vkControl);/*from www  . j a va2 s. c  o m*/
    robot.keyPress(KeyEvent.VK_T);
    robot.keyRelease(vkControl);
    robot.keyRelease(KeyEvent.VK_T);

    // Wait up to 5 seconds to the second tab to be opened
    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.numberOfWindowsToBe(2));

    // Switch to new tab
    List<String> windowHandles = new ArrayList<>(driver.getWindowHandles());
    System.err.println(windowHandles);
    driver.switchTo().window(windowHandles.get(1));

    // Open other URL in second tab
    driver.get("https://google.com/");
}

From source file:litecartAdmin.Task14ExternalLinks.java

@Test
public void OpenLinksTest() {
    new AdminLoginPage(driver).login();
    driver.get("http://litecart.resscode.org.ua/admin/?app=countries&doc=edit_country&country_code=AF");
    List<WebElement> links = driver.findElements(By.className("fa-external-link"));
    String mainWindow = driver.getWindowHandle();
    Set<String> allOpenedWindows = driver.getWindowHandles();
    for (WebElement link : links) {
        link.click();/*from   w w  w .j  av  a  2  s .  c o  m*/
        WebDriverWait wait = new WebDriverWait(driver, TestConstants.EXPLICIT_WAIT_SECONDS);
        wait.until(ExpectedConditions.numberOfWindowsToBe(allOpenedWindows.size() + 1));
        Set<String> allWindows = driver.getWindowHandles();
        allWindows.removeAll(allOpenedWindows);
        driver.switchTo().window(allWindows.iterator().next());
        driver.close();
        driver.switchTo().window(mainWindow);
    }
}

From source file:net.thucydides.productionvalidation.junit.pages.ValidationPage.java

public void clickOnCaptionedReportLink() {
    validateBrowserReady();/* ww w  .  j a v a 2 s .com*/
    waitUntilElementVisible(captioned_report_link);
    captioned_report_link.waitUntilVisible();
    clickWhenReady(captioned_report_link);
    //captioned_report_link.click();
    evaluateJavascript("document.getElementById('ctl00_IdSiteMap_treeLeftMenut9').click();");
    waitForTimeout(5000);
    withTimeoutOf(120, TimeUnit.SECONDS).waitFor(ExpectedConditions.numberOfWindowsToBe(2));
    Object[] arrWindows = getDriver().getWindowHandles().toArray();
    getDriver().switchTo().window(arrWindows[1].toString());
    waitForTimeout(12000);
    validateBrowserReady();
    waitUntilElementVisible(captioned_report_close_btn);
    waitUntilElementVisible(captioned_report_close_btn);
    captioned_report_close_btn.waitUntilVisible();
    //evaluateJavascript("document.getElementById('ctl00_SPWebPM_CaptionReportWP1_ctl00_btClose').click();");
    getDriver().switchTo().window(arrWindows[1].toString()).close();
    withTimeoutOf(500, TimeUnit.SECONDS).waitFor(ExpectedConditions.numberOfWindowsToBe(1));
    getDriver().switchTo().window(arrWindows[0].toString());
    waitForTimeout(5000);
    System.out.println("clickOnCaptionedReportLink Passed");
}

From source file:net.thucydides.productionvalidation.junit.pages.ValidationPage.java

public void clickOnAddNotesLink() {
    validateBrowserReady();/*from   w w w  .  j  av  a2s.c o  m*/
    waitUntilElementVisible(add_notes_link);
    clickWhenReady(add_notes_link);
    //add_notes_link.click();
    evaluateJavascript("document.getElementById('ctl00_IdSiteMap_treeLeftMenut26').click();");
    waitForTimeout(5000);
    withTimeoutOf(120, TimeUnit.SECONDS).waitFor(ExpectedConditions.numberOfWindowsToBe(2));
    Object[] arrWindows = getDriver().getWindowHandles().toArray();
    System.out.println("clickOnAddNotesLink - Number of windows :" + arrWindows.length);
    getDriver().switchTo().window(arrWindows[1].toString());
    waitForTimeout(12000);
    validateBrowserReady();
    waitUntilElementVisible(cancel_add_notes_btn);
    waitUntilElementVisible(cancel_add_notes_btn);
    cancel_add_notes_btn.waitUntilVisible();
    //    evaluateJavascript("document.getElementById('ctl00_SPWebPM_AddNotesWP1_ctl00_btnCancelDown').isDisplayed();");  
    getDriver().switchTo().window(arrWindows[1].toString()).close();
    withTimeoutOf(500, TimeUnit.SECONDS).waitFor(ExpectedConditions.numberOfWindowsToBe(1));
    getDriver().switchTo().window(arrWindows[0].toString());
    waitForTimeout(5000);
    System.out.println("Add Notes Passed");
}

From source file:net.thucydides.productionvalidation.junit.pages.ValidationPage.java

public void clickOnSalvageLink() {
    validateBrowserReady();/*from  w  ww .  j ava 2s . c  o m*/
    waitUntilElementVisible(salvage_link);
    salvage_link.waitUntilVisible();
    clickWhenReady(salvage_link);
    //salvage_link.click();
    evaluateJavascript("document.getElementById('ctl00_IdSiteMap_treeLeftMenut31').click();");
    waitForTimeout(12000);
    withTimeoutOf(120, TimeUnit.SECONDS).waitFor(ExpectedConditions.numberOfWindowsToBe(2));
    Object[] arrWindows = getDriver().getWindowHandles().toArray();
    System.out.println("clickOnSalvageLink - Number of windows :" + arrWindows.length);
    getDriver().switchTo().window(arrWindows[1].toString());
    waitForTimeout(15000);
    validateBrowserReady();
    waitUntilElementVisible(go_to_salvage_btn);
    waitUntilElementVisible(go_to_salvage_btn);
    go_to_salvage_btn.waitUntilVisible();
    go_to_salvage_btn.waitUntilEnabled();
    go_to_salvage_btn.waitUntilClickable();
    evaluateJavascript("document.getElementById('ctl00_SPWebPM_ClaimantPopUpWP1_ctl00_btnSalvage').click();");
    withTimeoutOf(500, TimeUnit.SECONDS).waitFor(ExpectedConditions.numberOfWindowsToBe(1));
    getDriver().switchTo().window(arrWindows[0].toString());
    waitForTimeout(6000);
    System.out.println("salvage Passed");
    validateBrowserReady();
    waitUntilElementVisible(salvage_details_save_btn);
    salvage_details_save_btn.waitUntilVisible();
    tlc_tab.waitUntilVisible();
    tlc_tab.waitUntilClickable();
    tlc_tab.click();
    processDialogs();
    validateBrowserReady();
    waitUntilElementVisible(tlc_save_btn);
    tlc_save_btn.waitUntilVisible();
}

From source file:org.awesomeagile.webapp.page.LandingPage.java

License:Apache License

public LandingPage viewDefinitionOfReady() {
    int windowCount = driver.getWindowHandles().size();
    viewDefinitionOfReadyButton.click();
    wait.until(ExpectedConditions.numberOfWindowsToBe(windowCount + 1));
    return this;
}

From source file:org.awesomeagile.webapp.page.LandingPage.java

License:Apache License

public LandingPage viewDefinitionOfDone() {
    int windowCount = driver.getWindowHandles().size();
    viewDefinitionOfDoneButton.click();// w  w  w. j  a v  a 2  s .co  m
    wait.until(ExpectedConditions.numberOfWindowsToBe(windowCount + 1));
    return this;
}