Home » appium-tutorial » Appium Zoom with Multi TouchAction in Android

Newly Updated Posts

Appium Zoom with Multi TouchAction in Android

Previous Topic, This tutorial we are going to learn Appium Zoom with MultiTouchAction in Android. Before going further lets understand Zoom in appium.

What is Zoom Action in Mobile Device?

Zoom action is an event to maximize and minimize the window for any image, web page etc so that it is more visible and clear to the user.

or in other words during the in zoom action the coordinates (x,y) from a specific point changes ,is being moved to other point location results in the change in co ordinates, which magnifies the window and makes it more clear to the user.

The zoom action is performed manually with the help of multiple touch(more than two), so that the area to be zoom out or in can be made larger or smaller , the action can be performed by double touch, triple touch or multi touch. Lets understand how to perform in Appium.

How to to perform Appium Zoom with MultiTouchAction in Android?

Appium Zoom with Multi Touch Action in Android device

Appium provides the capability to perform zoom action or multi touch action using MultiTouchAction class. With the help of MultiTouchAction class, we are capable to add different AndroidTouchAction and perform action simultaneously.

For each touch action, we individually perform action ( move the co ordinates from on place to another) creating different object and finally add them using MultiTouchAction using add method.

Lets understand it more in depth by taking a scenario:

Step1) Open the application “MultiTouch Tester” (if you do not have please download it from playstore).

Step 2) Now point two touch gesture and move both the points to other location by changing the coordinates(try to zoom).

Step 3) close the application.

Dimension dim=adriver.manage().window().getSize();     
int width=dim.width;
int height =dim.height;

int firstTouchXcoordinate_Start =(int)(width*.5);
int firstTouchYcoordinate_Start =(int)(height*.4);

int firstTouchXcoordinate_End =(int)(width*.1);
 int firstTouchYcoordinate_End =(int)(height*.1);

 int secondTouchXcoordinate_Start =(int)(width*.5);
 int secondTouchYcoordinate_Start =(int)(height*.6);

 int secondTouchXcoordinate_End =(int)(width*.9);
 int secondTouchYcoordinate_End =(int)(height*.9);

 TouchAction touch1=new TouchAction(adriver);
 TouchAction touch2=new TouchAction(adriver);

 touch1.longPress(PointOption.point(firstTouchXcoordinate_Start, firstTouchYcoordinate_Start))
 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
 .moveTo(PointOption.point(firstTouchXcoordinate_End, firstTouchYcoordinate_End));

 touch2.longPress(PointOption.point(secondTouchXcoordinate_Start, secondTouchYcoordinate_Start))
 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
 .moveTo(PointOption.point(secondTouchXcoordinate_End, secondTouchYcoordinate_End));

 MultiTouchAction multi=new MultiTouchAction(adriver);
 multi.add(touch1).add(touch2).perform();

Code Description of above code:

Step1) Firstly get the size of the window and extract the width and height of the window

Dimension dim=adriver.manage().window().getSize();
int width=dim.width;
int height =dim.height;

Step 2) Get the (x,y) coordinates of source point of the First touch gesture and (x,y) co ordinates of destination point of the coordinates

int firstTouchXcoordinate_Start =(int)(width.5); int firstTouchYcoordinate_Start =(int)(height.4);

int firstTouchXcoordinate_End =(int)(width.1); int firstTouchYcoordinate_End =(int)(height.1);

Step 3) Get the (x,y) coordinates of source point of the Second touch gesture and (x,y) co ordinates of destination point of the coordinates

int secondTouchXcoordinate_Start =(int)(width.5); int secondTouchYcoordinate_Start =(int)(height.6);

int secondTouchXcoordinate_End =(int)(width.9); int secondTouchYcoordinate_End =(int)(height.9);

Step 4) Now create the 2 object of TouchAction class passing the driver as parameter for 2 touch action named as touch1 and touch2.

TouchAction touch1=new TouchAction(adriver);
TouchAction touch2=new TouchAction(adriver);

Step 5) Now in first Touch gesture longPress the drag element from starting element taking (x,y) co ordinate and wait for 2 seconds or 2000 milliseconds and then move to the destination element by (x,y) co ordinate.

touch1.longPress(PointOption.point(firstTouchXcoordinate_Start, firstTouchYcoordinate_Start))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
.moveTo(PointOption.point(firstTouchXcoordinate_End, firstTouchYcoordinate_End));

Step 6) Now in Second Touch gesture longPress the drag element from starting element taking (x,y) co ordinate and wait for 2 seconds or 2000 milliseconds and then move to the destination element by (x,y) co ordinate.

touch2.longPress(PointOption.point(secondTouchXcoordinate_Start, secondTouchYcoordinate_Start))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
.moveTo(PointOption.point(secondTouchXcoordinate_End, secondTouchYcoordinate_End));

Step 7) Now create the object of MultiTouchAction and through refence variable add the two touch action and perform.

MultiTouchAction multi=new MultiTouchAction(adriver);
multi.add(touch1).add(touch2).perform();

Conclusion: So we can not perform Appium zoom action with multi gesture using MultiTouchAction and add mulitple touch to it.