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();
}
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();
}
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));
}
}
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();
}
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();
}
Aggregations