Example usage for org.openqa.selenium.interactions.touch TouchActions perform

List of usage examples for org.openqa.selenium.interactions.touch TouchActions perform

Introduction

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

Prototype

public void perform() 

Source Link

Document

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

Usage

From source file:com.ecofactor.qa.automation.platform.action.impl.AndroidUIAction.java

License:Open Source License

/**
 * Swipe.//from   w w w.j  a  va  2  s . c o  m
 * @param element the element
 * @param xCoordinate the x coordinate
 * @param yCoordinate the y coordinate
 * @param distance the distance
 * @param speed the speed
 * @param direction the direction
 * @see com.ecofactor.qa.automation.mobile.action.impl.AbstractMobileUIAction#swipe(org.openqa.selenium.WebElement,
 *      double, double, double, double,
 *      com.ecofactor.qa.automation.mobile.action.impl.AbstractUIAction.Direction)
 */
@Override
protected void swipe(final WebElement element, final double xCoordinate, final double yCoordinate,
        final double distance, final double speed, final Direction direction) {

    final int xOffset = (int) (getEndX(xCoordinate, distance, direction) - xCoordinate);
    final int yOffset = (int) (getEndY(yCoordinate, distance, direction) - yCoordinate);
    final int speedValue = (int) speed;
    final TouchActions flick = new TouchActions(driverOps.getDeviceDriver()).flick(element, xOffset, yOffset,
            speedValue);
    flick.perform();
    setLogString("Save mobile swipe screenshot for test: " + getTestName(), true);
}

From source file:com.ecofactor.qa.automation.platform.action.impl.AndroidUIAction.java

License:Open Source License

/**
 * swipe the window at window size./*from   www  .j a v a2s  . co m*/
 * @param element
 * @param xCoordinate
 * @param yCoordinate
 * @param speed
 * @param direction
 * @see com.ecofactor.qa.automation.platform.action.impl.AbstractMobileUIAction#swipe(org.openqa.selenium.WebElement,
 *      double, double, double,
 *      com.ecofactor.qa.automation.platform.action.impl.AbstractUIAction.Direction)
 */
@Override
protected void swipe(final WebElement element, final double xCoordinate, final double yCoordinate,
        final double speed, final Direction direction) {

    final int xOffset = (int) (getEndX(xCoordinate, getWindowWidth(element), direction));

    final int yOffset = (int) (getEndY(yCoordinate, getWindowHeight(element), direction));
    final int speedValue = (int) speed;

    final TouchActions flick = new TouchActions(driverOps.getDeviceDriver()).flick(element, xOffset, yOffset,
            speedValue);
    flick.perform();
    setLogString("Save mobile swipe screenshot for test: " + getTestName(), true);

}

From source file:com.nike.tests.MobileWebTest.java

License:Apache License

@Test
public void shouldSearchWithEbay() {
    // And now use this to visit ebay
    driver.get("http://m.ebay.de");

    System.out.println("starting flick");
    //WebElement pages = driver.findElement(By.id("vp_pages"));
    TouchActions flick = new TouchActions(driver).flick(100, 860);
    flick.perform();
    TouchActions swipe = new TouchActions(driver).scroll(-200, 860);
    swipe.perform();/*  w  w w .  j  a va2 s . co m*/

    TouchAction ta = (new TouchActionBuilder()).pointerDown(200, 860).pointerMove(100, 10).pointerUp().build();
    ta.perform(driver);
    System.out.println("done");
    // Find the text input element by its id
    WebElement element = driver.findElement(By.id("kw"));

    // Enter something to search for
    element.sendKeys("Nexus 5");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();
}

From source file:com.sugarcrm.candybean.examples.mobile.AppiumIosTest.java

License:Open Source License

@Test
public void testSlider() throws Exception {
    //get the slider
    WebElement slider = driver.findElement(By.xpath("//slider[1]"));
    assertEquals(slider.getAttribute("value"), "50%");
    TouchActions drag = new TouchActions(driver).flick(slider, new Integer(-1), 0, 0);
    drag.perform();
    assertEquals(slider.getAttribute("value"), "0%");
}

From source file:io.selendroid.nativetests.NativeElementInteractionTest.java

License:Apache License

@Test
public void shouldLongPressOnElement() {
    openStartActivity();//  ww  w  .ja v a 2  s.  co m
    WebElement button = driver().findElement(By.id("buttonTest"));
    TouchActions longPress = new TouchActions(driver()).longPress(button);
    longPress.perform();
    WebElement text = driver().findElement(By.partialLinkText("Long Press Tap"));
    Assert.assertNotNull(text);
    // TODO ddary this is essential, not perfect. must be refactored
    driver().findElement(By.id("button1")).click();
}

From source file:io.selendroid.nativetests.NativeElementInteractionTest.java

License:Apache License

@Test
public void shouldTapOnElement() {
    openStartActivity();/*from  w  w w  . j a  v  a 2s  .co m*/
    WebElement button = driver().findElement(By.id("buttonTest"));
    TouchActions longPress = new TouchActions(driver()).singleTap(button);
    longPress.perform();
    WebElement text = driver().findElement(By.partialLinkText("end the activity"));
    Assert.assertNotNull(text);
    // TODO ddary this is essential, not perfect. must be refactored
    driver().findElement(By.id("button2")).click();
}

From source file:io.selendroid.nativetests.UnhandledExceptionPropagatingTest.java

License:Apache License

@Test
public void shouldBeAbleToFetchExceptionAfterMotionEvent() {
    try {/*from ww w.ja v a 2  s .  c  o  m*/
        WebElement exceptionTestButton = driver().findElement(By.id("exceptionTestButton"));
        Assert.assertNotNull("Button should be found.", exceptionTestButton);
        TouchActions tapAction = new TouchActions(driver()).singleTap(exceptionTestButton);
        tapAction.perform();
    } catch (Exception e) {
        String message = e.getMessage();
        Assert.assertTrue(message.contains("Unhandled exception from application under test."));
        try {
            // Recover from the application crash which was made by intention.
            startSelendroidServer();
        } catch (Exception e1) {
            Assert.fail("Unable to restart selendroid server");
        }
        return;
    }
    Assert.fail("Should catch the exception.");
}

From source file:org.oneandone.qxwebdriver.ui.mobile.core.WidgetImpl.java

License:LGPL

public static void tap(WebDriver driver, WebElement element) {
    if (driver instanceof HasTouchScreen) {
        TouchActions tap = new TouchActions(driver).singleTap(element);
        tap.perform();
    } else {/*w w  w  .  j a  va 2s  . c  o m*/
        element.click();
    }
}

From source file:org.oneandone.qxwebdriver.ui.mobile.core.WidgetImpl.java

License:LGPL

public static void longtap(WebDriver driver, WebElement element) {
    if (driver instanceof HasTouchScreen) {
        TouchActions longtap = new TouchActions(driver);
        Point center = getCenter(element);
        longtap.down(center.getX(), center.getY());
        longtap.perform();
        try {/*ww  w. jav a 2s . c  o  m*/
            Thread.sleep(750);
        } catch (InterruptedException e) {
        }
        longtap.up(center.getX(), center.getY());
        longtap.perform();
    } else {
        Locatable locatable = (Locatable) element;
        Coordinates coords = locatable.getCoordinates();
        Mouse mouse = ((HasInputDevices) driver).getMouse();
        mouse.mouseDown(coords);
        try {
            Thread.sleep(750);
        } catch (InterruptedException e) {
        }
        mouse.mouseUp(coords);
    }
}