In this tutorial, we will demonstrate the automation of mobile applications on Android using the Appium framework.
Examples provided here originate from our samples repository, which is publicly available in the following Github project.
Before going through this tutorial, make sure you understand what stepkeywords and plans are.
In addition, you will need access to a (preferably local) step instance. Please follow the Quick setup guide to go through a quick installation process on your local computer.
Make sure that your host or laptop supports hardware acceleration. In this example, we’re assuming you’re running Microsoft Windows as the OS hosting the Android Virtual devices, but the exact same results can be achieved on Linux.
Android Studio setup
Let’s install Android Studio in order to be able to create some Android Virtual devices.
You can start by downloading the latest version of Android Studio for Windows from this link.
Double-click the installation package and on the “Choose Components” screen, make sure to select only “Android Studio” and click on next : (we will install and configure the Android Virtual devices on our own)
You can leave the options displayed in the nexts screens set to their default values.
Creating an Android Virtual Device
Using Android Studio
Once the installation has completed, open Android Studio and click on the top level menu entry “Tools” then “AVD Manager” :
On the next screen, click on “Create Virtual Device” :
On the hardware selection screen, choose “Phone” from the left Category panel, then “Nexus 5X” as device type then click on Next :
On the system image selection screen, click on the “x86 images” tab then hit the Oreo (version 26, x86_64, without the Google APIs)Download link , wait for the download to complete than hit the Next button :
Set the device name to Nexus_5X_API_26_Demo_1 and click on the Finish button :
You now have completed you first Android Virtual device creation !
Using the Studio CLI
Open a command prompt and navigate to the Sdk tools bin directory :
The prompt will ask you if you wish to create a custom hardware profile, you can type “no” and hit enter.
Check that the device has been properly created :
avdmanager.bat list avd
Device: Nexus 5X (Google)
Target: Google Play (Google Inc.)
Try the sample
Get the Appium client apk
This sample is based on a demo application provided by Appium. To continue, download the application file from the Appium Github and put it in the location of your choice.
Run the JUnit demo
The Appium keywords sample is located in the demo-appium-keyword folder in the step sample repository hosted on Github.
You can continue by cloning this repository and opening the project in your favorite IDE (we will use Eclipse in the remaining steps of the tutorial).
Since we previously created an AVD named “Nexus_5X_API_26_Demo_1”, you can directly open the AppiumKeywordExampleTest class and execute the JUnit tests called testApiDemo :
You can now see the Android Virtual device booting, and once the boot sequence completed, the keywords being executed, as illustrated in the following video:
Scaling out your executions
Let’s now take a look at how step can be leveraged to scale out the keyword executions on multiple devices. We’ll create a 2nd device called “Nexus_5X_API_26_Demo_2” using Android Studio again.
Building and deploying the keywords
First we have to package the keywords as a JAR file using Maven or any other dependency management tool. Using Eclipse, we’ll right-click the project name and then choose “Run as -> Maven build”. The Maven goals to use would be “clean package” :
Once downloaded, import them to your step instance from the “Plans” tab by clicking on button “Import plan” located in the top right corner of the Plans view, next to the “New Plan” button. A window will pop up, allowing you to drag and drop the plan file. Then make sure to click “Save” :
Note: As of step 3.10, after importing a plan in which Keywords are referenced by id, such as in this plan, Keyword calls still need to be bound manually to the local instance of your keywords. So please make sure to go through each Keyword call located inside the “Appium_Demo” plan, then click Select to choose the local version of your Keyword:
Alternatively, the CallKeyword artefact can be used to identify a keyword by name.
You can now execute the plan “Orchestrate_Demo_Multiple_Devices”, which will trigger the execution of the Appium keywords on 2 devices simultaneously, as illustrated in this second video:
One of the interesting things to note about step’s Keyword API and Appium is that they can not only be used for application automation but also to manage the Android devices themselves. This is a very efficient way of achieving scale, especially when combining these tools with technology such as Docker and Kubernetes, which is what we do in our own cloud. Devices can be booted on demand, applications can be deployed and automation scenarios executed.
Here’s a hint of what the architecture looks like if you package your step agent along with the emulators:
While we can not disclose the entire source code and details for managing our private cloud-based farms, we encourage users to try and build their own Android emulator farms and manage them using this strategy which has been very successful for us. You can send any questions on this topic to email@example.com or using our contact page