Example usage for org.openqa.selenium By linkText

List of usage examples for org.openqa.selenium By linkText

Introduction

In this page you can find the example usage for org.openqa.selenium By linkText.

Prototype

public static By linkText(String linkText) 

Source Link

Usage

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

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:/*from w w  w  . j a  va  2  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  av a  2s.co 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 v a  2s  .c  o  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:/*from www .j a v  a2 s  . 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.MetaLayerHomeDashboard.java

License:Apache License

/**
 * ############################### Test Case 1 ###############################
 *
 * Test Case Name:/* www.j a  va  2  s  . c  o  m*/
 *    MetaLayer Home Dashboard - clicking details
 * Description:
 *    We pretend to validate when user click on 'Details...' a pop-up message
 *    is displayed.
 * Steps:
 *    1. Open the MetaLayer Home Dashboard.
 *    2. Click in 'Details...'.
 *    3. Check if we have width = 500 and height = 600
 */
@Test
public void tc1_LinkDetails_PopupJPivot() {
    this.log.info("tc1_LinkDetails_PopupJPivot");
    /*
     * ## Step 1
     */
    driver.get(baseUrl
            + "api/repos/%3Apublic%3Aplugin-samples%3Apentaho-cdf%3A20-samples%3Ahome_dashboard_2%3Ahome_dashboard_metalayer.xcdf/generatedContent");

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

    //Wait for title become visible and with value 'Community Dashboard Framework'
    String titlePage = this.elemHelper.WaitForTitle(driver, "Community Dashboard Framework");
    //Wait for visibility of 'Top Ten Customers'
    String expectedSampleTitle = "Top Ten Customers";
    String actualSampleTitle = this.elemHelper.WaitForTextPresence(driver, By.xpath("//div[@id='titleObject']"),
            expectedSampleTitle);
    // Validate the sample that we are testing is the one
    assertEquals(titlePage, "Community Dashboard Framework");
    assertEquals(actualSampleTitle, expectedSampleTitle);

    /*
     * ## Step 2
     */
    //Wait for visibility of 'topTenCustomersDetailsObject' the text 'Details'
    WebElement linkDetails = this.elemHelper.FindElement(driver, By.linkText("Details..."));
    assertEquals("Details...", linkDetails.getText());
    //click on the 'Details...'
    linkDetails.click();

    /*
     * ## Step 3
     */
    //Wait for the frame
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("fancybox-content"));
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//iframe"));
    WebElement frame = this.elemHelper.FindElement(driver, By.xpath("//iframe"));
    String valueFrameAttrSrc = frame.getAttribute("src");

    ///pentaho/plugin/jpivot/Pivot?solution=system&path=%2Fpublic%2Fplugin-samples%2Fpentaho-cdf%2Factions&action=jpivot.xaction&width=500&height=600
    //Check if we have the sizes 500 and 600
    assertTrue(StringUtils.containsIgnoreCase(valueFrameAttrSrc, "&width=500&height=600"));

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

    //Wait for the element be visible.
    WebDriver driverFrame = driver.switchTo().frame(frame);
    assertNotNull(this.elemHelper.FindElement(driverFrame, By.xpath("//div[@id='internal_content']")));
    assertEquals("Measures", this.elemHelper.WaitForElementPresentGetText(driverFrame,
            By.xpath("//div[@id='internal_content']/table/tbody/tr[2]/td[2]/p/table/tbody/tr/th[2]")));
    assertEquals("Australian Collectors, Co.", this.elemHelper.WaitForElementPresentGetText(driverFrame, By
            .xpath("//div[@id='internal_content']/table[1]/tbody/tr[2]/td[2]/p[1]/table/tbody/tr[5]/th/div")));
    assertEquals("180,125", this.elemHelper.WaitForElementPresentGetText(driverFrame,
            By.xpath("//div[@id='internal_content']/table[1]/tbody/tr[2]/td[2]/p[1]/table/tbody/tr[7]/td")));

    //Close pop-up
    driver.switchTo().defaultContent();
    wait.until(ExpectedConditions.elementToBeClickable(By.id("fancybox-close")));
    String background = this.elemHelper.FindElement(driver, By.cssSelector("#fancybox-close"))
            .getCssValue("background-image");
    String background1 = background.substring(background.indexOf(34) + 1, background.lastIndexOf(34));
    assertEquals("http://localhost:8080/pentaho/api/repos/pentaho-cdf/js-legacy/lib/fancybox/fancybox.png",
            background1);
    this.elemHelper.FindElement(driver, By.id("fancybox-close")).click();
    this.elemHelper.WaitForElementInvisibility(driver, By.id("fancybox-content"));
    assertEquals("200", Integer.toString(HttpUtils.GetResponseCode(background1, "admin", "password")));
}

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

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:/*from   w  w  w  . j  a v 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() {
    this.log.info("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);

    String confirmationMsg = this.elemHelper.WaitForAlertReturnConfirmationMsg(driver);
    String expectedCnfText = "You chose from " + strToday + " to " + strToday;

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name://from w  w  w  .  j  a v a  2  s.  com
 *    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() {
    this.log.info("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);

    String confirmationMsg = this.elemHelper.WaitForAlertReturnConfirmationMsg(driver);
    String expectedCnfText = "You chose from " + sdf.format(c.getTime()) + " to " + strToday;

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:// www. j  a v  a  2 s.c o  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() {
    this.log.info("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";

    String confirmationMsg = this.elemHelper.WaitForAlertReturnConfirmationMsg(driver);
    String expectedCnfText = "You chose from " + strCurrentMonth + " to " + strToday;

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 6 ###############################
 *
 * Test Case Name://from   w w w .  j av a2s .co  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() {
    this.log.info("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";

    String confirmationMsg = this.elemHelper.WaitForAlertReturnConfirmationMsg(driver);
    String expectedCnfText = "You chose from " + strBeginYear + " to " + strToday;

    assertEquals(confirmationMsg, expectedCnfText);
}

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

License:Apache License

/**
 * ############################### Test Case 7 ###############################
 *
 * Test Case Name://www  . j av  a  2  s  .c  o  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() {
    this.log.info("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);

    String confirmationMsg = this.elemHelper.WaitForAlertReturnConfirmationMsg(driver);
    String expectedCnfText = "You chose from " + strLastMonthStartDay + " to " + strLastMonthEndDay;
    assertEquals(confirmationMsg, expectedCnfText);
}