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