This article will describe how to setup the Appium framework for Android device app automation testing. Appium is an open source tool which is used to automate testing for native, hybrid and mobile web. Appium is designed to automate mobile app testing from any language.
How does it work for Android?
When we execute the test scripts, Appium sends the command to UIAutomator or Selendroid on the basis of the Android version. Here, bootstrap.jar plays the role of a TCP server, which we can use to send the test command in order to perform the action on the Android device using UIAutomator/Selendroid.
Prerequisite for Appium Setup:
1. Installation of ANDROID SDK (Studio)
2. Installation of JDK (Java Development Kit)
3. Installation of Eclipse
4. Installation of TestNG for Eclipse
5. Installation of Selenium Server JAR
6. Appium Client Library
7. js (Not Required – Whenever Appium server is installed, it by default comes with “Node.exe” & NPM. It’s included in Current version of Appium)
8. Installation of Appium Desktop
Sample Test Case for Appium for Native Android App (Amazon):
1) Launch Appium Node server
2) Create your first test script
3) Execute your first test
Launch Appium Node Server:
1) Appium window should be opened on your machine.
If you have restarted your system then please start Appium by navigates to Appium directory in your system and start Appium by double-clicking Appium.exe file.
1) Android Icon is for Configuration settings.
2) Settings Icon is for General Settings.
3) Play Icon is for Starting Node server.
1) Click on Android icon to open the configuration of the Appium run. There you need to select the check box of ‘No Reset‘. This will ensure that the Appium will not install or uninstall App on every run.
2) Click on General Setting icon and make sure that Server Address and Port is populated.
3) Now it’s time to start the Appium server, just click on the Launch Appium Node Server button on the top right corner of Appium window and wait for few seconds. Appium server started and running on your system.
Sample Test Script Creation:
Now you are all set to write your first test script. Create a small test Program for opening an Amazon application on your
device using Appium.
To start the test just select Run > Run As > Java Application Or Right Click on Eclipse code and Click Run As > Java Application. After a few Seconds, Amazon application will be launched on your device. Once the execution is finished, you will see a long list of messages on the Appium console.
Import libraries statements:
// Library for Appium drivers
// Library to create the path to APK
// Library used to verify if URL is malformed
// Library used to create URL for the Appium server
// Libraries for configuring Desired Capabilities
Path to APK file:
Since the Amazon app apk is stored in the computer and is not already installed on the device what we need to create a file object, which represents the actual apk file on the disk. I placed the folder ‘/Apps/Amazon/‘ which contains the apk file inside the Eclipse project.
// Path to Eclipse project
File classpathRoot = new File(System.getProperty(“user.dir”));
// Path to /Apps -> Amazon
File appDir = new File(classpathRoot, “/Apps/Amazon/”);
// Path to /Apps -> Amazon/Amazon apk file
File app = new File(appDir, “in.amazon.mShop.android.shopping.apk”);
To be able to test the app on an actual device Desired Capabilities need to be set. Desired Capabilities are a set of keys and values sent to the Appium server to tell the server what kind of automation session we’re interested in starting up. There are also capabilities used to modify the behavior of the server during automation.
// To create an object of Desired Capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
// Name of the mobile web browser to automate. It should be an empty string, as we are automation an app
// Name of the OS: Android, iOS or FirefoxOS
// Mobile OS version – My device is running Android 4.4.2
// Device name: – I am using Micromax A311
capabilities.setCapability(“device name”, “Micromax A311”);
// An absolute local path to the APK file
// Java package of the tested Android app
// An activity name for the Android activity you want to run from your package.
// Constructor to initialize driver object with new Url and Capabilities
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
Limitations using Appium:
1. Appium does not support testing of Android Version lower than 4.2
2. Limited support for hybrid app testing. e.g.: not possible to test the switching action of application from the web app to native and vice-versa.
3. No support to run Appium Inspector on Microsoft Windows.