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.RadioComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:/*from  w  ww  .  jav a 2s  . c  o  m*/
 *    Select options one by one
 * Description:
 *    We pretend validate the selection of each option one by one.
 * Steps:
 *    1. Select Eastern
 *    2. Select Central
 *    3. Select Western
 *    4. Select Southern
 */
@Test
public void tc3_SelectEachItem_AlertDisplayed() {
    this.log.info("tc3_SelectEachItem_AlertDisplayed");

    // ## Step 1
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Eastern']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Eastern", confirmationMsg);
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());

    // ## Step 2
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Central']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central", confirmationMsg);
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());

    // ## Step 3
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Western']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Western", confirmationMsg);
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());

    // ## Step 4
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Southern']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern", confirmationMsg);
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());
}

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

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name://from  w w w  .  j  a  v  a 2 s .com
 *    Select arbitrary options
 * Description:
 *    We pretend validate the selection every available options but arbitrary.
 * Steps:
 *    1. Select Western
 *    2. Select Southern
 *    3. Select Central
 *    4. Select Western
 */
@Test
public void tc4_SelectArbitrary_AlertDisplayed() {
    this.log.info("tc4_SelectArbitrary_AlertDisplayed");

    // ## Step 1
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Western']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Western", confirmationMsg);
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());

    // ## Step 2
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Southern']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Southern", confirmationMsg);
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());

    // ## Step 3
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Central']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central", confirmationMsg);
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());

    // ## Step 4
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Western']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Western", confirmationMsg);
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Southern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Eastern']")).isSelected());
    assertFalse(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).isSelected());
    assertTrue(this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).isSelected());
}

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

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:/*from  w  ww  . j  a  v a  2  s. co 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");

    /*
     * ## Step 1
     */
    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 4
     */
    //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.require.MonthPickerComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name://from w w w  .  j a  v a  2 s  . co  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("monthPickerComponent")));
    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.require.MultiButtonComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name://  w  w w . j  a  v a  2  s  .com
 *    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.require.MultiButtonComponent.java

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name:/*  ww w . j  a  v  a  2s  . co  m*/
 *    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);
}

From source file:com.pentaho.ctools.cdf.require.RadioComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name://  w ww  .j a  va2s.  co  m
 *    Select options one by one
 * Description:
 *    We pretend validate the selection of each option one by one.
 * Steps:
 *    1. Select Eastern
 *    2. Select Central
 *    3. Select Western
 *    4. Select Southern
 */
@Test
public void tc3_SelectEachItem_AlertDisplayed() {
    this.log.info("tc3_SelectEachItem_AlertDisplayed");

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

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

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

    /*
     * ## Step 4
     */
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Southern']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='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.require.RadioComponent.java

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name://from   ww w.  ja  v  a  2 s.c om
 *    Select arbitrary options
 * Description:
 *    We pretend validate the selection every available options but arbitrary.
 * Steps:
 *    1. Select Western
 *    2. Select Southern
 *    3. Select Central
 *    4. Select Western
 */
@Test
public void tc4_SelectArbitrary_AlertDisplayed() {
    this.log.info("tc4_SelectArbitrary_AlertDisplayed");

    /*
     * ## Step 1
     */
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Western']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Western", confirmationMsg);

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

    /*
     * ## Step 3
     */
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Central']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Central']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Central", confirmationMsg);

    /*
     * ## Step 4
     */
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='Western']")));
    this.elemHelper.FindElement(driver, By.xpath("//input[@value='Western']")).click();
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("you chose: Western", confirmationMsg);
}

From source file:com.pentaho.ctools.cdf.require.SchedulePrptComponent.java

License:Apache License

/**
 * ############################### Test Case 2 ###############################
 *
 * Test Case Name:/*  www . jav a  2s .c  o  m*/
 *    Create a Schedule
 * Description:
 *    It is supposed to create a schedule and validate it was created with
 *    specify data and date.
 * Steps:
 *    1. Click to create a schedule prpt.
 *    2. Fill the form and submit
 *    3. Check for alert.
 *    4. On Schedule Manager, it is set the schedule.
 * @throws InterruptedException
 */
@Test
public void tc3_SchedulePrpt_ScheduleCreatedSuccessful() {
    this.log.info("tc3_SchedulePrpt_ScheduleCreatedSuccessful");
    this.bRemoveSchedule = true;
    String schLocation = "/public";

    //Initialize some data
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    SimpleDateFormat sdfDay = new SimpleDateFormat("d");
    Date dNow = new Date();
    Calendar c = Calendar.getInstance();
    c.setTime(dNow);
    c.add(Calendar.DATE, 1);
    Date dTomorrow = c.getTime();
    c.add(Calendar.DATE, 40); //30th days from today
    Date d40days = c.getTime();

    /*
     * ## Step 1
     */
    this.elemHelper.FindElement(driver, By.xpath("//div[@id='sampleObject']/button")).click();

    /*
     * ## Step 2
     */
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("jqistate_basicState")));
    //Set schedule name
    this.elemHelper.FindElement(driver, By.id("nameIn")).clear();
    this.elemHelper.FindElement(driver, By.id("nameIn")).sendKeys(this.schNameTc3);
    //Set schedule location
    this.elemHelper.FindElement(driver, By.id("locationIn")).clear();
    this.elemHelper.FindElement(driver, By.id("locationIn")).sendKeys(schLocation);
    //Select Monthly
    Select slRecurrence = new Select(this.elemHelper.FindElement(driver, By.id("recurrId")));
    slRecurrence.selectByValue("monthly");
    //Select Hour
    Select slHours = new Select(this.elemHelper.FindElement(driver, By.id("hours")));
    slHours.selectByValue("9");
    //Select Minutes
    Select slMinutes = new Select(this.elemHelper.FindElement(driver, By.id("minutes")));
    slMinutes.selectByValue("17");
    //Select AM/FM
    Select slAMFM = new Select(this.elemHelper.FindElement(driver, By.id("amPm")));
    slAMFM.selectByValue("pm");
    //Select Option 'The x y of every month
    this.elemHelper.Click(driver, By.xpath("//div[@id='patternMonth']/input[2]"));
    //Select Month
    Select slOccDay = new Select(this.elemHelper.FindElement(driver, By.id("monthOpt1Select")));
    slOccDay.selectByValue("1");
    //Select Wednesday
    Select slWeekday = new Select(this.elemHelper.FindElement(driver, By.id("monthOpt2Select")));
    slWeekday.selectByValue("3");
    //Select Range Of Recurrence
    //Start - tomorrow
    this.elemHelper.FindElement(driver, By.id("rangeStartIn")).clear();
    this.elemHelper.FindElement(driver, By.id("rangeStartIn")).sendKeys(sdf.format(dTomorrow));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//table[@class='ui-datepicker-calendar']")));
    WebElement dateCalendar = this.elemHelper.FindElement(driver,
            By.xpath("//table[@class='ui-datepicker-calendar']"));
    List<WebElement> columns = dateCalendar.findElements(By.tagName("td"));
    String tomorrowDay = sdfDay.format(dTomorrow);
    for (WebElement cell : columns) {
        String strCell = cell.getText();
        if (strCell.equals(tomorrowDay)) {
            cell.findElement(By.linkText(tomorrowDay)).click();
            break;
        }
    }
    //End
    //Select End Date
    wait.until(ExpectedConditions.elementToBeClickable(By.id("endByRadio")));
    this.elemHelper.FindElement(driver, By.id("endByRadio")).click();
    this.elemHelper.FindElement(driver, By.id("endByIn")).sendKeys(sdf.format(d40days));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//table[@class='ui-datepicker-calendar']")));
    WebElement dateCalendar2 = this.elemHelper.FindElement(driver,
            By.xpath("//table[@class='ui-datepicker-calendar']"));
    List<WebElement> columns2 = dateCalendar2.findElements(By.tagName("td"));
    String day = sdfDay.format(d40days);
    for (WebElement cell2 : columns2) {
        String strCell2 = cell2.getText();
        if (strCell2.equals(day)) {
            cell2.findElement(By.linkText(day)).click();
            break;
        }
    }

    //Submit Form
    wait.until(ExpectedConditions.elementToBeClickable(By.id("jqi_basicState_buttonOk")));
    this.elemHelper.FindElement(driver, By.id("jqi_basicState_buttonOk")).click();
    //Wait for the new window.
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("jqistate_mailState")));
    wait.until(ExpectedConditions.elementToBeClickable(By.id("jqi_mailState_buttonOk")));
    this.elemHelper.FindElement(driver, By.id("jqi_mailState_buttonOk")).click();

    // ## Step 3
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals(confirmationMsg, "Successfully scheduled.");

    /*
     * ## Step 4
     */
    //-->Need to check if the schedule was created
    //Go to home page
    driver.get(PageUrl.PUC);

    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

    //Click in Schedule
    wait.until(ExpectedConditions.titleContains("Pentaho User Console"));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div[@id='pucUserDropDown']/table/tbody/tr/td/div")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[@id='home.perspective']")));
    wait.until(ExpectedConditions
            .elementToBeClickable(By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]")));
    this.elemHelper
            .FindElement(driver, By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]"))
            .click();
    WebElement listMenyTr = this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='customDropdownPopupMajor']/div/div/table/tbody"));
    List<WebElement> listMenuElementsTrs = listMenyTr.findElements(By.xpath("//td[@class='gwt-MenuItem']"));
    for (int i = 0; i < listMenuElementsTrs.size(); i++) {
        WebElement element = listMenuElementsTrs.get(i);
        if (element.getText().equals("Schedules")) {
            element.click();
            break;
        }
    }
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.workspaceHeading")));
    // Now we are in Schedule page
    List<WebElement> listScheduleTrs = this.elemHelper
            .FindElement(driver, By.xpath("//table[@id='schedule-table']/tbody"))
            .findElements(By.tagName("tr"));
    String scheduleName = "";
    String scheduleRepeats = "";
    String scheduleSourceFile = "";
    String scheduleOuputLocation = "";
    String scheduleLastRun = "";
    String scheduleNextRun = "";
    String scheduleCreatedBy = "";
    String scheduleStatus = "";
    for (int j = 1; j <= listScheduleTrs.size(); j++) {
        WebElement elementFirstDiv = this.elemHelper.FindElement(driver,
                By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td/div"));
        scheduleName = elementFirstDiv.getText();
        if (scheduleName.equals(this.schNameTc3)) {

            scheduleRepeats = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[2]/div"));
            scheduleSourceFile = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[3]/div"));
            scheduleOuputLocation = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[4]/div"));
            scheduleLastRun = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[5]/div"));
            scheduleNextRun = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[6]/div"));
            scheduleCreatedBy = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[7]/div"));
            scheduleStatus = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[8]/div"));
            break;
        }
    }

    //Getting the week day of next run
    String dayOfWeek = "";
    if (!scheduleNextRun.isEmpty()) {
        try {
            Date dateNextRun = new SimpleDateFormat("yyyy MMM dd HH:mm:ss", Locale.US).parse(scheduleNextRun);
            dayOfWeek = new SimpleDateFormat("EE", Locale.US).format(dateNextRun);
        } catch (ParseException pe) {
            this.log.error(pe.getMessage());
        }
    }

    assertEquals(this.schNameTc3, scheduleName);
    assertEquals("The second Wednesday of every month at 21:17:00", scheduleRepeats);
    assertEquals("/public/Steel Wheels/Widget Library/Report Snippets/InventorybyLine", scheduleSourceFile);
    assertEquals(schLocation, scheduleOuputLocation);
    assertEquals("-", scheduleLastRun);
    assertEquals("Wed", dayOfWeek);
    assertEquals("admin", scheduleCreatedBy);
    assertEquals("Normal", scheduleStatus);
}

From source file:com.pentaho.ctools.cdf.require.SelectComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:/*from ww w .ja v a  2 s  .c om*/
 *    Select options one by one
 * Description:
 *    We pretend validate the selection of each option one by one.
 * Steps:
 *    1. Select Dusseldorf
 *    2. Select Lisbon
 */
@Test
public void tc3_SelectEachItem_AlertDisplayed() {
    this.log.info("tc3_SelectEachItem_AlertDisplayed");

    // ## Step 1
    this.elemHelper.SelectByValue(driver, By.cssSelector("select"), "2");
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You chose: 2", confirmationMsg);

    // ## Step 2
    this.elemHelper.SelectByValue(driver, By.cssSelector("select"), "1");
    wait.until(ExpectedConditions.alertIsPresent());
    alert = driver.switchTo().alert();
    confirmationMsg = alert.getText();
    alert.accept();
    assertEquals("You chose: 1", confirmationMsg);
}