Hi all, in this article, I will explain how to do some appium mobile actions such as swipe, tap, press, multi-touch based on Appium 6.0.0 version which is released 24 May 2018. I wrote a MobileActions class which comprises of these actions. You can instantiate it into your BaseScreen or BasePage class and use it in your Screen/Page classes. I will start with the MobileActions class. By using these class, you can do the below actions:

  • Tab by using an element
  • Tab by using x,y coordinates
  • Press by using an element and duration (in seconds)
  • Press by using x,y coordinates, and duration (in seconds)
  • Horizontal swipe by using start and end percentage of the screen and an anchor for the height.
  • Vertical swipe by using start and end percentage of the screen and an anchor for the width.
  • Swipe one element to an another element
  • Multitouch by using an element

MobileActions Class – Here is the code of all actions:

You can use this class by instantiating it in BasePage or BaseScreen class as shown below:

And from now on you can use mobileActions object in your screen classes too. You can see its usage in below code snippet.

As you see the above screen class, we can use mobileAction object to perform swipe and tab actions.

  • verticalSwiteByPercentages gets start point percentage with respect to the screen, endpoint percentage with respect to the screen, and anchor percentage with respect to the screen.
  • swipeByElements gets first and second elements to perform swipe operation.
  • tabByElement gets an element to tap on it.

You can use all appium mobile actions which are declared in MobileActions class in this way. Also, you can add new appium mobile actions to enhance this class. This code is modified for an Android project but you can change the driver type as AppiumDriver or as IOSDriver to use it in your project needs.

I hope you enjoy reading appium mobile actions article and it helped you in your mobile automation projects.

You can also look at our Appium articles by clicking this link.

Thank you.
Onur Baskirt