I cannot make gestures for me in Appium using Java

I cannot do work with Swipe. I browsed the web for several days and found many similar questions, but no working answer. I also tried the TouchAction class, it doesn't work.

I have Appium Version 1.4.13 (Draco) and using Java, Framework TestNG.

btw I did a scroll using (you can use the same logic as attraction to update), here is a sample code.

public void scrollUp() {
    JavascriptExecutor js = (JavascriptExecutor) getDriver();
    HashMap<String, String> scrollObject = new HashMap<String,String();
    scrollObject.put("direction", "up");
    scrollObject.put("element", listElements.get(1).getText());
    js.executeScript("mobile: scroll", scrollObject);
}
+4
source share
5 answers

// Method names explain themselves. I hope this works.

            public static void swipeFromRightToLeftMultipleTimes(int howManySwipes) {
                    JavascriptExecutor js = (JavascriptExecutor) iosDriver;
                    for(int counter=0; counter < howManySwipes; counter++){
                        HashMap<String, Integer> swipeObject = new HashMap<String, Integer>();
                        swipeObject.put("startX", getScreenWidth());
                        swipeObject.put("startY", getScreenHeight());
                        swipeObject.put("endX", getScreenWidth()/4);
                        swipeObject.put("endY", getScreenHeight());
                        swipeObject.put("duration", 2);
                        js.executeScript("mobile: swipe", swipeObject);
                    }
            }

            public static void swipeFromLeftToRightMultipleTimes(int howManySwipes) {
                    JavascriptExecutor js = (JavascriptExecutor) iosDriver;
                    for(int counter=0; counter < howManySwipes; counter++){
                        HashMap<String, Integer> swipeObject = new HashMap<String, Integer>();
                        swipeObject.put("startX", getScreenWidth()/4);
                        swipeObject.put("startY", getScreenHeight());
                        swipeObject.put("endX", getScreenWidth());
                        swipeObject.put("endY", getScreenHeight());
                        swipeObject.put("duration", 2);
                        js.executeScript("mobile: swipe", swipeObject);
                    }
            }
0
source

iOS Android? , . iOS Xcode 7.0.1 iOS 8.x/9.0. , , .

, Android- Android, Android Simulator.

swipeElement MobileElement. this.swipeElement(driver, MobileElement, 200, 3000); scroll length positive, , negative .

public void swipeElement(AndroidDriver driver, WebElement element, int scrollLength, int duration){ 

driver.context("NATIVE_APP");
int bottomY = element.getLocation().getY()+scrollLength;

((AppiumDriver)driver).swipe(element.getLocation().getX(), element.getLocation().getY(), element.getLocation().getX(), bottomY, duration); 

}
0

iOS- Appium 1.4.13; Java-Client 3.2.0; Xcode 7.0.1; iOS 8.x/9.0;

'elementName', .

JavascriptExecutor js = (JavascriptExecutor) iosDriv;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("element", ((RemoteWebElement) iosDriv.findElement(By.name("elementName"))).getId());
js.executeScript("mobile: scroll", scrollObject);
Hide result

0
driver.context("NATIVE_APP"); 
        Dimension size = driver.manage().window().getSize(); 
        int startx = (int) (size.width * 0.8); 
        int endx = (int) (size.width * 0.20); 
        int starty = size.height / 2; 
        driver.swipe(startx, starty, endx, starty, 1000);

. startx starty, .

0
source

driver.swipe (startingXCoordinate, StartingYCoordinate, EndXCoordinate, EndYCoordinate, timeForSwipe);

Ex: driver.swipe(100,200,450,200,2000);

here you will draw from the 100th coordinate of X to the 450th coordinate of X. That is why the Y coordinates are the same for the start and end points (200 and 200). The last parameter 2 indicates that the swipe action will take 2 seconds. In fact, we have to mention 2000 milliseconds in 2 seconds.

-1
source

Source: https://habr.com/ru/post/1605864/


All Articles