Best way to Automate mobile application : Appium
Welcome to our Appium Tutorial!
Nowadays automated test scripts are very important for mobile application testing. Through the automation script, we can reduce our time for the testing.
However, there is a number of automation testing tools for mobile application. We are going to discuss the Appium Automation Tool. Before we begin, let’s first know Appium.
What is Appium?
Appium is an open source and cross-platform tool. Appium supports the android as well as iOS applications. We can automate the scripts in six languages as Java, Ruby, Python, PHP, JavaScript, and C#. With the help of jar files, we can automate the mobile application. Appium supports from android version 2.3 to 4 by using Appium’s Selendroid driver and android versions 4.2 and up are supported via Appium’s uiautomatorviewer. We can run the scripts on real devices as well as on Android emulators.
Pre-requisites for Appium : (Script for Android Application)
To follow along with this guide, you would be requiring following things ready:
1.Java JDK installed with Java_Home
2. Android SDK installed withAndroid_Home
3.ADB which comes under android path- C:\Users\user\android-sdks\platform-tools .
4.Eclipse IDE.
5.Node js for windows.
6.Jar files for appium – to get this go to the appium-java .
Installations:
After following the prerequisites, follow this guide to how to install appium on windows operating system.
1.Java Application: JDK (Java SE Development Kit) – [ Compulsory ]
- Before installing Jenkins on the system first we need to install Java in the system.
- Go to the URL of Java software and download it as per the operating system i.e. Windows.
Link: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- After successfully download the software we need to install in the system.
- Once the installation is done completely we need to set an environmental variable in the system.
- To set the environmental variable we have to follow some steps-
- Go to the Control Panel —>All Control Panel Items –>System.
- Click on Advanced System Settings
- In the System properties, click on the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
- Give the complete path of Java by creating or editing Java_Home.
2.Android SDK installation
- Go to the Android SDK link. Download the android SDK as per the operating system. Here I have downloaded the installation file for Windows operating system min. version should be Android SDK ≥ 16.
- link – https://developer.android.com/studio/
- After installing it. Set the environmental path of Android SDK.
- Please refer above point to set the environmental path in windows operating system.
3.Eclipse IDE
- Go to the link of eclipse IDE.download it.
- link – https://www.eclipse.org/downloads/
- Install it. Now open the eclipse. We need TestNG software to run the test cases
- Go to Help –> install new software. add–> type name : TestNG
- Type Location: http://beust.com/eclipse/
- Accept the licenses and install it
4.Node.js
- Go to the link of Node.js and download it.
- link – https://nodejs.org/en/download/
- Install it.
5.Appium tool windows [By this we can get the appium GUI]
- Go to the link of appium and download it.
- link – http://appium.io/
- Install it as per the operating system. we will download the file as per windows operating system.
- By the help of this, we can get the inbuilt inspector to find out the elements.
Steps to Install the Appium Tool
- Step 1. Install the Java application.
- Step 2. Open a command prompt.
- Type the command: “node –v” (to check the node version. we will get the installed version of node)
- Step 3. Install Appium via NPM command.
- Type the command: “npm install -g appium”
- Step 4. After installation done successfully. Check the version of installed appium
- Type the command: “appium –v”
- Step 5. To start appium server
- Type the command: “appium”
We will get the appium version as well as will get the appium listener with the port number. This is useful to run an android application on the listening port successfully.
Steps to create the simple script for the Android application.
Step 1. To create the project first open eclipse.
Go to File –> New –> Other –> Select Maven Project –>select simple project and workspace –> type groupid artifact id etc and click on finish.
We will get the project in eclipse on the left-hand side.
Step 2. Now we will get the pom.xml file.
Set the properties of Test-NG and appium in that file. Here we will mention the TestNG version and appium jar files java version.
Step 3. Then click on src/test/java to create the package.
Src/test/java –> new –> package. Here Name of the package: “appiumPackage”
Step 4. Now create a class in a created package
Right click –> new –> class
A]Type new class name. Once a class is created then we will get it as in the figure. This class will be used to create appium android driver for appium.
B]Now again create another class for Testcase execution. Here is the testcase class to run the test cases using appium.
Step 5. Now go to the src/test/resources –> copy and paste the apk in that folder
Right click–>new–>folder
Step 6 .Type desired capabilities in the DemoClassForAppium.java
Here we need the code –
final File classpathRoot = new File(System.getProperty(“user.dir”));
final File appDir = new File(classpathRoot, “/src/test/resources/app/”);
final File app = new File(appDir, “Demo.apk”); // give the path of apk.
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(“browserName”, “”);
caps.setCapability(“platform”, “ANDROID”); //Assign platform name of your application.
caps.setCapability(“deviceName”, “name of your device”); //Name of your device
caps.setCapability(“platformVersion”, “version of your mobile”); //Version of your device
caps.setCapability(“appPackage”, “package of your application”); //package of the application
caps.setCapability(“appActivity”, “activity of your application”); //app activity of the application
This is very important. We have to mention the URL of the Appium server.
driver = new AndroidDriver(new URL(“http://0.0.0.0:4723/wd/hub”), caps);
Steps 6. Before run the application we have to set build path by providing archive files to the project.
For this We have to Build Path–> Configure Build Path–>Libraries–> Add external Jars–> Apply and close.
Step 7.Now we will use UIAutomator.To get UIAutomator, Go to the android sdk. And you will get the path of UIAutomator as below-
C:\Users\user\android-sdks\tools\uiautomatorviewer
By using this we can find the elements of the application. We can get the elements by resource-id, Xpath, accessibility id, text etc.
Example: Here I have given you the example for resource id. You can get the elements by other ways also.
@Test(priority = 0) //(Always give the priority to test case)
public void sampleTest() throws InterruptedException{
driver.findElement(MobileBy.id(“com…..”)).click();
System.out.println(“We are able to click on yes Button and allowing to proceed”);
Thread.sleep(100);
}
Step 8. Once after done this, we have to run the application. To run the application we have to right click on the application. Select RunAs–> TestNG Test.
i]Before we have to do this step. We have to attach the android device by USB. And start the appium server.
Start Appium Server: A]If you are starting the appium server by command prompt then we have type in cmd as : appium
B]If you are starting appium by GUI desktop. then open appium gui and start the server.
ii] Connect the real device to the system using adb and run the script using appium tool.
We can get the result of test cases on the console.
In this above Article, I just explained how we can easily automate the android application using Appium Tool. Hope you all liked it. Thank You..!!!