Appium Swipe( Pattern Functionality)

I want to make a 'Z’in password pattern format . I have used the below apporach.but its taking three strokes or we can say three swipes in order to make. But i want to swipe whole path in a single stroke

 driver.swipe(532,270,770,249,2000);
 driver.swipe(770,249,535,493,2000);
 driver.swipe(535,493,775,492,2000);
 Thread.sleep(2000);

Have a look at TouchActions

Hi Tanuj,

you have to use MultiTouchAction class for that.

MultiTouchAction mta = new MultiTouchAction(driver);
TouchAction ta0 = new TouchAction(driver).longPress(200, 800, 1000).moveTo(200, 100).waitAction(100);
TouchAction ta1 = new TouchAction(driver).longPress(500, 800, 1000).moveTo(500, 1600).waitAction(100);
TouchAction ta2 = new TouchAction(driver).longPress(900, 800, 1000).moveTo(100, 800).waitAction(100);
mta.add(ta0).add(ta1).add(ta2).perform();

Hi narendarsingam,

Have used this…but still its clicking on first point and script gets stopped

MultiTouchAction mta = new MultiTouchAction(driver);
TouchAction ta0 = new TouchAction(driver).press(532,270).moveTo(770,249).waitAction(100);
TouchAction ta1 = new TouchAction(driver).press(770,249).moveTo(535,493).waitAction(100);
TouchAction ta2 = new TouchAction(driver).press(535,493).moveTo(775,492).waitAction(100);
mta.add(ta0).add(ta1).add(ta2).perform();

have tried longpress tooo

I would try it without MultiTouchAction just in a single TouchAction like e.g.

driver.performTouchAction(new IOSTouchAction(driver)
.press(x,y).moveTo(x,y).moveTo(x,y).moveTo(x,y).release());

public class SwipeDevice {

AndroidDriver driver;

@BeforeTest
public void SetUp() throws MalformedURLException{
	DesiredCapabilities capabilities = new DesiredCapabilities();

	  capabilities.setCapability("deviceName", "CELZSSMJUOJBPV99");
	  capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
	  capabilities.setCapability(CapabilityType.VERSION, "4.4.2");
	  capabilities.setCapability("platformName", "Android");

	  capabilities.setCapability("appPackage", "com.android.settings");

	  
	  capabilities.setCapability("appActivity", "com.android.settings.Settings");

	 
	try
	{
		  driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
			
}

@Test(priority=0)
	 
 public void testCal()  throws Exception 
     {
             String str="Security";
           // driver.scrollTo(str);
            
             driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+str+"\").instance(0))").click();

      }
@Test(priority=1)
 public void Sum() throws InterruptedException  {
	 
	// android.widget.TextView
	
	 driver.findElement(By.xpath("//android.widget.TextView[contains(@resource-id,'android:id/title') and @text='Screen lock']")).click();
	 Thread.sleep(2000);
	 
	 driver.findElement(By.xpath("//android.widget.TextView[contains(@resource-id,'android:id/title') and @text='Pattern']")).click();
	 Thread.sleep(2000);
}

@Test(priority=2)
 public void Sum1() throws InterruptedException  {
	 
	// android.widget.TextView

// MultiTouchAction mta1 = new MultiTouchAction(driver);
//
// TouchAction d1= swipe(532,270,770,249,2000);
// TouchAction d2= swipe(770,249,535,493,2000);
// TouchAction d3= swipe(535,493,775,492,2000);
// mta1.add(d1).add(d2).add(d3).perform();

	 driver.swipe(532,270,770,249,2000);
	 driver.swipe(770,249,535,493,2000);
	 driver.swipe(535,493,775,492,2000);
	 Thread.sleep(2000);

// new TouchAction(driver).press(532,270).moveTo(770,249).release().perform();

// new TouchAction(driver).press(532,270).moveTo(770,249).moveTo(535,493).moveTo(775,492).release().perform();
// Thread.sleep(4000);

// new TouchAction(driver).press(532,270).waitAction(2000).moveTo(770,249).waitAction(2000).moveTo(535,493).moveTo(775,492).release().perform();
// Thread.sleep(2000);

//

	 MultiTouchAction mta = new MultiTouchAction(driver);
	 TouchAction ta0 = new TouchAction(driver).longPress(532,270).moveTo(770,249).waitAction(1000);
	 TouchAction ta1 = new TouchAction(driver).longPress(770,249).moveTo(535,493).waitAction(1000);
	 TouchAction ta2 = new TouchAction(driver).longPress(535,493).moveTo(775,492).waitAction(1000);
	 mta.add(ta0).add(ta1).add(ta2).perform();	
	
}


@AfterTest
 public void End() throws InterruptedException
 {
	
  driver.quit();
 }
}

Not Able to make “Z” in single stroke…
if anyone has code plz provide me with same

try:

TouchAction(driver).press(532,270).waitAction(200).moveTo(250,0).waitAction(200).moveTo(-250,200).waitAction(200).moveTo(250,0).release().perform();

i tried diz also …in diz it selects the first point and dosent go to the next point …
if you have done diz plz share the code with me…

with RELATIVE coordinates you tried?

As u can see i have used all posssible combinations in Script…

And What do you mean by relative coordinates…

Relative:
1 point is x = 500, y = 250
2 point x = 750, y = 250

you tried:
press(500,250).moveTo(750,250)

i suggest to try relative:
press(500,250).moveTo(250,0)

i will try …if u have code for this can u provide me with the same…

when you tried - do you see that something happens on screen? Enable in development menu to show what happens on screen!

enable:

  • Show touches
  • Show touch data