use of io.appium.java_client.TouchAction in project cerberus-source by cerberustesting.
the class AppiumService method click.
@Override
public MessageEvent click(final Session session, final Identifier identifier) {
try {
final TouchAction action = new TouchAction(session.getAppiumDriver());
if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {
final Coordinates coordinates = getCoordinates(identifier);
action.tap(coordinates.getX(), coordinates.getY()).perform();
} else {
action.tap(getElement(session, identifier, false, false)).perform();
}
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICK).resolveDescription("ELEMENT", identifier.toString());
} catch (NoSuchElementException e) {
if (LOG.isDebugEnabled()) {
LOG.debug(e.getMessage());
}
return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT).resolveDescription("ELEMENT", identifier.toString());
} catch (WebDriverException e) {
LOG.warn(e.getMessage());
return parseWebDriverException(e);
}
}
use of io.appium.java_client.TouchAction 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 io.appium.java_client.TouchAction in project java-client by appium.
the class AndroidTouchTest method dragNDropByCoordinatesTest.
@Test
public void dragNDropByCoordinatesTest() {
Activity activity = new Activity("io.appium.android.apis", ".view.DragAndDropDemo");
driver.startActivity(activity);
AndroidElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
AndroidElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));
WebElement dragText = driver.findElement(By.id("io.appium.android.apis:id/drag_text"));
assertEquals("Drag text not empty", "", dragText.getText());
Point center1 = dragDot1.getCenter();
Point center2 = dragDot3.getCenter();
TouchAction dragNDrop = new TouchAction(driver).longPress(point(center1.x, center1.y)).moveTo(point(center2.x, center2.y)).release();
dragNDrop.perform();
assertNotEquals("Drag text empty", "", dragText.getText());
}
use of io.appium.java_client.TouchAction in project java-client by appium.
the class AndroidTouchTest method tapActionTestByElement.
@Test
public void tapActionTestByElement() throws Exception {
Activity activity = new Activity("io.appium.android.apis", ".view.ChronometerDemo");
driver.startActivity(activity);
AndroidElement chronometer = driver.findElementById("io.appium.android.apis:id/chronometer");
TouchAction startStop = new TouchAction(driver).tap(tapOptions().withElement(element(driver.findElementById("io.appium.android.apis:id/start")))).waitAction(waitOptions(ofSeconds(2))).tap(tapOptions().withElement(element(driver.findElementById("io.appium.android.apis:id/stop"))));
startStop.perform();
String time = chronometer.getText();
assertNotEquals(time, "Initial format: 00:00");
Thread.sleep(2500);
assertEquals(time, chronometer.getText());
}
use of io.appium.java_client.TouchAction in project java-client by appium.
the class AndroidTouchTest method tapActionTestByCoordinates.
@Test
public void tapActionTestByCoordinates() throws Exception {
Activity activity = new Activity("io.appium.android.apis", ".view.ChronometerDemo");
driver.startActivity(activity);
AndroidElement chronometer = driver.findElementById("io.appium.android.apis:id/chronometer");
Point center1 = driver.findElementById("io.appium.android.apis:id/start").getCenter();
TouchAction startStop = new TouchAction(driver).tap(point(center1.x, center1.y)).tap(element(driver.findElementById("io.appium.android.apis:id/stop"), 5, 5));
startStop.perform();
String time = chronometer.getText();
assertNotEquals(time, "Initial format: 00:00");
Thread.sleep(2500);
assertEquals(time, chronometer.getText());
}
Aggregations