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.pentaho.ctools.cdf.DateRangeInputComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name://w ww. jav  a 2s .  c  o m
 *    Set Date Range Today
 * Description:
 *    When click on Today option an alert is displayed with today date in
 *    range interval.
 * Steps:
 *    1. Click in Today option
 *    2. Check for Alert
 */
@Test
public void tc3_Today_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("Today")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date dNow = new Date();
    String strToday = sdf.format(dNow);

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + strToday + " to " + strToday;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name:/* w w  w.ja  va2s. c  om*/
 *    Set Date Range for the Last Seven Days.
 * Description:
 *    When click on Last 7 Days option an alert is displayed with 7 days
 *    before today and the today date.
 * Steps:
 *    1. Click in Last 7 Days option
 *    2. Check for Alert
 */
@Test
public void tc4_LastSevenDays_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("Last 7 days")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_MONTH, -7);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date dNow = new Date();
    String strToday = sdf.format(dNow);

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + sdf.format(c.getTime()) + " to " + strToday;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:/*from w  w  w  .  j  av a2 s  . co  m*/
 *    Set Date Range Month to Today date
 * Description:
 *    When click on Month to date option an alert is displayed with begin
 *    month day to today date.
 * Steps:
 *    1. Click in Month to date option
 *    2. Check for Alert
 */
@Test
public void tc5_MonthToDate_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("Month to date")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM");
    Date dNow = new Date();
    String strToday = sdf.format(dNow);
    String strCurrentMonth = sdfMonth.format(dNow) + "-01";

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + strCurrentMonth + " to " + strToday;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 6 ###############################
 *
 * Test Case Name://from  ww w.  j a v a 2  s  .  c o  m
 *    Set Date Range Year To Date
 * Description:
 *    When click on Year To Date option an alert is displayed with begin year
 *    date to today date in range interval.
 * Steps:
 *    1. Click in Year to date option
 *    2. Check for Alert
 */
@Test
public void tc6_YearToDate_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("Year to date")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
    Date dNow = new Date();
    String strToday = sdf.format(dNow);
    String strBeginYear = sdfYear.format(dNow) + "-01-01";

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + strBeginYear + " to " + strToday;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 7 ###############################
 *
 * Test Case Name://w  ww  .ja  va2  s  . co  m
 *    Set Date Range Today
 * Description:
 *    When click on The Previous Month option an alert is displayed with the
 *    start day of previous month to last day of previous month in range
 *    interval.
 * Steps:
 *    1. Click in The Previous Month option
 *    2. Check for Alert
 */
@Test
public void tc7_ThePreviousMonth_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("The previous Month")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MONTH, -1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");

    String strLastMonthEndDay = sdf.format(c.getTime());
    String strLastMonthStartDay = sdf.format(c.getTime()) + "-01";
    c.add(Calendar.MONTH, 1);
    c.add(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) * -1);
    strLastMonthEndDay += "-" + c.get(Calendar.DAY_OF_MONTH);

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + strLastMonthStartDay + " to " + strLastMonthEndDay;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 8 ###############################
 *
 * Test Case Name://  www  .j a  va 2s  . c  o m
 *    Set Date Range Today
 * Description:
 *    When click on All Dates Before option an alert is displayed with an 
 *    interval starting from '2014-04-22'  to the selected date.
 * Steps:
 *    1. Click in Today option and then Cancel
 *    2. Click in Today option and then Done
 *    3. Check for Alert
 */
@Test
public void tc8_AllDatesBeforePressCancelAndSelectDate_DateIsCancelAndThenSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    this.elemHelper.FindElement(driver, By.linkText("All Dates Before")).sendKeys(Keys.ENTER);
    this.elemHelper.Click(driver, By.xpath("(//button[contains(text(),'Cancel')])[7]"));
    this.elemHelper.WaitForElementInvisibility(driver, By.xpath("(//a[text()='All Dates Before'])[2]"), 5);
    WebElement dataPickerDisable = this.elemHelper.WaitForElementPresence(driver,
            By.xpath("(//a[text()='All Dates Before'])[2]"), 1);
    assertFalse(dataPickerDisable.isDisplayed());

    /*
     * ## Step 2
     */
    //Click in day 29
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("All Dates Before")).sendKeys(Keys.ENTER);
    this.elemHelper.FindElement(driver, By.linkText("29")).sendKeys(Keys.ENTER);

    /*
     * ## Step 3
     */
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();

    Calendar c = Calendar.getInstance();
    c.add(Calendar.YEAR, -1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String beginDate = sdf.format(c.getTime());

    assertEquals("You chose from " + beginDate + " to 2014-09-29", confirmationMsg);
}

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

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:/*from w  w  w.  j ava  2s.  c  o  m*/
 *    Select Month
 * Description:
 *    The test case pretends to validate an alert is displayed after select
 *    a month and the alert displayed the selected month.
 * Steps:
 *    1. Open Pie Chart
 *    2. Click on chart
 *    3. Open Bar Chart
 *    4. Click on chart
 */
@Test
public void tc3_ClickOnChart_AlertDisplayed() {
    this.log.info("tc3_ClickOnChart_AlertDisplayed");
    String title = "";

    String firstChart = this.elemHelper.GetAttribute(driver, By.xpath("//img[@id='sampleObjectimage']"), "src");

    ActionsHelper actsHelper = new ActionsHelper(driver);
    actsHelper.MouseOver(By.xpath("//div[contains(text(),'Details')]"));
    title = this.elemHelper.WaitForElementPresentGetText(driver, By.id("sampleObjectcaptiontitle"));
    assertTrue(title.equals("Top 10 Customers"));
    this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionchartType']"));
    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));
    //Check if the generated image is different from previews, is not something static
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//img[@id='sampleObjectimage']")));
    String secondChart = this.elemHelper.GetAttribute(driver, By.xpath("//img[@id='sampleObjectimage']"),
            "src");
    assertNotEquals(firstChart, secondChart);

    // ## Step 2
    //Click in 'Dragon Souveniers, Ltd.'
    this.elemHelper.Click(driver, By.xpath("//map[@id='sampleObjectimageMap']/area[4]"));
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You clicked Dragon Souveniers, Ltd.", confirmationMsg);
    //Click in 'Mini Gifts Distributors Ltd'
    this.elemHelper.FindElement(driver, By.xpath("//map[@id='sampleObjectimageMap']/area[9]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You clicked Mini Gifts Distributors Ltd.", confirmationMsg);

    // ## Step 3
    Actions acts2 = new Actions(driver);
    acts2.moveToElement(this.elemHelper.FindElement(driver, By.xpath("//div[contains(text(),'Details')]")));
    acts2.perform();
    //Open the Pie Chart
    title = this.elemHelper.WaitForElementPresentGetText(driver, By.id("sampleObjectcaptiontitle"));
    assertTrue(title.equals("Top 10 Customers"));
    this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionchartType']"));
    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));
    //Check if the generated image is different from previews, is not something static
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//img[@id='sampleObjectimage']")));
    String thirdChart = this.elemHelper.GetAttribute(driver, By.xpath("//img[@id='sampleObjectimage']"), "src");
    assertNotEquals(firstChart, thirdChart);
    assertNotEquals(secondChart, thirdChart);

    // ## Step 3
    //Click in 'Australian Collectors, Co.'
    this.elemHelper.FindElement(driver, By.xpath("//map[@id='sampleObjectimageMap']/area[8]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You clicked Australian Collectors, Co.", confirmationMsg);
    //Click in 'Down Under Souveniers, Inc'
    this.elemHelper.FindElement(driver, By.xpath("//map[@id='sampleObjectimageMap']/area[5]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You clicked Down Under Souveniers, Inc", confirmationMsg);
}

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

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:// ww  w.  j a v a2  s  .  c o  m
 *    Select Month
 * Description:
 *    The test case pretends to validate an alert is displayed after select
 *    a month and the alert displayed the selected month.
 * Steps:
 *    1. Pick a month and check for alert
 */
@Test
public void tc3_SelectMonth_AlertDisplayed() {
    this.log.info("tc3_SelectMonth_AlertDisplayed");

    //## Step 1
    Calendar c = Calendar.getInstance();
    c.add(Calendar.YEAR, 2006 - c.get(Calendar.YEAR));
    c.add(Calendar.MONTH, 2);
    Date timeToPick = c.getTime();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
    String strTimeToPick = sdf.format(timeToPick);

    Select select = new Select(this.elemHelper.FindElement(driver, By.id("myInput")));
    select.selectByValue(strTimeToPick);

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

    assertEquals("You chose: " + strTimeToPick, confirmationMsg);
}

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

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:/*w  w  w.ja  va 2  s .c o m*/
 *    Click In Each Button
 * Description:
 *    The test case pretends to validate the buttons works ok.
 * Steps:
 *    1. Click in Eastern
 *    2. Click in Central
 *    3. Click in Western
 *    4. Click in Southern
 */
@Test
public void tc3_ClickInEachOption_AlertDisplayed() {
    this.log.info("tc3_ClickInEachOption_AlertDisplayed");

    // ## Step 1
    this.elemHelper.FindElement(driver, By.xpath("//button[contains(text(),'Eastern')]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Eastern", confirmationMsg);

    // ## Step 2
    this.elemHelper.FindElement(driver, By.xpath("//button[contains(text(),'Central')]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central", confirmationMsg);

    // ## Step 3
    this.elemHelper.FindElement(driver, By.xpath("//button[contains(text(),'Western')]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Western", confirmationMsg);

    // ## Step 4
    this.elemHelper.FindElement(driver, By.xpath("//button[contains(text(),'Southern')]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern", confirmationMsg);
}

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

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name:/*from  w w w.  ja  v a 2 s  .  com*/
 *    Click Arbitrary in available Button
 * Description:
 *    The test case pretends to validate no error occurs when we click
 *    arbitrary in the buttons.
 * Steps:
 *    1. Click in Central
 *    2. Click in Southern
 *    3. Click in Eastern
 *    4. Click in Southern
 */
@Test
public void tc4_ClickArbitrary_AlertDisplayed() {
    this.log.info("tc4_ClickArbitrary_AlertDisplayed");

    // ## Step 1
    this.elemHelper.FindElement(driver, By.xpath("//button[contains(text(),'Central')]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central", confirmationMsg);

    // ## Step 2
    this.elemHelper.FindElement(driver, By.xpath("//button[contains(text(),'Southern')]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern", confirmationMsg);

    // ## Step 3
    this.elemHelper.FindElement(driver, By.xpath("//button[contains(text(),'Eastern')]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Eastern", confirmationMsg);

    // ## Step 4
    this.elemHelper.FindElement(driver, By.xpath("//button[contains(text(),'Southern')]")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern", confirmationMsg);
}