Search in sources :

Example 1 with SwipeAction

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

the class AndroidAppiumService method swipe.

@Override
public MessageEvent swipe(Session session, SwipeAction action) {
    try {
        SwipeAction.Direction direction = this.getDirectionForSwipe(session, action);
        // Get the parametrized swipe duration
        Parameter duration = parameters.findParameterByKey(CERBERUS_APPIUM_SWIPE_DURATION_PARAMETER, "");
        // Do the swipe thanks to the Appium driver
        TouchAction dragNDrop = new TouchAction(session.getAppiumDriver()).press(direction.getX1(), direction.getY1()).waitAction(Duration.ofMillis(duration == null ? DEFAULT_CERBERUS_APPIUM_SWIPE_DURATION : Integer.parseInt(duration.getValue()))).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) SwipeAction(org.cerberus.engine.entity.SwipeAction) Parameter(org.cerberus.crud.entity.Parameter) TouchAction(io.appium.java_client.TouchAction)

Example 2 with SwipeAction

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

the class SwipeActionTest method testCreateCustomAction.

@Test
public void testCreateCustomAction() throws Exception {
    SwipeAction action = SwipeAction.fromStrings("CUSTOM", "0;1;2;3");
    Assert.assertEquals(SwipeAction.ActionType.CUSTOM, action.getActionType());
    Assert.assertTrue(action.isCustom());
    Assert.assertEquals(0, action.getCustomDirection().getX1());
    Assert.assertEquals(1, action.getCustomDirection().getY1());
    Assert.assertEquals(2, action.getCustomDirection().getX2());
    Assert.assertEquals(3, action.getCustomDirection().getY2());
}
Also used : SwipeAction(org.cerberus.engine.entity.SwipeAction) Test(org.junit.Test)

Example 3 with SwipeAction

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

the class ActionService method doActionSwipe.

private MessageEvent doActionSwipe(TestCaseExecution tCExecution, String object, String property) {
    // Check arguments
    if (tCExecution == null || object == null) {
        return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);
    }
    // Create the associated swipe action to the given arguments
    SwipeAction action = null;
    try {
        action = SwipeAction.fromStrings(object, property);
    } catch (Exception e) {
        return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE).resolveDescription("DIRECTION", action == null ? "Unknown" : action.getActionType().name()).resolveDescription("REASON", e.getMessage());
    }
    // Swipe screen according to the application type
    String applicationType = tCExecution.getApplicationObj().getType();
    if (Application.TYPE_APK.equals(applicationType)) {
        return androidAppiumService.swipe(tCExecution.getSession(), action);
    }
    if (Application.TYPE_IPA.equals(applicationType)) {
        return iosAppiumService.swipe(tCExecution.getSession(), action);
    }
    // Else we are faced with a non supported application
    return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION).resolveDescription("ACTION", "Swipe screen").resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) SwipeAction(org.cerberus.engine.entity.SwipeAction) CerberusEventException(org.cerberus.exception.CerberusEventException) CerberusException(org.cerberus.exception.CerberusException)

Example 4 with SwipeAction

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

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

the class SwipeActionTest method testCreateCommonAction.

@Test
public void testCreateCommonAction() throws Exception {
    SwipeAction action = SwipeAction.fromStrings("UP", null);
    Assert.assertEquals(SwipeAction.ActionType.UP, action.getActionType());
    Assert.assertFalse(action.isCustom());
}
Also used : SwipeAction(org.cerberus.engine.entity.SwipeAction) Test(org.junit.Test)

Aggregations

SwipeAction (org.cerberus.engine.entity.SwipeAction)5 MessageEvent (org.cerberus.engine.entity.MessageEvent)2 Test (org.junit.Test)2 TouchAction (io.appium.java_client.TouchAction)1 Parameter (org.cerberus.crud.entity.Parameter)1 Direction (org.cerberus.engine.entity.SwipeAction.Direction)1 CerberusEventException (org.cerberus.exception.CerberusEventException)1 CerberusException (org.cerberus.exception.CerberusException)1 Dimension (org.openqa.selenium.Dimension)1