Search in sources :

Example 1 with PerformsTouchActions

use of io.appium.java_client.PerformsTouchActions in project seleniumRobot by bhecquet.

the class HtmlElement method pinch.

@ReplayOnError(waitAfterAction = true)
public void pinch() {
    PerformsTouchActions performTouchActions = checkForMobile();
    MobileElement mobElement = (MobileElement) getUnderlyingElement(getRealElementNoSearch());
    // code taken from appium
    MultiTouchAction multiTouch = new MultiTouchAction(performTouchActions);
    Point upperLeft = mobElement.getLocation();
    Point center = mobElement.getCenter();
    int yOffset = center.getY() - upperLeft.getY();
    TouchAction<?> action0 = createTouchAction().press(ElementOption.element(mobElement, center.getX(), center.getY() - yOffset)).moveTo(ElementOption.element(mobElement)).release();
    TouchAction<?> action1 = createTouchAction().press(ElementOption.element(mobElement, center.getX(), center.getY() + yOffset)).moveTo(ElementOption.element(mobElement)).release();
    multiTouch.add(action0).add(action1).perform();
}
Also used : MultiTouchAction(io.appium.java_client.MultiTouchAction) MobileElement(io.appium.java_client.MobileElement) Point(org.openqa.selenium.Point) PerformsTouchActions(io.appium.java_client.PerformsTouchActions) Point(org.openqa.selenium.Point) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 2 with PerformsTouchActions

use of io.appium.java_client.PerformsTouchActions in project seleniumRobot by bhecquet.

the class HtmlElement method zoom.

@ReplayOnError(waitAfterAction = true)
public void zoom() {
    PerformsTouchActions performTouchActions = checkForMobile();
    MobileElement mobElement = (MobileElement) getUnderlyingElement(getRealElementNoSearch());
    MultiTouchAction multiTouch = new MultiTouchAction(performTouchActions);
    Point upperLeft = mobElement.getLocation();
    Point center = mobElement.getCenter();
    int yOffset = center.getY() - upperLeft.getY();
    TouchAction<?> action0 = createTouchAction().press(PointOption.point(center.getX(), center.getY())).moveTo(ElementOption.element(mobElement, center.getX(), center.getY() - yOffset)).release();
    TouchAction<?> action1 = createTouchAction().press(PointOption.point(center.getX(), center.getY())).moveTo(ElementOption.element(mobElement, center.getX(), center.getY() + yOffset)).release();
    multiTouch.add(action0).add(action1).perform();
}
Also used : MultiTouchAction(io.appium.java_client.MultiTouchAction) MobileElement(io.appium.java_client.MobileElement) Point(org.openqa.selenium.Point) PerformsTouchActions(io.appium.java_client.PerformsTouchActions) Point(org.openqa.selenium.Point) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 3 with PerformsTouchActions

use of io.appium.java_client.PerformsTouchActions in project seleniumRobot by bhecquet.

the class Element method createTouchAction.

/**
 * Creates a TouchAction depending on mobile platform. Due to appium 6.0.0 changes
 * @return
 */
protected TouchAction<?> createTouchAction() {
    String platform = SeleniumTestsContextManager.getThreadContext().getPlatform();
    PerformsTouchActions performTouchActions = checkForMobile();
    if (platform.toLowerCase().startsWith("android")) {
        return new TouchAction<>(performTouchActions);
    } else if (platform.toLowerCase().startsWith("ios")) {
        return new TouchAction<>(performTouchActions);
    } else {
        throw new ConfigurationException(String.format("%s platform is not supported", platform));
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) PerformsTouchActions(io.appium.java_client.PerformsTouchActions) TouchAction(io.appium.java_client.TouchAction)

Example 4 with PerformsTouchActions

use of io.appium.java_client.PerformsTouchActions in project seleniumRobot by bhecquet.

the class Element method checkForMobile.

/**
 * Check if the current platform is a mobile platform
 * if it's the case, search for the element, else, raise a ScenarioException
 */
protected PerformsTouchActions checkForMobile() {
    CustomEventFiringWebDriver driver = (CustomEventFiringWebDriver) WebUIDriver.getWebDriver(false);
    if (driver == null) {
        throw new ScenarioException("Driver has not already been created");
    }
    if (!SeleniumTestsContextManager.isMobileTest()) {
        throw new ScenarioException("action is available only for mobile platforms");
    }
    if (!(driver.getWebDriver() instanceof AppiumDriver<?>)) {
        throw new ScenarioException("action is available only for mobile platforms");
    }
    findElement(true);
    return (PerformsTouchActions) driver.getWebDriver();
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) AppiumDriver(io.appium.java_client.AppiumDriver) ScenarioException(com.seleniumtests.customexception.ScenarioException) PerformsTouchActions(io.appium.java_client.PerformsTouchActions)

Example 5 with PerformsTouchActions

use of io.appium.java_client.PerformsTouchActions in project seleniumRobot by bhecquet.

the class HtmlElement method tap.

/**
 * Tap with X fingers on screen
 *
 * @param fingers  number of fingers to tap with
 * @param duration duration in ms to wait before releasing
 */
@ReplayOnError(waitAfterAction = true)
public void tap(int fingers, int duration) {
    PerformsTouchActions performTouchActions = checkForMobile();
    MobileElement mobElement = (MobileElement) getUnderlyingElement(getRealElementNoSearch());
    // code from appium
    MultiTouchAction multiTouch = new MultiTouchAction(performTouchActions);
    for (int i = 0; i < fingers; i++) {
        TouchAction<?> tap = createTouchAction();
        multiTouch.add(tap.press(ElementOption.element(mobElement)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration))).release());
    }
    multiTouch.perform();
}
Also used : MultiTouchAction(io.appium.java_client.MultiTouchAction) MobileElement(io.appium.java_client.MobileElement) PerformsTouchActions(io.appium.java_client.PerformsTouchActions) Point(org.openqa.selenium.Point) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Aggregations

PerformsTouchActions (io.appium.java_client.PerformsTouchActions)5 ReplayOnError (com.seleniumtests.uipage.ReplayOnError)3 MobileElement (io.appium.java_client.MobileElement)3 MultiTouchAction (io.appium.java_client.MultiTouchAction)3 Point (org.openqa.selenium.Point)3 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)1 AppiumDriver (io.appium.java_client.AppiumDriver)1 TouchAction (io.appium.java_client.TouchAction)1