iOS Vertical Swipe is performed as Horizontal Swipe in Appium 1.7.2

我是研究僧i 提交于 2019-12-08 11:29:46

问题


I am using the below code to swipe vertically in my iOS real device automation project, but during execution it is actually performing horizontal swipe.

Dimension size = driver.manage().window().getSize();
int starty = (int) (size.height * 0.80);
int endy = (int) (size.height * 0.20);
int startx = size.width / 2;
driver.swipe(startx, starty, startx, endy, 2000);

Can anyone please let me know if I have done anything wrong?

Xcode version: 8.3.2 iOS version: 10.2 Appium Version: 1.7.2


回答1:


driver.swipe is deprecated in Appium Java client. You should stop using it.

For doing vertical swipe on iOS Appium exposes mobile:swipe and if you need to set direction - mobile:scroll

Python:

driver.execute_script('mobile: scroll', {'direction': 'down'});



回答2:


I'm using this one, and it works both ways, vertical & horizontal:

public enum DIRECTION {
    DOWN, UP, LEFT, RIGHT;
}


public static void swipe(MobileDriver driver, DIRECTION direction, long duration) {
    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);
            new TouchAction(driver)
                    .press(startX, startY)
                    .waitAction(Duration.ofMillis(duration))
                    .moveTo(endX, startY)
                    .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;

    }
}


来源:https://stackoverflow.com/questions/50332661/ios-vertical-swipe-is-performed-as-horizontal-swipe-in-appium-1-7-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!