向左或向右滑动不适用于app app的appium

时间:2017-01-31 14:00:19

标签: java appium

我正试图从第一个内容向右滑动(左侧没有内容) 到目前为止我在下面使用,但它不起作用,

public void swipeRightToLeft() {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, Double> swipeObject = new HashMap<String, Double>();
    swipeObject.put("startX", 0.9);
    swipeObject.put("startY", 0.5);
    swipeObject.put("endX", 0.01);
    swipeObject.put("endY", 0.5);
    swipeObject.put("duration", 3.0);
    js.executeScript("mobile: swipe", swipeObject);

}

错误日志:org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)

1 个答案:

答案 0 :(得分:0)

public void swipe(String direction, int offset, int time) {

        int y = appiumDriver.manage().window().getSize().getHeight();
        int x = appiumDriver.manage().window().getSize().getWidth();
        TouchAction touchAction = new TouchAction(appiumDriver);
        System.out.println(x + " " + y);
        System.out.println("Entering swipe");
        if ("right".equalsIgnoreCase(direction)) {
            System.out.println("Swipe Right");
            touchAction.press(x - offset, y / 2).moveTo(-(x - (2 * offset)), 0).release().perform();
        } else if ("left".equalsIgnoreCase(direction)) {
            System.out.println("Swipe Left");
            touchAction.press(offset, y / 2).moveTo((x - (2 * offset)), 0).release().perform();
        } else if ("up".equalsIgnoreCase(direction)) {
            System.out.println("Swipe Up");
            touchAction.press(x / 2, offset).moveTo(0, y - (2 * offset)).release().perform();
        } else if ("down".equalsIgnoreCase(direction)) {
            System.out.println("Swipe Down");
            touchAction.press(x / 2, y - offset).moveTo(0, -(y - (2 * offset))).release().perform();
        } else {
            throw new FrameworkException("Invalid direction");
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

or
    public void swipe(int startx, int starty, int endx, int endy, int duration) {
        TouchAction touchAction = new TouchAction(appiumDriver);
        System.out.println(startx + " " + starty);
        System.out.println("Entering swipe");

        System.out.println("Swipe from " + startx + " " + starty + "to" + endx + " " + endy);
        touchAction.press(startx, starty).waitAction(duration).moveTo(endx, endy).release().perform();
starty + "to" + endx + " " + endy);
    }