Touch actions in Appium | Explain Touch Actions in APPIUM?

 



appium,appium tutorial,appium tutorial for beginners,appium automation testing,long press in appium,tap in appium,appium mobile automation,how to do tap in appium,appium mobile testing,appium mobile automation testing tutorial,appium touch action example in python,how to perform tap using coordinates in appium,appium touch action,android appium touch actions,#appium,appium scroll,how to automate seekbar in appium,touch actions,appium gestures



What is Touch Actions in Appium ?

  • Touch actions in Appium are used to simulate touch-based interactions with a mobile app. 
  • Touch actions are used to tap, swipe, scroll, and perform other types of gestures that can be performed on a mobile device. 
  • These actions are performed by creating instances of the TouchAction class and calling its methods.


1. Tapping: Tapping is used to simulate a single tap on an element. 


For example, to tap on a button, you would do the following:


WebElement element = driver.findElement(By.id("element_id"));
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(element).perform();


In this example, the TouchAction instance is created by passing the driver to its constructor. The tap method is then called on the TouchAction instance, passing in the WebElement that should be tapped. Finally, the perform method is called on the TouchAction instance to actually perform the touch action.




2. Long Press: Long press is used to simulate a press-and-hold gesture on an element. 


For example, to long press on an element, you would do the following:


WebElement element = driver.findElement(By.id("element"));
new TouchAction(driver).longPress(element).perform();


In this example, we use the findElement method to locate the element, and then we use the TouchAction class to perform a long press on it. The perform method is called to execute the touch action.



3. Swiping: Swiping is used to simulate a swipe gesture on the screen. 


For example, to swipe up on the screen, you would do the following:


WebElement element = driver.findElement(By.id("element_id"));
TouchAction touchAction = new TouchAction(driver);
touchAction.press(element).waitAction(Duration.ofMillis(1000)).moveTo(0,-100).release().perform();



In this example, the touch action performs a swipe gesture by calling the press method, then the waitAction method with a duration of 1000 milliseconds, followed by the moveTo method to move the swipe by 100 pixels in the negative y direction, and finally the release method.



4. Pinch-to-Zoom: Pinch-to-zoom is used to simulate the pinch-to-zoom gesture on an element. 


For example, to pinch-to-zoom in on an element, you would do the following:



WebElement element = driver.findElement(By.id("element_id"));
TouchAction zoomIn = new TouchAction(driver);
zoomIn.press(element).moveTo(0, 100).release().perform();
TouchAction zoomOut = new TouchAction(driver);
zoomOut.press(element).moveTo(0, -100).release().perform();



It's also possible to combine multiple touch actions into a single gesture. For example, you can use the perform method to execute multiple touch actions in sequence:


WebElement element1 = driver.findElement(By.id("element_id1"));
WebElement element2 = driver.findElement(By.id("element_id2"));
 
TouchAction touchAction1 = new TouchAction(driver);
TouchAction touchAction2 = new TouchAction(driver);
 
touchAction1.press(element1).moveTo(element2).release().perform();
touchAction2.tap(element2).perform();


In this example, the first touch action performs a swipe gesture by pressing on element1, moving to element2, and releasing. The second touch action performs a tap gesture on element2. By using the perform method, both touch actions are executed in sequence, creating a complex gesture that interacts with multiple elements in the mobile app.



Conclusion:

In conclusion, touch actions in Appium provide a flexible and powerful way to simulate touch-based interactions with a mobile app. By combining touch actions and executing them in sequence, you can test a wide range of complex interactions in your mobile app.



Post a Comment

Post a Comment (0)

Previous Post Next Post