Swipe in Android using Appium

Let’s see, How can you Swipe in Android using Appium. In previous tutorials, You have seen, How can perform Drop Drag in Android. Now we will see, How can we swipe vertically & horizontally. Swipe is the common action for any android mobile app.

 

As you know, We can swipe horizontally(left to right or right to left) and swipe vertically(bottom to top and top to bottom) In android mobile app.

 

Here, We have described how to swipe horizontally and vertically in the Android mobile app using driver.swipe() when running Appium Automation Test.

 

Horizontal Swipe in Andriod using Appium

Let’s take an Example to see the, How can you perform the Swipe Horizontally.

 

In above test script, swipingHorizontal() method is responsible for horizontal swipe. To swipe in Andriod on your device you have to perform some operation like –

  • Put your finger on the screen in right size.
  • Swipe to left
  • Now release your finger.

 

Here, You can notice, We have three points –

  • starty – It is the point, Where you need to place your finger on the right side of a screen.

  • endy – It is the point, where you will leave your finger in the left side of the screen.

  • startx – It defines the position of the screen vertically, Where you will put your screen(Middle of the screen vertically)

 

Now, Let’s understand the method used in the above Test Script –

  • driver.manage().window().getSize(); will find your device’s screen size(Width X Height).
  • startx Is located at 70% (From right) of your device’s screen width.
  • endx Is located at 30%  (From left) of your device’s screen width.
  • starty Is located at the vertical middle of the screen.
  • First, driver.swipe method will swipe from right side to left side as swipe start point(startx) is located at right side of the screen and end point(endx) is locate at the left side of the screen. Here 3000 Is time in milliseconds to perform swipe operation.
  • Second driver.swipe method will swipe from left side to right side as swipe start point(endx) is located at left side of the screen and end point(startx) is locate at the right side of the screen.
  • Vertical point starty will remain steady as we are performing horizontal swipe.

 

Vertical Swipe in Andriod using Appium

Just like Horizontal swipe, We can also perform the vertical swipe in Andriod using Appium. Let’s take an example of vertical swap as well.

 

Let’s understand the above example. swipingVertical() method is responsible for vertical swipe in above Android Automation Test Script . Just like the previous method we have touch points on the screen and on the basis od these touch points. We will perform the swapping .

 

In Above test script –

  • starty Is located at 80% (From top) of your device’s screen height.
  • endy Is located at 20%  (From top) of your device’s screen height.
  • startx Is located at the horizontal middle of the screen.
  • First, driver.swipe method will swipe from bottom to top as swipe start point(starty) is located at a bottom side of the screen and end point(endy) is locate at the top side of the screen. Here 3000 Is time in milliseconds to perform swipe operation.
  • Second driver.swipe method will swipe from top side to bottom as swipe start point(endy) is located at the top side of the screen and end point(starty) is locate at the bottom side of the screen.
  • Horizontal point startx will remain steady as we are performing horizontal swipe.

 

Now you are aware of the concept of Swapping both ways.

0 Comment

Leave a Reply