Search in sources :

Example 6 with TouchAction

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);
    }
}
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 7 with TouchAction

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

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

Example 9 with TouchAction

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());
}
Also used : TouchAction(io.appium.java_client.TouchAction) MultiTouchAction(io.appium.java_client.MultiTouchAction) Test(org.junit.Test)

Example 10 with TouchAction

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

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