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

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

Introduction

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

Prototype

public Actions(WebDriver driver) 

Source Link

Usage

From source file:com.vaadin.tests.components.tree.TreeKeyboardNavigationToNoneTest.java

License:Apache License

private void sendKey(Keys key) {
    Actions actions = new Actions(getDriver());
    actions.sendKeys(key).build().perform();
}

From source file:com.vaadin.tests.components.tree.TreeScrollingOnRightClickTest.java

License:Apache License

@Test
public void testScrollingOnRightClick() throws Throwable {
    openTestURL();//from   www  .  j  av a  2 s.  com

    // Focus tree
    WebElement tree = getDriver().findElement(By.id(TreeScrollingOnRightClick.TREE_ID));
    tree.click();

    // Move selection down 50 items
    for (int down = 0; down < 50; down++) {
        tree.sendKeys(Keys.ARROW_DOWN);
    }

    Thread.sleep(1000);

    // Get location of item 40
    Point item40Location = getTreeNode("Node 40").getLocation();

    // Right click on item 45
    WebElement item45 = getTreeNode("Node 45");
    new Actions(getDriver()).moveToElement(item45).contextClick(item45).perform();

    // Ensure location of item 40 is still the same (no scrolling)
    Point item40Location2 = getTreeNode("Node 40").getLocation();
    assertEquals(item40Location.getY(), item40Location2.getY());
}

From source file:com.vaadin.tests.components.window.CloseShortcutTest.java

License:Apache License

private void attemptCtrlShortcut() {
    window.focus();// ww w.  j a  v a  2s .  c  om
    new Actions(driver).keyDown(Keys.CONTROL).perform();
    $(TextFieldElement.class).first().sendKeys("A");
    new Actions(driver).keyUp(Keys.CONTROL).perform();
}

From source file:com.vaadin.tests.components.window.CloseShortcutTest.java

License:Apache License

private void attemptShiftShortcut() {
    window.focus();//from   ww w. j a  va 2s .c om
    new Actions(driver).keyDown(Keys.SHIFT).perform();
    $(TextFieldElement.class).first().sendKeys("H");
    new Actions(driver).keyUp(Keys.SHIFT).perform();
}

From source file:com.vaadin.v7.tests.components.grid.GridDragSelectionWhileScrolledTest.java

License:Apache License

@Test
public void testDragSelect() throws IOException {
    openTestURL();/*from w w  w. j a va2s  . co  m*/

    // Scroll grid to view
    GridElement grid = $(GridElement.class).first();
    ((JavascriptExecutor) getDriver()).executeScript("arguments[0].scrollIntoView(true);", grid);

    // Drag select 2 rows
    new Actions(getDriver()).moveToElement(grid.getCell(3, 0), 5, 5).clickAndHold()
            .moveToElement(grid.getCell(2, 0), 5, 5).release().perform();

    // Assert only those are selected.
    assertTrue("Row 3 should be selected", grid.getRow(3).isSelected());
    assertTrue("Row 2 should be selected", grid.getRow(2).isSelected());
    assertFalse("Row 4 should not be selected", grid.getRow(4).isSelected());
    assertFalse("Row 1 should not be selected", grid.getRow(1).isSelected());
}

From source file:com.vaadin.v7.tests.components.grid.GridEditorFrozenColumnsUITest.java

License:Apache License

private void openEditor(int rowIndex) {
    GridElement grid = $(GridElement.class).first();

    GridCellElement cell = grid.getCell(rowIndex, 1);

    new Actions(driver).moveToElement(cell).doubleClick().build().perform();
}

From source file:com.vaadin.v7.tests.components.grid.GridEditorUITest.java

License:Apache License

@Test
public void testEditor() {
    assertFalse("Sanity check", isElementPresent(PasswordFieldElement.class));

    openEditor(5);// w w  w . j  a  v  a 2s  . co m
    new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();

    openEditor(10);

    assertTrue("Editor should be opened with a password field", isElementPresent(PasswordFieldElement.class));

    assertFalse("Notification was present", isElementPresent(NotificationElement.class));
}

From source file:com.vaadin.v7.tests.components.grid.GridResizeHiddenColumnTest.java

License:Apache License

@Test
public void testDragResizeHiddenColumnSize() {
    GridElement grid = $(GridElement.class).first();
    Actions action = new Actions(getDriver());

    // Check if column 'Gender' hidden
    List<GridCellElement> headerCells = grid.getHeaderCells(0);
    Assert.assertEquals("There should be two visible columns", 2, headerCells.size());
    Assert.assertFalse("Gender column should be hidden", containsText("Gender", headerCells));

    // Resize first column
    int dragOffset = -100;
    int headerCellWidth = headerCells.get(0).getSize().getWidth();
    dragResizeColumn(headerCells.get(0), 1, dragOffset);

    // When dragging the resizer on IE8, the final offset will be smaller
    // (might be an issue with the feature that doesn't start resizing until
    // the cursor moved a few pixels)
    double delta = BrowserUtil.isIE8(getDesiredCapabilities()) ? 5d : 0;
    Assert.assertEquals("Column width should've changed by " + dragOffset + "px", headerCellWidth + dragOffset,
            headerCells.get(0).getSize().getWidth(), delta);

    // Make column 'Gender' visible
    WebElement menuButton = grid.findElement(By.className("v-contextmenu")).findElement(By.tagName("button"));
    action.click(menuButton).perform(); // Click on menu button

    WebElement sidebarPopup = findElement(By.className("v-grid-sidebar-popup"));
    WebElement visibilityToggle = findElementByText("Gender",
            sidebarPopup.findElements(By.className("gwt-MenuItem")));
    action.click(visibilityToggle).perform(); // Click on 'Gender' menu item

    // Check if column 'Gender' is visible
    headerCells = grid.getHeaderCells(0);
    Assert.assertEquals("There should be three visible columns", 3, headerCells.size());
    Assert.assertTrue("Gender column should be visible", containsText("Gender", headerCells));

    // Check if column 'Gender' has expanded width
    int widthSum = 0;
    for (GridCellElement e : headerCells) {
        widthSum += e.getSize().getWidth();
    }/* w w w .jav a2 s.  co m*/
    Assert.assertEquals("Gender column should take up the remaining space",
            grid.getHeader().getSize().getWidth(), widthSum, 1d);
}

From source file:com.vaadin.v7.tests.components.grid.GridResizeHiddenColumnTest.java

License:Apache License

private void dragResizeColumn(GridCellElement headerCell, int posX, int offset) {
    Dimension size = headerCell.getSize();
    new Actions(getDriver()).moveToElement(headerCell, size.getWidth() + posX, size.getHeight() / 2)
            .clickAndHold().moveByOffset(offset, 0).release().perform();
}

From source file:com.vilt.minium.impl.actions.DefaultInteraction.java

License:Apache License

/**
 * New actions.// w  w  w. j  ava 2 s.  c  o  m
 *
 * @param elem the elem
 * @return the actions
 */
protected Actions newActions(WebElement elem) {
    return new Actions(((WrapsDriver) elem).getWrappedDriver());
}