Search in sources :

Example 1 with Direction

use of org.cerberus.engine.entity.SwipeAction.Direction in project cerberus-source by cerberustesting.

the class AppiumService method getDirectionForSwipe.

/**
 * @param session
 * @param action
 * @return
 * @throws IllegalArgumentException
 */
@Override
public Direction getDirectionForSwipe(Session session, SwipeAction action) throws IllegalArgumentException {
    Dimension window = session.getAppiumDriver().manage().window().getSize();
    SwipeAction.Direction direction;
    switch(action.getActionType()) {
        case UP:
            direction = SwipeAction.Direction.fromLine(new Line2D.Double(window.getWidth() / 2, 2 * window.getHeight() / 3, 0, -window.getHeight() / 3));
            break;
        case DOWN:
            direction = SwipeAction.Direction.fromLine(new Line2D.Double(window.getWidth() / 2, window.getHeight() / 3, 0, window.getHeight() / 3));
            break;
        case LEFT:
            direction = SwipeAction.Direction.fromLine(new Line2D.Double(2 * window.getWidth() / 3, window.getHeight() / 2, -window.getWidth() / 3, 0));
            break;
        case RIGHT:
            direction = SwipeAction.Direction.fromLine(new Line2D.Double(window.getWidth() / 3, window.getHeight() / 2, window.getWidth() / 3, 0));
            break;
        case CUSTOM:
            direction = action.getCustomDirection();
            break;
        default:
            throw new IllegalArgumentException("Unknown direction");
    }
    return direction;
}
Also used : SwipeAction(org.cerberus.engine.entity.SwipeAction) Dimension(org.openqa.selenium.Dimension) Direction(org.cerberus.engine.entity.SwipeAction.Direction)

Example 2 with Direction

use of org.cerberus.engine.entity.SwipeAction.Direction 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)

Aggregations

Direction (org.cerberus.engine.entity.SwipeAction.Direction)2 TouchAction (io.appium.java_client.TouchAction)1 IOSTouchAction (io.appium.java_client.ios.IOSTouchAction)1 MessageEvent (org.cerberus.engine.entity.MessageEvent)1 SwipeAction (org.cerberus.engine.entity.SwipeAction)1 Dimension (org.openqa.selenium.Dimension)1