Функция прокрутки в Andriod для Java-Client-5.0.3 не работает

Я использовал приведенный ниже код для пролистывания страниц в Android Mobile Automation Testing, функция пролистывания не поддерживается. Это дает ошибку:

Метод swipe(int, int, int, int, int) не определен для типа AppiumDriver.

Ниже приведен код

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

person Varun.S    schedule 12.03.2018    source источник


Ответы (1)


Проверьте это, это поможет вам перелистывать страницы (для Java-клиента 5.0.3), у меня это работает отлично.

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

Справа налево: swipeHorizontal((AppiumDriver) driver,0.9,0.01,0.5,3000);

Слева направо: swipeHorizontal((AppiumDriver) driver,0.01,0.9,0.5,3000);

person Al Imran    schedule 12.03.2018
comment
Спасибо за вашу помощь, это действительно помогло мне :) - person Varun.S; 13.03.2018
comment
Принят твой ответ - person Varun.S; 13.03.2018