In this post, we will learn how to run a simple calculator app script in Eclipse, using Android SDK on a virtual device, and Appium. Over the past few years, more and more firms are using Appium for the development of their applications. Appium is an open-source test automation framework for use with native, hybrid, and mobile web apps. It drives iOS and Android apps using the WebDriver protocol.
There are tons of resources out there on how to get started and I wanted to share my approach being that it is straightforward and I have it fresh in my mind. It took some trial and error, but I believe with these steps, you will be able to use them as a template for setting up any kind of TC with Appium.
Feel free to leave questions or comments below!
Let’s Get Started to Appium Using Android Virtual Device
For my approach, I have laid out the different versions of software I used. These versions you do not need specifically, but Appium, Eclipse, and Android may require more advanced releases than what you are currently running. These worked fine for me!
Prerequisites
- Appium for Windows and node.js
- Android SDK (I am using the standalone)
- JDK 1.8.0_51
- Eclipse SDK 4.2.1
- TestNG, and Binary download of TestNG Jar
- Appium Client Library 3.1.0
- Selenium Service Jar 2.45.0
These versions not a bit outdated. Please use the latest versions of these tools.
Setup
- Begin with downloading Appium, unzip the package, and follow the step to install.
- Install Android SDK in your system.
Go to Control panel ->> System and Security ->> System and from the left panel click on ‘Advanced System Settings‘. From the ‘System Properties‘ pop up, click on the ‘Advanced‘ tab and then click on the “Environment Variables” button.
From ‘Environment variables‘ pop up, double click on ‘Path‘ and set ANDROID_HOME variable that points to your SDK directory. In the path append the whole SDK folder path. Make sure it is separated by a semi-colon e.g.- ; C:\User\ABC\Desktop\adt-bundled-windows-x86_64-20140321\sdk
Eclipse
- Install Eclipse, create a new workspace
- Android ADT and TestNG
- For TestNG, In the Help drop-down select Install new Software->> Add->> and copy this link to the location: http://beust.com/eclipse
- After Eclipse restarts, we will be doing the same for the ADT with https://dl-ssl.google.com/android/eclipse/
The eclipse will restart again and you will begin making the connection points.
- You will see the SDK manager set up the first time you install Android.
- If not, go to Windows->> Preferences, under Android set the path to the SDK on your computer and press OK.
- I already have the platforms above installed so you will not see them until you do so. To set up, go to windows->>SDK Manager, or click the icon on the taskbar. These packages take a while to install, so for our intents and purposes, we will only be installing API level 17.
- I received an error when attempting to start my emulator, so in extras, I also had to install Intel x86 Emulator Accelerator (HAXM installer) as well.
I also had to go into where my SDK folder is ->>extras ->>intel ->> Hardware Accelerated Execution Manager->> and run the intelhaxm-android application.
Setting Up the Test Case
- File->> add a new Java project, name it and->> next. This is where we are going to be setting up our jar files. (You can get here by right-clicking a project->> build path->> customize path as well)
- Under Libraries tab->> Add External Jars->> the Test NG jar from where you stored it, and the Appium java client library.
- Add the Selenium Jar file 2.45.0
- Also, in the Selenium folder, go into the libs folder and import all Jars in this folder. This may not be necessary depending on what you want your program to do; I just like having them all at my disposal.
- Now you are ready to start scripting!!!
Test Code for the Calculator Application
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; /** * Created by ONUR on 03.04.2016. */ public class FirstAppiumAndroidTest { WebDriver driver; @BeforeClass public void setUp() throws MalformedURLException{ //Set up desired capabilities and pass the Android app-activity //and app-package to Appium DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("BROWSER_NAME", "Android"); capabilities.setCapability("VERSION", "4.4.2"); capabilities.setCapability("deviceName","EmulatorS4"); capabilities.setCapability("platformName","Android"); // This package name of your app (you can get it from apk info app) capabilities.setCapability("appPackage", "com.android.calculator2"); // This is Launcher activity of your app (you can get it from apk info app) capabilities.setCapability("appActivity","com.android.calculator2.Calculator"); //Create RemoteWebDriver instance and connect to the Appium server //It will launch the Calculator App in Android Device using the configurations //specified in Desired Capabilities driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } @Test public void testCal() throws Exception { //locate the Text on the calculator by using By.name() WebElement two=driver.findElement(By.name("2")); two.click(); WebElement plus=driver.findElement(By.name("+")); plus.click(); WebElement four=driver.findElement(By.name("4")); four.click(); WebElement equalTo=driver.findElement(By.name("=")); equalTo.click(); //locate the edit box of the calculator by using By.tagName() WebElement results=driver.findElement(By.className("android.widget.EditText")); //Check the calculated value on the edit box assert results.getText().toString().equals("6"):"Actual value is : " +results.getText()+" did not match with expected value: 6"; } @AfterClass public void teardown(){ //close the app driver.quit(); } }
Almost there! Now we need to set up our Emulator in AVD Manager. In the Manager dialog select create. This will bring up a form that you will use to set up the device. I called my device Emulator, but you can go with a different conventional name, just be sure it matches in your code and in Appium. If you set yours up like this you should have no problem with your device:
- Click OK, and start your device
- Now we can run Appium! In Android settings, set it up to match your device and give the path to your SDK.
- Make sure only necessary boxes are selected.
- Your server should be set up to default as below, so all that’s left to do is run the server, note this is the server from my code.
- If the server is started correctly your prompt should look similar to this:
- With the device loaded, we are ready to run the script by right-clicking and run as TestNG. The calculator app will open and the functions will execute.
Conclusion
Attached is a video of the execution of this test case, A few things to point out, again this tutorial has been set up by pooling resources from several locations. A lot of my setup was through trial and error, but if you follow these steps you should have a working TC. The scenario you may be looking for may not be the same, but this is a convenient way to build a TC with Appium. Appium has a great deal of functionality, whether it be simply helping with the execution of test cases or passing parameters to your tests.
To get a better understanding of Appium and for our partner Quilmont’s consulting practices with automation visit their website at Quilmont.com. Quilmont provides organizations with a comprehensive testing practice by fully utilizing industry leading software testing tools for mobile, web, and desktop applications. We (swtestacademy.com) thank Quilmont’s Solution Architect James Koch and CEO Patrick Quilter for their collaboration with us.
For execution, see the YouTube video below
Quilmont was established in 2007 by our owner and CEO Patrick Quilter. Patrick has over 15 years of experience in software development life cycle & test automation architecture. Quilmont owns a patented product called Test Case Manager, an automation framework that allows firms to get more out of their scripting tools. Quilmont was founded in Washington D.C., being so, we are still connected with several prime government contractors in the area that reach out to us when they need help; we are currently registered in the SAM database. Our partnerships include Polarion, HP, and Keynote Studios. We provide organizations with a comprehensive testing practice by fully utilizing industry-leading software testing tools.
Quilmont has had projects of all different kinds and scopes; from working with startups, government contracts, and even large fortune 500 companies like Berkshire Hathaway/Geico. Unlike the other products and consulting services on the market, Quilmont provides its clients with the most cost-effective and best-personalized solution to fit their automation needs. We provide customer service and support and offer training. At Quilmont it is our mission to form strategic relationships with other enthusiastic automated testing organizations. We utilize next-generation technologies to virtually distribute our solutions globally while providing our workforce with opportunities to enhance their IT skills.

James Koch is a CTFL, Senior Engineer at Slalom Build.