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.calendar.CalendarNotificationsTestIE.java

License:Apache License

@Test
public void notificationTest() throws Exception {
    openTestURL();/*from  www. jav  a  2 s. co m*/

    WebElement day = findElements(By.className("v-calendar-day-number")).get(2);
    // IE8 requires you to click on the text part to fire the event
    new Actions(getDriver()).moveToElement(day, day.getSize().getWidth() - 3, day.getSize().getHeight() / 2)
            .click().perform();

    // check that a notification was opened, this is done with a log instead
    // of a screenshot or element presence check due to problems with IE
    // webdriver
    String text = findElement(By.id("Log")).findElement(By.className("v-label")).getText();
    Assert.assertTrue("Notification should've opened", "1. Opening a notification".equals(text));

    // move the mouse around a bit
    new Actions(getDriver()).moveByOffset(5, 5).moveByOffset(100, 100).perform();

    // wait until the notification has animated out
    sleep(1000);

    Assert.assertFalse("There should be no notification on the page", $(NotificationElement.class).exists());
}

From source file:com.vaadin.tests.components.calendar.CalendarResizeOverlappingEventsTest.java

License:Apache License

private void dragAndDrop(WebElement element, int yOffset) {
    /*/*  ww w  .  j av a 2s. c  om*/
     * Selenium doesn't properly drag and drop items in IE8. It tries to
     * start dragging an element from a position above the element itself.
     */
    if (BrowserUtil.isIE8(getDesiredCapabilities())) {
        Actions action = new Actions(getDriver());
        action.moveToElement(element);
        action.moveByOffset(0, 1);
        action.clickAndHold();
        action.moveByOffset(0, yOffset);
        action.release();
        action.build().perform();
    } else {
        Actions action = new Actions(getDriver());
        action.dragAndDropBy(element, 0, yOffset);
        action.build().perform();
    }
}

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

License:Apache License

@Test
public void testComboboxPageLength() {
    openTestURL();/*from  w ww .  j  a va 2 s  .c o  m*/

    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.datefield.AbstractDateFieldTestTest.java

License:Apache License

private void openPopup() throws InterruptedException {
    Dimension size = getInput().getSize();
    new Actions(getDriver()).moveToElement(getInput(), 0, 0)
            .moveByOffset(size.getWidth() + 5, size.getHeight() / 2).click();
    // This fails in Opera for some weird reason
    // getDriver().findElement(By.className("v-datefield-button")).click();
}

From source file:com.vaadin.tests.components.datefield.AbstractDateFieldTestTest.java

License:Apache License

/**
 * @since//from   www  .  jav a 2 s  . c o m
 * @param string
 */
private void menuSub(String string) {
    getDriver().findElement(By.xpath("//span[text() = '" + string + "']")).click();
    new Actions(getDriver()).moveByOffset(100, 0).build().perform();
}

From source file:com.vaadin.tests.components.datefield.DateFieldValueChangeEventsTest.java

License:Apache License

@Test
public void tb2test() throws Exception {
    openTestURL();// w  w w  . ja v  a  2s.  c om
    getPopUpButton().click();
    getCalendarDayElement(2, 1).click();
    Assert.assertEquals("1. Value changes: 1", getLogRow(0));
    getPopUpButton().click();
    new Select(getHoursSelect()).selectByValue("01");
    new Select(getMinutesSelect()).selectByValue("02");
    new Select(getSecondsSelect()).selectByValue("03");
    new Actions(driver).sendKeys(getSecondsSelect(), Keys.ENTER).perform();
    $(LabelElement.class).first().click();
    Assert.assertEquals("2. Value changes: 2", getLogRow(0));
    getResolutionSelect().selectByText("Month");
    getPopUpButton().click();
    getNextMonthButton().click();
    getNextYearButton().click();
    getNextMonthButton().click();
    getNextMonthButton().sendKeys(Keys.ENTER);
    Assert.assertEquals("3. Value changes: 3", getLogRow(0));
}

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

License:Apache License

@Test
public void testTextAreaDndImage() {
    openTestURL();//from  w ww  . j a  v a  2 s.  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);

}

From source file:com.vaadin.tests.components.grid.basicfeatures.client.DisabledGridClientTest.java

License:Apache License

@Test
public void testEditorOpening() {
    selectMenuPath("Component", "Editor", "Enabled");
    GridRowElement row = getGridElement().getRow(0);
    GridCellElement cell = getGridElement().getCell(0, 0);
    cell.click();/*from   www  .  j  a va2s .c  om*/
    assertNull("Editor should not open", getEditor());

    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
    assertNull("Editor should not open", getEditor());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.client.GridClientContextMenuEventTest.java

License:Apache License

@Test
public void testContextMenuEventIsHandledCorrectly() {
    setDebug(true);/*  w w w .ja  va  2  s .c  o  m*/
    openTestURL();

    selectMenuPath("Component", "Internals", "Listeners", "Add context menu listener");

    openDebugLogTab();
    clearDebugMessages();

    new Actions(getDriver()).moveToElement(getGridElement().getCell(0, 0), 5, 5).contextClick().perform();

    assertTrue("Debug log was not visible",
            isElementPresent(By.xpath("//span[text() = 'Prevented opening a context menu in grid body']")));

    new Actions(getDriver()).moveToElement(getGridElement().getHeaderCell(0, 0), 5, 5).contextClick().perform();

    assertTrue("Debug log was not visible",
            isElementPresent(By.xpath("//span[text() = 'Prevented opening a context menu in grid header']")));

}

From source file:com.vaadin.tests.components.grid.basicfeatures.client.GridClientKeyEventsTest.java

License:Apache License

@Test
public void testBodyKeyEvents() throws IOException {
    openTestURL();/*from  w ww  .j a  v  a  2  s.com*/

    getGridElement().getCell(2, 2).click();

    new Actions(getDriver()).sendKeys("a").perform();

    for (int i = 0; i < 3; ++i) {
        assertEquals("Body key event handler was not called.",
                "(2, 2) event: GridKey" + eventOrder.get(i) + "Event:["
                        + (eventOrder.get(i).equals("Press") ? "a" : 65) + "]",
                findElements(By.className("v-label")).get(i * 3).getText());

        assertTrue("Header key event handler got called unexpectedly.",
                findElements(By.className("v-label")).get(i * 3 + 1).getText().isEmpty());
        assertTrue("Footer key event handler got called unexpectedly.",
                findElements(By.className("v-label")).get(i * 3 + 2).getText().isEmpty());
    }

}