Example usage for org.openqa.selenium.interactions Actions perform

List of usage examples for org.openqa.selenium.interactions Actions perform

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions perform.

Prototype

public void perform() 

Source Link

Document

A convenience method for performing the actions without calling build() first.

Usage

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

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:/*  www . j  av a 2s  .c  om*/
 *    Display Page
 * Description:
 *    We pretend validate to check if a comment is removed.
 * Steps:
 *    1. Add a comment
 *    2. Remove added comment
 */
@Test
public void tc5_RemoveComment_CommentRemoved() {
    this.log.info("tc5_RemoveComment_CommentRemoved");
    this.tcRemoveComment = true;
    /*
     * Guarantee no comments displayed
     */
    cleanAllComments();

    String commentText = "Some comment!";
    String noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    String addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);

    /*
     * ## Step 1
     */
    this.elemHelper.ClickJS(driver, By.cssSelector("div.addComment"));
    //Insert the text
    this.elemHelper.FindElement(driver, By.cssSelector("textarea.addCommentText")).sendKeys(commentText);
    this.elemHelper.ClickJS(driver, By.cssSelector("div.saveComment"));
    //wait for the page rendered
    this.elemHelper.WaitForElementPresence(driver, By.cssSelector("div.navigateRefresh"));
    //Check if the comment was added
    String commentAdded = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div"));
    assertEquals(commentAdded, commentText);

    /*
     * ## Step 2
     */
    Actions acts = new Actions(driver);
    acts.moveToElement(this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div")));
    acts.build().perform();
    acts.perform();
    acts.moveToElement(this.elemHelper.FindElement(driver, By.cssSelector("div.archive")));
    acts.click();
    acts.perform();
    //Check we don't have more comments
    noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);
    String refreshComments = this.elemHelper.WaitForElementPresentGetText(driver,
            By.cssSelector("div.navigateRefresh"));
    assertEquals("Refresh", refreshComments);
}

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

License:Apache License

/**
 * This method shall clean all existence comments.
 *///from w  ww  . j  av a 2 s.  c  om
private void cleanAllComments() {
    this.log.info("Remove comments");

    ElementHelper elemHelper = new ElementHelper();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    List<WebElement> listEraseComments = driver.findElements(By.cssSelector("div.archive"));
    int nIteractions = listEraseComments.size();
    this.log.info("Number elements to remove: " + nIteractions);
    if (nIteractions > 0) {
        this.log.debug("We have comments to remove");
        for (int i = 1; i <= nIteractions; i++) {
            Actions acts = new Actions(driver);
            acts.moveToElement(elemHelper.FindElement(driver,
                    By.xpath("//div[@id='sampleObject']/div/div/div/div[2]/div[2]")));
            acts.perform();
            acts.moveToElement(elemHelper.FindElement(driver,
                    By.xpath("//div[@id='sampleObject']/div/div/div/div[2]/div[2]/div")));
            acts.click();
            acts.perform();
            this.log.debug("One comment removed.");
        }
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

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

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:/*  w ww. j  av 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.utils.ElementHelper.java

License:Apache License

/**
 * The function will search for the element present (doesn't matter
 * if element is visible or not) and then click on it.
 *
 * @param driver/*from w w  w  .  ja  v a 2 s.c o m*/
 * @param locator
 */
public void MoveToElementAndClick(WebDriver driver, By locator) {
    this.log.debug("MoveToElementAndClick::Enter");

    try {
        WebElement element = WaitForElementPresenceAndVisible(driver, locator);
        if (element != null) {
            Actions builder = new Actions(driver);
            builder.moveToElement(element).click(element);
            builder.perform();
        } else {
            this.log.error("Element is null " + locator.toString());
        }
    } catch (StaleElementReferenceException sere) {
        //Repeat it again
        MoveToElementAndClick(driver, locator);
    }

    this.log.debug("MoveToElementAndClick::Exit");
}

From source file:com.pivotal.gemfire.tools.pulse.tests.PulseTests.java

License:Open Source License

protected void scrollbarVerticalDownScroll() {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("javascript:window.scrollBy(250,700)");
    WebElement pickerScroll = driver.findElement(By.className("jspDrag"));
    WebElement pickerScrollCorner = driver.findElement(By.className("jspCorner"));
    Actions builder = new Actions(driver);
    // pickerscroll is the webelement
    Actions movePicker = builder.dragAndDrop(pickerScroll, pickerScrollCorner);
    movePicker.perform();
}

From source file:com.pivotal.gemfire.tools.pulse.tests.PulseTests.java

License:Open Source License

protected void scrollbarHorizontalRightScroll() {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("javascript:window.scrollBy(250,700)");
    WebElement pickerScroll = driver/*from w  w  w.  j av a  2 s . co m*/
            .findElement(By.xpath("//div[@id='gview_queryStatisticsList']/div[3]/div/div[3]/div[2]/div"));
    WebElement pickerScrollCorner = driver.findElement(By.className("jspCorner"));
    Actions builder = new Actions(driver);
    // pickerscroll is the webelement
    Actions movePicker = builder.dragAndDrop(pickerScroll, pickerScrollCorner);
    movePicker.perform();
}

From source file:com.technophobia.webdriver.substeps.impl.ActionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Performs a double click on the current element (set with a previous Find
 * method).//from w ww  .  j  a v a 2  s  .  c om
 * 
 * @example PerformDoubleClick
 * @section Clicks
 * 
 */
@Step("PerformDoubleClick")
public void doDoubleClick() {

    final Actions actions = new Actions(webDriver());

    actions.doubleClick(webDriverContext().getCurrentElement());

    actions.perform();
}

From source file:com.technophobia.webdriver.substeps.impl.ActionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Performs a context click (typically right click, unless this has been
 * changed by the user) on the current element.
 * //  w w w.j a v  a  2s  .c  o m
 * @example PerformContextClick
 * @section Clicks
 * 
 */
@Step("PerformContextClick")
public void performContextClick() {

    final Actions actions = new Actions(webDriver());

    actions.contextClick(webDriverContext().getCurrentElement());

    actions.perform();
}

From source file:com.vaadin.tests.components.combobox.ComboboxPageLengthZeroScrollTest.java

License:Apache License

@Test
public void testComboboxPageLength() {
    openTestURL();/*from   w  w  w  . j  a v a  2s .c om*/

    WebElement comboBox = vaadinElement(
            "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VFilterSelect[0]#textbox");

    // navigate to the next page. keyboard navigation is the preferred
    // method here since it's much easier to implement.

    Actions keyNavigation = new Actions(driver).moveToElement(comboBox).click();

    for (int i = 0; i < 25; ++i) {
        keyNavigation.sendKeys(Keys.ARROW_DOWN);

    }
    keyNavigation.perform();

    // The broken behavior always caused a v-shadow element to have
    // height: 10px. Verify that this does no longer happen.

    String cssValue = driver.findElement(By.className("v-shadow")).getCssValue("height");

    Assert.assertNotEquals("v-shadow height should not be 10px", "10px", cssValue);

}

From source file:com.vaadin.tests.components.draganddropwrapper.DragAndDropFocusObtainTest.java

License:Apache License

@Test
public void testTextAreaDndImage() {
    openTestURL();//  w w w  .j a  v a2s. com

    WebElement wrapper = driver.findElement(By.className("v-ddwrapper"));
    Actions actions = new Actions(driver);
    actions.click(wrapper);
    actions.perform();

    WebElement focusedElement = driver.findElement(By.className("v-textarea-focus"));
    Assert.assertNotNull("Text area did not obtain focus after click", focusedElement);

}