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

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

Introduction

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

Prototype

public static ExpectedCondition<Alert> alertIsPresent() 

Source Link

Usage

From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java

License:Open Source License

@Override
public String getAlert() {
    switchTo();//from ww  w. ja va2s .c o  m

    WebDriverWait webDriverWait = new WebDriverWait(this, 1);

    Alert alert = webDriverWait.until(ExpectedConditions.alertIsPresent());

    return alert.getText();
}

From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java

License:Open Source License

@Override
public boolean isAlertPresent() {
    boolean alertPresent = false;

    switchTo();/*  w w w  .  j a v a2  s .c o m*/

    try {
        WebDriverWait webDriverWait = new WebDriverWait(this, 1);

        webDriverWait.until(ExpectedConditions.alertIsPresent());

        alertPresent = true;
    } catch (Exception e) {
        alertPresent = false;
    }

    return alertPresent;
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static String getConfirmation(WebDriver webDriver) {
    webDriver.switchTo();//from  w w  w .  j a va2  s . c om

    WebDriverWait webDriverWait = new WebDriverWait(webDriver, 1);

    try {
        Alert alert = webDriverWait.until(ExpectedConditions.alertIsPresent());

        String confirmation = alert.getText();

        alert.accept();

        return confirmation;
    } catch (Exception e) {
        throw new WebDriverException();
    }
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

protected static boolean isAlertPresent(WebDriver webDriver) {
    WebDriverWait webDriverWait = new WebDriverWait(webDriver, 1);

    try {/*from   ww w. jav  a  2  s  .c o m*/
        webDriverWait.until(ExpectedConditions.alertIsPresent());

        return true;
    } catch (org.openqa.selenium.TimeoutException te) {
        return false;
    }
}

From source file:com.mkl.websuites.internal.command.impl.wait.WaitForAlertCommand.java

License:Apache License

@Override
protected void runStandardCommand() {

    WebDriverWait wait = new WebDriverWait(browser, getWebElementWaitTimeout());

    wait.until(ExpectedConditions.alertIsPresent());
}

From source file:com.pentaho.ctools.cda.CDACacheManager.java

License:Apache License

/**
 * ############################### Test Case 2 ###############################
 *
 * Test Case Name:/*from ww w  .  java 2  s .c  om*/
 *    Clean Cache
 * Description:
 *    The test case pretends to validate the clean cache functionality.
 * Steps:
 *    1. Press to clear cache
 *    2. Check no query is listed
 */
@Test
public void tc2_ClearCache_AllQueriesWhereRemove() {
    this.log.info("tc2_ClearCache_AllQueriesWhereRemove");

    //Go to Cached Queries
    WebElement buttonCachedQueries = this.elemHelper.FindElement(driver, By.id("cacheButton"));
    assertNotNull(buttonCachedQueries);
    buttonCachedQueries.click();

    //Click in clear cache
    this.elemHelper.FindElement(driver, By.id("clearCacheButton")).click();

    /*
     * ## Step 1
     */
    //Wait for pop-up 1
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "This will remove ALL items from cache. Are you sure?";
    alert.accept();
    assertEquals(confirmationMsg, expectedCnfText);

    //Wait for pop-up 2
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    expectedCnfText = "items have been removed from cache";
    alert.accept();
    assertThat("The displayed popup: " + confirmationMsg, confirmationMsg,
            CoreMatchers.containsString(expectedCnfText));

    /*
     * ## Step 2
     */
    String textEmptyCache = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='cachedQueriesOverviewLines']/div"));
    assertEquals("Cache is empty.", textEmptyCache);
}

From source file:com.pentaho.ctools.cdf.CheckComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:/*  w  ww .j  a  va 2s . c  o m*/
 *    Check options
 * Description:
 *    Here we pretend to check each option one by one and validate if an alert
 *    is raised with correct message.
 * Steps:
 *    1. Check in Southern and validate alert
 *    2. Check in Eastern and validate alert
 *    3. Check in Central and validate alert
 *    4. Check in Western and validate alert
 */
@Test
public void tc3_CheckEachOption_AfterCheckAnAlertIsDisplayed() {
    this.log.info("tc3_CheckEachOption_AfterCheckAnAlertIsDisplayed");
    String confirmationMsg = "";
    // ## Step 1
    //Click in Southern
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Southern']"));

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern", confirmationMsg);

    // ## Step 2
    //Click in Eastern
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Eastern']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern,Eastern", confirmationMsg);

    // ## Step 3
    //Click in Central
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Central']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern,Eastern,Central", confirmationMsg);

    // ## Step 4
    //Click in Western
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Western']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern,Eastern,Central,Western", confirmationMsg);
}

From source file:com.pentaho.ctools.cdf.CheckComponent.java

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name:/* w  ww.  j  av a2 s .  co m*/
 *    Unchecked options
 * Description:
 *    Here we pretend to unchecked each option one by one and validate if an
 *    alert is raised with correct message.
 * Steps:
 *    1. Unchecked Southern and validate alert
 *    2. Unchecked Eastern and validate alert
 *    3. Unchecked Central and validate alert
 *    4. Unchecked Western and validate alert
 */
@Test
public void tc4_UncheckedEachOption_AfterUncheckAnAlertIsDisplayed() {
    this.log.info("tc4_UncheckedEachOption_AfterUncheckAnAlertIsDisplayed");
    String confirmationMsg = "";
    // ## Step 1
    //Click in Southern
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Southern']"));

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Eastern,Central,Western", confirmationMsg);

    // ## Step 2
    //Click in Eastern
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Eastern']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central,Western", confirmationMsg);

    // ## Step 3
    //Click in Central
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Central']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Western", confirmationMsg);

    // ## Step 4
    //Click in Western
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Western']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: ", confirmationMsg);
}

From source file:com.pentaho.ctools.cdf.CheckComponent.java

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:/*ww w.  ja va2 s  .c  o m*/
 *    Check and Unchecked Arbitrary
 * Description:
 *    Here we pretend to check and unchecked arbitrary and validate the alert
 *    message according each action (check and unchecked).
 * Steps:
 *    1. Check and unchecked arbitrary, and validate alert message
 */
@Test
public void tc5_UncheckedEachOption_AfterUncheckAnAlertIsDisplayed() {
    this.log.info("tc5_UncheckedEachOption_AfterUncheckAnAlertIsDisplayed");
    String confirmationMsg = "";
    //Click in Central
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Central']"));

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central", confirmationMsg);

    //Click in Southern
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Southern']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern,Central", confirmationMsg);

    //UnChecked Southern
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Southern']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central", confirmationMsg);

    //Click in Western
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Western']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central,Western", confirmationMsg);

    //Click in Western
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Eastern']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Eastern,Central,Western", confirmationMsg);

    //Unchecked Central
    this.elemHelper.ClickJS(driver, By.xpath("//input[@name='regionSelector' and @value='Central']"));

    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Eastern,Western", confirmationMsg);
}

From source file:com.pentaho.ctools.cdf.DateInputComponent.java

License:Apache License

/**
 * ############################### Test Case 1 ###############################
 *
 * Test Case Name://  www . ja  v a  2 s  .  c  o  m
 *    DateInputComponent
 * Description:
 *    We pretend to check the component when user pick a data an alert message
 *    is displayed indicating the date picked.
 * Steps:
 *    1. Go to Pentaho solution web page.
 *    2. Render the component again.
 *    3. Choose the date '2011-10-23'.
 */
@Test
public void tc1_DataInput_DisplayPopupWithPickedDate() {
    this.log.info("tc1_DataInput_DisplayPopupWithPickedDate");
    /*
     * ## Step 1
     */
    driver.get(PageUrl.DATEINPUT_COMPONENT);

    //NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));

    //Wait for visibility of 'DateInputComponent'
    this.elemHelper.WaitForElementVisibility(driver,
            By.xpath("//div[@id='dashboardContent']/div/div/div/h2/span[2]"));
    // Validate the sample that we are testing is the one
    assertEquals("Community Dashboard Framework", driver.getTitle());
    assertEquals("DateInputComponent", this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='dashboardContent']/div/div/div/h2/span[2]")));

    /*
     * ## Step 2
     */
    //Render again the sample
    this.elemHelper.ClickJS(driver, By.xpath("//div[@id='example']/ul/li[2]/a"));
    this.elemHelper.ClickJS(driver, By.xpath("//div[@id='code']/button"));
    //NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));
    //Now sample element must be displayed
    assertTrue(this.elemHelper.FindElement(driver, By.id("sample")).isDisplayed());

    /*
     * ## Step 3
     */
    //Pick a date
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("myInput"));
    this.elemHelper.FindElement(driver, By.id("myInput")).sendKeys("''");

    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("ui-datepicker-div"));
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.className("ui-datepicker-month"));
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.className("ui-datepicker-year"));
    Select month = new Select(this.elemHelper.FindElement(driver, By.className("ui-datepicker-month")));
    month.selectByValue("9");
    Select year = new Select(this.elemHelper.FindElement(driver, By.className("ui-datepicker-year")));
    year.selectByValue("2011");
    //Day 23
    this.elemHelper.FindElement(driver, By.xpath("//table[@class='ui-datepicker-calendar']//tbody//tr[5]/td/a"))
            .sendKeys(Keys.ENTER);

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();

    /*##########################################################################
      EXPECTED RESULT:
      - The popup alert shall displayed the data picked.
     #########################################################################*/
    assertEquals(confirmationMsg, "You chose: 2011-10-23");
}