Search code examples
androidtestingautomationselenium-webdriverappium

Swipe method not working in android automation testing


I am trying to implement swipe method.May I know what is the correct way to achieve my objective?

public void swipeWithCordinateLocation(WebDriver driver,double startX,
                                       double  startY,double endX,double endY,
                                       double Duration)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new HashMap<String, Double>();
swipeObject.put("x", startX);
swipeObject.put("y", startY);
swipeObject.put("x", endX);
swipeObject.put("y",endY );
swipeObject.put("duration", Duration);
// HashMap[] param = {swipeObject};
js.executeScript("mobile: swipe", swipeObject);

}

common.swipeWithCordinateLocation(driver, 100.00, 500.00, 500.00, 500.00, 1.00);

But appium is perform swipe but it takes different credentials

[x=360][y=592]
 to [x=360][y=592]

. what to do? Can any one help me please.


Solution

  • The best way to analyze a swipe in automation is to enable "Show touches" and "pointer location" options in your developer option.

    The correct code for the swipe parameters is this -

    swipeObject.put("startX", 198.00);
    swipeObject.put("startY", 685.00);
    swipeObject.put("endX", 198.00);
    swipeObject.put("endY", 550.00);
    swipeObject.put("duration", 1.0);
    

    Hope this helps.

    Or even a better way is to use something like using fractions -

    swipeObject.put("startX", 0.50);
    swipeObject.put("startY", 0.50);
    swipeObject.put("endX", 0.50);
    swipeObject.put("endY", 0.35);
    swipeObject.put("duration", 1.0);