本文介绍了Andriod for Java-Client-5.0.3 中的滑动功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android 移动自动化测试中使用以下代码进行页面滑动,不支持滑动功能.它给出了错误:

I was using below code for page swiping in Android Mobile Automation Testing, the swipe function is not supported. It gives the error:

swipe(int, int, int, int, int) 方法未定义类型Appium驱动程序

下面是代码

public static void Swipe(String Direction) throws Exception,IOException{
    if(Direction.equalsIgnoreCase("Right to Left")){
        AgenceGS_Framwork.driver.context("NATIVE_APP");
        Dimension size = AgenceGS_Framwork.driver.manage().window().getSize();
        int startx = (int) (size.height * 0.8);
        int endx = (int) (size.height * 0.20);
        int starty = size.width / 2;
        //Mobile_Framwork.driver.swipe(startx, starty, endx, starty, 1000);
        AgenceGS_Framwork.driver.swipe(endx, starty, startx, starty, 2000);
        AgenceGS_Framwork.switchWebview("android.webkit.WebView");
    }
    if(Direction.equalsIgnoreCase("Left to Right")){
        AgenceGS_Framwork.driver.context("NATIVE_APP");
        Dimension size = AgenceGS_Framwork.driver.manage().window().getSize();
        int endx = (int) (size.width * 0.8);
        System.out.println("start width");
        int startx = (int) (size.width * 0.20);
        System.out.println("start width");
        int starty = size.height / 2;
        AgenceGS_Framwork.driver.swipe(startx, starty, endx, starty, 1000);
        AgenceGS_Framwork.switchWebview("android.webkit.WebView");
    }
    if(Direction.equalsIgnoreCase("Coordinate Scroll")){
        AgenceGS_Framwork.driver.context("NATIVE_APP");
        TouchAction touch=new TouchAction(AgenceGS_Framwork.driver);
        touch.longPress(664,600).moveTo(664, 100).release().perform();
        AgenceGS_Framwork.switchWebview("android.webkit.WebView");
    }
}

推荐答案

检查一下,它会帮助您进行页面滑动(对于 Java 客户端 5.0.3),它对我来说非常有效.

Check it out, it will help you for page swiping (for Java client 5.0.3), it's working perfectly for me.

public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
        Dimension size = driver.manage().window().getSize();
        int anchor = (int) (size.height * anchorPercentage);
        int startPoint = (int) (size.width * startPercentage);
        int endPoint = (int) (size.width * finalPercentage);
        new TouchAction(driver).press(startPoint, anchor).waitAction(Duration.ofMillis(duration)).moveTo(endPoint, anchor).release().perform();
    }


    public static void swipeVertical(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
        Dimension size = driver.manage().window().getSize();
        int anchor = (int) (size.width * anchorPercentage);
        int startPoint = (int) (size.height * startPercentage);
        int endPoint = (int) (size.height * finalPercentage);
        new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofMillis(duration)).moveTo(anchor, endPoint).release().perform();
    }

打电话给他们:

向上滚动:swipeVertical((AppiumDriver)driver,0.9,0.1,0.5,3000);

向下滚动:swipeVertical((AppiumDriver)driver,0.1,0.9,0.5,3000);

从右到左:swipeHorizo​​ntal((AppiumDriver) driver,0.9,0.01,0.5,3000);

从左到右:swipeHorizo​​ntal((AppiumDriver) driver,0.01,0.9,0.5,3000);

这篇关于Andriod for Java-Client-5.0.3 中的滑动功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 01:26