Search in sources :

Example 21 with TouchAction

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) TouchAction(io.appium.java_client.TouchAction)

Example 22 with TouchAction

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);
    }
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TouchAction(io.appium.java_client.TouchAction) WebDriverException(org.openqa.selenium.WebDriverException)

Example 23 with TouchAction

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());
    }
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) Direction(org.cerberus.engine.entity.SwipeAction.Direction) TouchAction(io.appium.java_client.TouchAction) IOSTouchAction(io.appium.java_client.ios.IOSTouchAction)

Example 24 with TouchAction

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();
    }
}
Also used : Point(org.openqa.selenium.Point) TouchAction(io.appium.java_client.TouchAction)

Example 25 with TouchAction

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