iOS垂直滑动在Appium 1.7.2中作为水平滑动执行

时间:2018-05-14 14:21:36

标签: java appium-ios

我使用以下代码在我的iOS实际设备自动化项目中垂直滑动,但在执行期间它实际上执行水平滑动。

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);

如果我做错了什么,有人可以告诉我吗?

Xcode版本:8.3.2 iOS版:10.2 Appium版本:1.7.2

2 个答案:

答案 0 :(得分:0)

Appium Java客户端

driver.swipe 已弃用。你应该停止使用它。

在iOS上执行垂直滑动 Appium公开mobile:swipe,如果您需要设置方向 - mobile:scroll

Python:

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

答案 1 :(得分:0)

我使用这个,它可以双向工作,垂直和放大水平:

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;

    }
}