Automate swipe using appium – use of TouchAction

Swipe on mobile handsets can be of fromSwipeScreen_Appium

  • Left to right or vice versa
  • Top to bottom or vice versa

Let’s see how we can automate swipe in appium.

Depending on appium version you are using, implementation defers

Update : Java-Client version > 5.0.0, Swipe() deprecated, alternate solution is to use class TouchAction

Use of TouchAction

For Appium java-client version less than 5.0.0

Use of Swipe()

Start location (x and y axis location) to end location (x and y axis location) and the duration of swipe action.

E.g – If want to move from left to right, change the startx and starty values, but keep constant for startY and endY values.

let’s see one of the code implementation –

We will be using Contacts application, where we will be swiping from right to left to move Favorites to All Contacts.

NOTE: Always better to get the width and height of the panel on which we want to swipe rather than hard coding the x and y axis values, as it gets changes from one device to another.

Explanation of the above code – refer below screenshot




Starting position – we have taken somewhere half of the way of the panel on which we need to swipe.

swipeInAppium

Reference – Appium API documentation

Shortlink – bit.ly/qav-apmswipe

Content posted is based on learning or working experience, Share the post with others if find useful, Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

5 Responses

  1. pratheep says:

    not working

  2. sunilpatro1985 says:

    what error u r getting, can I see ur code block and application u r working?

  3. Raghavendra says:

    Hi Sunil,

    I have a watermark in my application and i want to scroll till that watermark, but when i run the code it says unable to find the element can you please hlep me in this regard

    Thanks
    Raghvendra

  4. sunilpatro1985 says:

    Hi Raghvendra,

    Follow bit.ly/qav-apmScroll and retry, or share your app details so I can take a look.

  5. Raghavendra says:

    Hi,

    This code scrolls till the specified time in swipe method, please let me know how to swipe to specific element in the screen (Ex: if there is a element called password in the screen, i want to swipe till password)

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: