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.grid.basicfeatures.server.GridColumnReorderTest.java

License:Apache License

@Test
public void testColumnReordering_bigWidth_dragElementPositionCorrect() {
    openTestURL();//from  www. j  av a 2 s.  c  o  m
    toggleColumnReordering();
    selectMenuPath("Component", "Size", "Width", "900px");
    assertColumnHeaderOrder(0, 1, 2, 3);

    GridCellElement draggedHeaderCell = getGridElement().getHeaderCell(0, 1);
    final int xOffset = 500;
    new Actions(getDriver()).moveToElement(draggedHeaderCell, 20, 10).clickAndHold().moveByOffset(xOffset, 0)
            .build().perform();

    WebElement floatingDragElement = findElement(By.className("dragged-column-header"));

    int expectedLeft = draggedHeaderCell.getLocation().getX() + xOffset + 20
            - (floatingDragElement.getSize().getWidth() / 2);
    int realLeft = floatingDragElement.getLocation().getX();

    assertTrue("Dragged element location wrong, expected " + expectedLeft + " was " + realLeft,
            Math.abs(expectedLeft - realLeft) < 10);
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridColumnReorderTest.java

License:Apache License

@Test
public void testDropMarker_sidebarOpenButtonVisible_dropMarkerOnCorrectPosition() {
    // using runo since there the sidebar opening button is wider than the
    // scroll deco, and because using Valo has some TB issues
    openTestURL("theme=runo");

    selectMenuPath("Component", "Size", "Width", "100%");
    selectMenuPath("Component", "Columns", "All columns hidable");
    toggleColumnReordering();/*from  ww w . j  a v  a2s.  c  o  m*/
    scrollGridHorizontallyTo(100000);

    new Actions(getDriver()).clickAndHold(getDefaultColumnHeader(10)).moveByOffset(800, 0).build().perform();

    WebElement dragDropMarker = findElement(By.className("v-grid-drop-marker"));
    WebElement sidebar = findElement(By.className("v-grid-sidebar"));

    int dragDropMarkerX = dragDropMarker.getLocation().getX();
    int sidebarX = sidebar.getLocation().getX();
    assertTrue("Drop marker misplaced " + dragDropMarkerX + " compared to sidebar open button " + sidebarX,
            dragDropMarkerX <= sidebarX);
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridColumnResizeTest.java

License:Apache License

private void dragResizeColumn(int columnIndex, int posX, int offset) {
    GridCellElement headerCell = getGridElement().getHeaderCell(0, columnIndex);
    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.vaadin.tests.components.grid.basicfeatures.server.GridEditorBufferedTest.java

License:Apache License

@Test
public void testKeyboardSave() {
    selectMenuPath(EDIT_ITEM_100);//  w  ww .  j  a  v a 2 s.co m

    WebElement textField = getEditorWidgets().get(0);

    textField.click();
    // without this, the click in the middle of the field might not be after
    // the old text on some browsers
    new Actions(getDriver()).sendKeys(Keys.END).perform();

    textField.sendKeys(" changed");

    // Save from keyboard
    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();

    assertEditorClosed();
    assertEquals("(100, 0) changed", getGridElement().getCell(100, 0).getText());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorBufferedTest.java

License:Apache License

@Test
public void testKeyboardSaveWithInvalidEdition() {
    makeInvalidEdition();//from w  w w  .  ja va 2 s.  c  o m

    GridEditorElement editor = getGridElement().getEditor();
    TestBenchElement field = editor.getField(7);

    field.click();
    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();

    assertEditorOpen();
    assertEquals("Column 7: Could not convert value to Integer", editor.getErrorMessage());
    assertTrue("Field 7 should have been marked with an error after error", editor.isFieldErrorMarked(7));

    editor.cancel();

    selectMenuPath(EDIT_ITEM_100);
    assertFalse("Exception should not exist", isElementPresent(NotificationElement.class));
    assertEquals("There should be no editor error message", null,
            getGridElement().getEditor().getErrorMessage());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorBufferedTest.java

License:Apache License

@Test
public void testSave() {
    selectMenuPath(EDIT_ITEM_100);//from   w  ww . j  a v  a 2 s  .c  o m

    WebElement textField = getEditorWidgets().get(0);

    textField.click();
    // without this, the click in the middle of the field might not be after
    // the old text on some browsers
    new Actions(getDriver()).sendKeys(Keys.END).perform();

    textField.sendKeys(" changed");

    WebElement saveButton = getEditor().findElement(By.className("v-grid-editor-save"));

    saveButton.click();

    assertEquals("(100, 0) changed", getGridElement().getCell(100, 0).getText());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorBufferedTest.java

License:Apache License

@Test
public void testProgrammaticSave() {
    selectMenuPath(EDIT_ITEM_100);//w  w w.j a v  a2 s .  c om

    WebElement textField = getEditorWidgets().get(0);

    textField.click();
    // without this, the click in the middle of the field might not be after
    // the old text on some browsers
    new Actions(getDriver()).sendKeys(Keys.END).perform();

    textField.sendKeys(" changed");

    selectMenuPath("Component", "Editor", "Save");

    assertEquals("(100, 0) changed", getGridElement().getCell(100, 0).getText());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorBufferedTest.java

License:Apache License

@Test
public void testScrollDisabledOnMouseOpen() {
    int originalScrollPos = getGridVerticalScrollPos();

    GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
    new Actions(getDriver()).doubleClick(cell_5_0).perform();

    scrollGridVerticallyTo(100);//from   ww w  .  j a v a 2s  .  co  m
    assertEquals("Grid shouldn't scroll vertically while editing in buffered mode", originalScrollPos,
            getGridVerticalScrollPos());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorBufferedTest.java

License:Apache License

@Test
public void testScrollDisabledOnKeyboardOpen() {
    int originalScrollPos = getGridVerticalScrollPos();

    GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
    cell_5_0.click();//from   w  w  w . ja v  a  2s.co m
    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();

    scrollGridVerticallyTo(100);
    assertEquals("Grid shouldn't scroll vertically while editing in buffered mode", originalScrollPos,
            getGridVerticalScrollPos());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorTest.java

License:Apache License

@Test
public void testKeyboardOpeningClosing() {

    getGridElement().getCell(4, 0).click();
    assertEditorClosed();//  w w  w  . jav  a  2  s. co m

    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
    assertEditorOpen();

    new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();
    assertEditorClosed();

    // Disable Editor
    selectMenuPath(TOGGLE_EDIT_ENABLED);
    getGridElement().getCell(5, 0).click();
    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
    assertEditorClosed();
}