ModaKolla
ModaKolla

Reputation: 137

How to swipe Up, Down, Left and right in appium Java IOS

.moveTo() // shows this error: The method moveTo(PointOption) is undefined for the type WaitOptions.

I do the provided quick fix which is: add cast to method receiver

Following error shows: The method waitAction(WaitOptions) in the type TouchAction is not applicable for the arguments (TouchAction)

java version "1.8.0_191" Simulator - iPhone x (IOS 12) Appium 1.9.0

public static void swipe(MobileDriver driver, DIRECTION direction, long duration) {
    org.openqa.selenium.Dimension size = driver.manage().window().getSize();

    int startX = 0;
    int endX = 0;
    int startY = 0;
    int endY = 0;

    switch (direction) {
        case RIGHT:
            startY = (int) (size.height / 2);
            startX = (int) (size.width * 0.90);
            endX = (int) (size.width * 0.05);
            TouchAction action = new TouchAction(driver);
            action.press(PointOption.point(427, 878))
            .waitAction(WaitOptions
                    .waitOptions(Duration
                            .ofMillis(1300))
                    .moveTo(PointOption.point(427, 554))
                    .release().perform();

            break;

        case LEFT:
            startY = (int) (size.height / 2);
            startX = (int) (size.width * 0.05);
            endX = (int) (size.width * 0.90);
            new TouchAction(driver)
                    .press(startX, startY)
                    .waitAction(Duration.ofMillis(duration))
                    .moveTo(endX, startY)
                    .release()
                    .perform();

            break;

        case UP:
            endY = (int) (size.height * 0.70);
            startY = (int) (size.height * 0.30);
            startX = (size.width / 2);
            new TouchAction(driver)
                    .press(startX, startY)
                    .waitAction(Duration.ofMillis(duration))
                    .moveTo(endX, startY)
                    .release()
                    .perform();
            break;


        case DOWN:
            startY = (int) (size.height * 0.70);
            endY = (int) (size.height * 0.30);
            startX = (size.width / 2);
            new TouchAction(driver)
                    .press(startX, startY)
                    .waitAction(Duration.ofMillis(duration))
                    .moveTo(startX, endY)
                    .release()
                    .perform();

            break;

    }
}

If use

public enum DIRECTION { LEFT }

I expect it to swipe left

Upvotes: 1

Views: 1614

Answers (1)

Amit Jain
Amit Jain

Reputation: 4587

waitAction method does not accept java.time.Duration duration it has to be passed using waitOptions as you have used in RIGHT case. Check waitOptions details here

Similarly moveTo and press accept PointOptions and directly coordinates cannot be passed.

    case LEFT:
        startY = (int) (size.height / 2);
       startX = (int) (size.width * 0.05);
        endX = (int) (size.width * 0.90);
        new TouchAction(driver)
                .press(PointOption.point(startX, startY))
                .waitAction(WaitOptions
                .waitOptions(Duration
                        .ofMillis(duration))
                .moveTo(PointOption.point(endX, startY))
                .release()
                .perform();

Upvotes: 1

Related Questions