Search in sources :

Example 26 with TouchAction

use of io.appium.java_client.TouchAction in project opentest by mcdcorp.

the class Tap method run.

@Override
public void run() {
    super.run();
    By locator = this.readLocatorArgument("locator", null);
    Integer xOffset = this.readIntArgument("xOffset", null);
    Integer yOffset = this.readIntArgument("yOffset", null);
    Integer x = this.readIntArgument("x", null);
    Integer y = this.readIntArgument("y", null);
    if (locator != null) {
        this.swipeAndCheckElementVisible(locator, this.getSwipeOptions());
        MobileElement element = this.getElement(locator);
        if (xOffset == null || yOffset == null) {
            element.click();
        } else {
            (new TouchAction(driver)).tap(TapOptions.tapOptions().withElement(ElementOption.element(element, xOffset != null ? xOffset : 0, yOffset != null ? yOffset : 0))).perform();
        }
    } else if (x != null && y != null) {
        (new TouchAction(driver)).tap(TapOptions.tapOptions().withPosition(PointOption.point(x, y))).perform();
    } else {
        throw new RuntimeException("You must either provide the locator argument of the element to tap, " + "or the x and y arguments to indicate the exact coordinates to tap at.");
    }
}
Also used : MobileElement(io.appium.java_client.MobileElement) By(org.openqa.selenium.By) TouchAction(io.appium.java_client.TouchAction)

Aggregations

TouchAction (io.appium.java_client.TouchAction)26 MultiTouchAction (io.appium.java_client.MultiTouchAction)12 Test (org.junit.Test)12 MobileElement (io.appium.java_client.MobileElement)6 Point (org.openqa.selenium.Point)6 MessageEvent (org.cerberus.engine.entity.MessageEvent)4 Dimension (org.openqa.selenium.Dimension)4 WebElement (org.openqa.selenium.WebElement)4 WebDriver (org.openqa.selenium.WebDriver)3 By (org.openqa.selenium.By)2 NoSuchElementException (org.openqa.selenium.NoSuchElementException)2 WebDriverException (org.openqa.selenium.WebDriverException)2 MobileDriver (io.appium.java_client.MobileDriver)1 IOSTouchAction (io.appium.java_client.ios.IOSTouchAction)1 ElementOption (io.appium.java_client.touch.offset.ElementOption)1 PointOption.point (io.appium.java_client.touch.offset.PointOption.point)1 Parameter (org.cerberus.crud.entity.Parameter)1 SwipeAction (org.cerberus.engine.entity.SwipeAction)1 Direction (org.cerberus.engine.entity.SwipeAction.Direction)1 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)1