use of io.appium.java_client.TouchAction in project carina by qaprosoft.
the class MobileUtils method longPress.
/**
* Tap and Hold (LongPress) on element
*
* @param element ExtendedWebElement
* @return boolean
*/
public static boolean longPress(ExtendedWebElement element) {
try {
WebDriver driver = DriverPool.getDriver();
TouchAction action = new TouchAction((MobileDriver<?>) driver);
action.longPress(element.getElement()).release().perform();
return true;
} catch (Exception e) {
LOGGER.info("Error occurs: " + e);
}
return false;
}
use of io.appium.java_client.TouchAction in project cerberus-source by cerberustesting.
the class AppiumService method type.
@Override
public MessageEvent type(Session session, Identifier identifier, String property, String propertyName) {
MessageEvent message;
try {
if (!StringUtil.isNull(property)) {
TouchAction action = new TouchAction(session.getAppiumDriver());
action.press(this.getElement(session, identifier, false, false)).release().perform();
session.getAppiumDriver().getKeyboard().pressKey(property);
}
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
if (!StringUtil.isNull(property)) {
message.setDescription(message.getDescription().replace("%DATA%", ParameterParserUtil.securePassword(property, propertyName)));
} else {
message.setDescription(message.getDescription().replace("%DATA%", "No property"));
}
return message;
} catch (NoSuchElementException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
LOG.debug(exception.toString());
return message;
} catch (WebDriverException exception) {
LOG.fatal(exception.toString());
return parseWebDriverException(exception);
}
}
use of io.appium.java_client.TouchAction in project cerberus-source by cerberustesting.
the class IOSAppiumService method swipe.
@Override
public MessageEvent swipe(Session session, SwipeAction action) {
try {
Direction direction = this.getDirectionForSwipe(session, action);
// Get the parametrized swipe duration
Integer myduration = parameters.getParameterIntegerByKey(CERBERUS_APPIUM_SWIPE_DURATION_PARAMETER, "", DEFAULT_CERBERUS_APPIUM_SWIPE_DURATION);
// Do the swipe thanks to the Appium driver
TouchAction dragNDrop = new TouchAction(session.getAppiumDriver()).press(direction.getX1(), direction.getY1()).waitAction(Duration.ofMillis(myduration)).moveTo(direction.getX2(), direction.getY2()).release();
dragNDrop.perform();
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWIPE).resolveDescription("DIRECTION", action.getActionType().name());
} catch (IllegalArgumentException e) {
return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE).resolveDescription("DIRECTION", action.getActionType().name()).resolveDescription("REASON", "Unknown direction");
} catch (Exception e) {
LOG.warn("Unable to swipe screen due to " + e.getMessage(), e);
return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE).resolveDescription("DIRECTION", action.getActionType().name()).resolveDescription("REASON", e.getMessage());
}
}
use of io.appium.java_client.TouchAction in project opentest by mcdcorp.
the class AppiumTestAction method swipe.
protected void swipe(int fromX, int fromY, int toX, int toY, int durationMs) {
// follows below is necessary to work around this inconsistency.
if (AppiumHelper.isPlatform("ios") && AppiumHelper.getConfig().getBoolean("appium.useRelativeCoordsIos", true)) {
int relativeX = toX - fromX;
int relativeY = toY - fromY;
(new TouchAction(driver)).press(PointOption.point(fromX, fromY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(durationMs))).moveTo(PointOption.point(relativeX, relativeY)).release().perform();
} else {
(new TouchAction(driver)).press(PointOption.point(fromX, fromY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(durationMs))).moveTo(PointOption.point(toX, toY)).release().perform();
}
}
use of io.appium.java_client.TouchAction in project opentest by mcdcorp.
the class LongPress method run.
@Override
public void run() {
super.run();
By locator = this.readLocatorArgument("locator");
Integer durationMs = this.readIntArgument("durationMs", null);
this.swipeAndCheckElementVisible(locator, this.getSwipeOptions());
MobileElement element = this.getElement(locator);
TouchAction action = new TouchAction((MobileDriver) driver);
if (durationMs == null) {
action.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(element)));
} else {
action.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(element)).withDuration(Duration.ofMillis(durationMs)));
}
action.release().perform();
}
Aggregations