如何在Appium中检测刷卡完成

时间:2018-07-17 20:58:09

标签: appium appium-android

Android有一个swipe container视图,我用Appium滑动以刷新ListView。如何使用Appium检测刷卡完成?

修改

对不起,我的问题不清楚。我想让Appium不在弹出手势完成时检测到,而是在刷新动画完成时检测到的方法。也许我应该问一个单独的问题。

1 个答案:

答案 0 :(得分:0)

我过去有过类似情况。因此,我将所有屏幕元素都放在了PageObject设计模式中。因此,每次滑动之后,我都只是重新初始化屏幕,并通过该逻辑重新初始化其所有元素,并且可以确定的是,我已经检查了某些元素是否已加载到该屏幕上,因此伪代码如下所示:

public void checkSwipeScreen(){
    swipe(driver, DIRECTION.LEFT, 5);
    Screen screen = new Screen(driver);
    Assert.assertTrue(screen.elementIsLoaded(button), "Screen is not loaded properly");
}

因此,如果在您的新屏幕上加载了全部/一个元素,则滑动成功。

使用最后一个参数,您可以控制滑动时间是否更长(持续时间长)。

如果您愿意,这里是滑动方法:

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;

    }
}

和枚举

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

希望这会有所帮助,