Work Flow of Appium
Appium test script written in IDE will interact with the Appium Server which is nothing but the node server with the specified IP address and port number. Node server again passes the request to mobile devices or emulator using the uiautomator as a JSON format. All the UI elements associated with the mobile application can be controlled by using the appium client which is nothing but the derived one of selenium.
The following information is going to explain about the Android application automation using Appium + Junit + Core Java. In the forthcoming posting, I will be sharing the information about the integration of Apache Maven and the continuous integration tool of Jenkins.
How to setup Appium in Windows x86 or x64 PC?
The following pre-requisites make it available at your end before start setting up Appium;
- Latest JDK (Should be installed not copy & paste)
- Android SDK with API 16 and above (Jellybean 4.1 and above)
- .NET Framework 4.5
- Appium.exe for windows
- Latest Eclipse IDE (I’ve tried with both Juno and Mars)
- APK file (Android mobile app)
Once the above pre-requisite is ready, start writing the test scripts in the newly created class file under java project by mapping the external dependencies of JAR files (Selenium & Appium client)
Now, we can see the above pre-requisite information in an elaborate way;
After installing the JDK and completed the environment variable setup of both the ‘JAVA_HOME’ and ‘Path’ based on the below screenshot;
Ensure the Java installation in the command prompt based on the below screenshot;
After downloading the Android SDK from https://developer.android.com/sdk and installing the Android SDK in your windows PC;
You have to setup the Android Environment variable in the ‘ANDROID_HOME’ and ‘Path’ as like JDK;
You have to add the android sdk installed location path based on the below screeshot;
You have to add both the platform-tools and tools location in the path variable;
Ensure the SDK manager is ready at your end based on the below screenshot; (click the SDK manager.exe available in the Android SDK location)
Download the .NET framework from https://www.microsoft.com/en-in/download/details.aspx?id=30653 and install it in your PC and ensure the installation in your installed programs in control panel based on the below screenshot;
Download the Appium Installer from https://bitbucket.org/appium/appium.app/downloads/ and I’ve downloaded ‘AppiumForWindows_1_3_7_2.zip’ from the above link. Unzip the installer file and click the ‘appium-installer.exe’ to install Appium in your windows PC;
Ensure Appium is successfully installed in your PC based on the below screenshot;
Download the Eclipse IDE from http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/marsr and run the ‘eclipse.exe’ available in your windows PC;
I am going to take Yammer Android Mobile Application for this test run. You can download the Yammer apk from http://apk-dl.com/ by giving the google play URL https://play.google.com/store/apps/details?id=com.yammer.v1&hl=en
Install the apk file to emulator using the below command and please note I’ve used Android API 19 (Kitkat 4.4.2) for installing the above apk. (You have to create an emulator using AVD manager.exe in the Android SDK installed location or you can connect the real device in your windows PC)
Even directly you can give the apk location path in Appium server IDE to install the apk by skipping the above section.
All the pre-requisites are ready at our end and now coming to the script preparation for automating an android mobile application;
- Create a java project in Eclipse IDE as AppiumDemo
2. Create a new package as Appiumdemo(your own name) and class as appiumTest(your own name) based on the below screenshot;
3. Now add the script in the appiumTest.java file in Eclipse IDE;
Before entering in to the script preparation, I would like to highlight the importance of ui automator available under the tools folder of android sdk;
It will help us to trace the mobile elements, which is used for triggering the user actions like click, swipe, scroll, enter text etc.
Just go to the tools folder under the installed android sdk location and click the ‘uiautomatorviewer.bat’ file and open the mobile app in the emulator, click the screenshot button in the ui automator IDE based on the below screenshot;
Now you could visualize the mobile element information for your automation need;
Go to Eclipse IDE –> Project –> Properties –> Select ‘Java Build Path’ in left pane and select the ‘Libraries’ tab and select the ‘Add External Jars…’ to map all the dependencies jar as mentioned below;
Selenium supporting jars from http://www.seleniumhq.org/download/ (Java)
Appium client libraries jars from http://appium.io/downloads.html (Java)
Add the selenium-java-2.45.0.jar and all jar files available in the libs folder.
Junit and hamcrest jars from https://github.com/junit-team/junit/wiki/Download-and-Install
Add the below script and run the test script in the Eclipse IDE;
public class appiumTest
private WebDriver driver = null;
public void setUp() throws Exception
DesiredCapabilities capabilities = new DesiredCapabilities();
driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub “),capabilities);
public void Login() throws Exception
List<WebElement> textFieldsList = driver.findElements(By.className(“android.widget.EditText”));
textFieldsList.get(0).sendKeys(“firstname.lastname@example.org”); //Give your account username
textFieldsList.get(1).sendKeys(“asdfghjkl”); //Give your account password
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //Taking screenshot
FileUtils.copyFile(scrFile, new File(“c:\\Temp\\screenshotGK.png”));
public void tearDown()
Make the Appium Server UP with the default configuration; Ensure the server address and port number as mentioned in the test script such as 127.0.0.1 with 4723.
Make the Emulator UP with the Installed APK file;
Go to Eclipse and right click the mouse button in script window by selecting the ‘Run as’ option and again select the JUnit Test’ as mentioned in the below screenshot;
That’s it!!! You script will be executed in the mobile application installed in the emulator. Next posting will be explaining about the integration of Appium with TestNG instead of JUnit.
5 thoughts on “How to Automate Android Mobile Application using Appium?”
Very good information… Its very easy to understand about Appium tool..Thanks for sharing….
Looks very good and so much useful….we all need to implement this and start from there to reach our destination….
I think, loading a test web page url statement is missing.
correct me if I am wrong.
testurl is applicable for browser related mobile web application automation.
It’s for mobile application right? so we have to specify the application package name and activity(screen) name as follows;
FileUtils.copyFile(scrFile, new File(“c:\\Temp\\Screen.png”));
not working [syntax error].