Appium Tutorial for Testing Andoid and iOS Mobile Apps

How to Install and Setup Appium on Windows with First Program to Get a Kick Start on Appium:

Appium is an open source and cross-platform tool that helps automate Mobile Apps testing – both Android and iOS Apps. Appium supports Native, Mobile and Hybrid Apps.

There are three types of Mobile Apps:

  • Native: Native apps built using the iOS, Android, or Windows SDKs. They are platform specific. They are built to work on a platform and/or device.
  • Hybrid: Hybrid apps are web applications developed using HTML, CSS, and wrapper of a native application on top of UIWebView for iOS and “webview” for Android Apps.
  • Mobile web apps: Mobile web apps are the apps ones accessed using mobile browsers.

Appium tutorial for beginners

Why is Appium a popular tool for automating Mobile Apps?

Appium is a “cross-platform tool” i.e. it allows you to write tests on multiple platforms (iOS, Android, Windows), using the same APIs. It is the most widely used tool for regression testing Mobile Apps on mobile phones and tablets.

Setting up the Appium Tool on Windows

Prerequisites: This is a short list of software and hardware required for automating a mobile App testing using Appium:

  • Your PC should have JDK, Appium Server, Eclipse, Android SDK installed
  • Apk: Mobile Application to be automated in our Case ContactManager.apk
  • Testing Device: In this case Moto G
  • Jars: Java-client jars and Selenium Jars.
  • USB driver for Testing Device: In this case Moto G

Step #1: Install the Java Development Kit (JDK)

Step #2: Set up Java Environment Variable Path

Step #3: Download and install Android SDK here  and update the APIs

To update API, Open Eclipse -> Click on Window in the Eclipse Menu and -> Select Android SDK manager

Update the APIs as shown in the below Screenshot:

Android SDK manager

Step #4: Now we need to install Appium for Windows. Go here and download Appium for Windows.

Step #5: Install Node JS from here: Node JS download 

Step #6: Set the ANDROID_HOME path as well as JAVA_HOME path

Specify the path for tools and platform-tool present in Android SDK path.

Android SDK path

These folders would be present in adt-bundle-windows-x86_64-20140702\sdk

Now we need to update the Environment variable (Refer below Screenshot)

(Note: Click on any image for enlarged view)

Update the Environment variable

Update path with tools and platform-tools (folder present in Android SDK).

The entry in Path will look as below:

C:\Program Files\nodejs\;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

Step #7:  Access adb

Press Win+R keys combination
Type CMD. Now in CMD type ‘adb’. adb will be accessible

Preparing Mobile Device for Automation with Appium

Connect your Mobile Testing device via USB to PC. Enable Developer Mode on Mobile Phone before automating the app.

Steps to Enable Developer Mode/Options on Android Phone or Tablet:

1) Open Settings, Tap on ‘About’ Option, Tap on ‘Software Information’, Tap On ‘More’.

2) Tap on “Build number” 7 times to enable Developer options.

3) Go back to Settings and make sure that “Developer options” is there.

4) Tap on Developer options and turn on USB Debugging option from the menu on the next screen.

Enable Developer Mode

For more help follow this link.

5) Download and install USB Drivers for the Mobile Testing device on PC.

6) In adb terminal type ‘adb devices’
C:\Users\NEERAJ>adb devices
List of devices attached
TA93305G0L      device

adb devices

This will display the list of devices connected to the system.We will be using App Contact Manager.apk as a sample App to automate. Download and install Contact Manager.apk on the device.

Starting  Automating Android App using Appium

Now run the appium.exe on PC.

Run Appium

Appium needs to be running and pass the following parameters and Device Name in Android Settings.

Note: Don’t change port number or anything in general setting icon. When Appium Server starts, the Server address, as well as Port address, will set by default. Port address will be 4723 by default

In Android Setting, the user needs to set APK path where the APK is located, Check app path, package and launch Activity.

------------

  • Connect your android phone to PC and turn on USB debugging mode.
  • Open Command prompt.
  • Type command adb logcat.
  • Open app on your android phone. Immediately press CTRL + C in command prompt

press CTRL + C

com.example.android.contactmanager is package name and com.example.android.contactmanager.ContactManager is activity name of Contact Manager app.

Contact Manager app

In above screenshot, we have populated all the needed information in Appium i.e package, launch activity, Mobile Device Name.

How to Locate Element using UIAutomatorViewer?

1) To automate the App firstly we will need to find the elements of the app that we will need to interact
for that, we will use UIAutomatorViewer

2) Connect the device in which App is installed to PC

3) Go to Terminal.

Type ‘adb devices‘

C:\Users\NEERAJ>adb devices
List of devices attached
TA93305G0L      device

This will show the list of devices connected to your PC.

4) Open the App which you want to automate in Mobile Device.

5) Open UIAutomatorViewer and go to the following path

adt-bundle-windows-x86_64-20140702\sdk\tools

adt-bundle-windows

6) So making sure your App is launched and UIAutomaterViewer is launched click on Device screenshot.

7) This option will take the screenshot of the App with all the detailed information of all the elements visible on the App.

App with all the detailed information

Click on Add contact Button for our Test Scenario

Add contact Button

From above screenshot, we can use locator By.name(“Add Contact”)

use locator By name

From above screenshot we can take By.className(“android.widget.EditText”)) as our locator for Contact Name

locator for Contact Name

By.name(“Save”) can be used as our locator for Save Button

First program For automating an App on Appium

Run the below Script, Contact Manager application will be launched on the real device and all the logs will be displayed in the Appium console showing you the all the actions getting invoked by the above script.

importjava.io.File;
importjava.net.MalformedURLException;
import java.net.URL;
importjava.util.List;

importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.remote.CapabilityType;
importorg.openqa.selenium.remote.DesiredCapabilities;
importorg.openqa.selenium.remote.RemoteWebDriver;
importorg.testng.annotations.*;

public class appium {

 WebDriver driver;

 @BeforeClass
 public void setUp() throws Exception {

//location of the app
 File app = new File("C:\\Users\\NEERAJ\\Downloads", "ContactManager.apk");
 
 //To create an object of Desired Capabilities
 DesiredCapabilities capability = new DesiredCapabilities();
//OS Name
 capability.setCapability("device","Android");
 capability.setCapability(CapabilityType.BROWSER_NAME, "");
//Mobile OS version. In My case its running on Android 4.2
 capability.setCapability(CapabilityType.VERSION, "4.2");
 capability.setCapability("app", app.getAbsolutePath());
//To Setup the device name
 capability.setCapability("deviceName","Moto G");
 capability.setCapability("platformName","Android");
//set the package name of the app
 capability.setCapability("app-package", "com.example.android.contactmanager-1");
 //set the Launcher activity name of the app
 capability.setCapability("app-activity", ".ContactManager");
//driver object with new Url and Capabilities
 driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capability);
 }

 @Test
public void testApp() throws MalformedURLException{

System.out.println("App launched");
 // locate Add Contact button and click it
WebElementaddContactButton = driver.findElement(By.name("Add Contact"));
addContactButton.click();
 //locate input fields and type name and email for a new contact and save it
 List<WebElement>textFields = driver.findElements(By.className("android.widget.EditText"));
textFields.get(0).sendKeys("Neeraj Test");
textFields.get(1).sendKeys("9999999999");
textFields.get(2).sendKeys("testemail@domain.com");
driver.findElement(By.name("Save")).click();
 //insert assertions here
 }
 }

Conclusion

With Emerging Trend and more demand for Mobile Apps, all major companies are migrating to get their business on mobile apps. Thus to release the quality Mobile apps, automation Testing of Mobile Apps is the latest trend in the industry.

Appium, because of its simplicity and ease of use, is one of the leaders and most widely used tool all over the globe for performing Automation testing of Mobile Apps i.e. for iOS or Android.

About the author: This post is written by STH team member Neeraj. He is a passionate Software tester currently working as a Senior Software Development Engineer in Test and enjoys testing Web and mobile applications.

Hope you will find this Appium tutorial useful. We are open for the discussion. Feel free to add your queries in comments below.

Recommended reading

4 comments ↓

#1 Dinesh Guptha Sivaguru

Hi…Do u have only this post available from Appium space?

If a person from manual testing background, want to enhance his career in automation space, Is this the right place to enhance him in an automation space?

#2 Prabhu misal

very hands on guide. can you share more on appium

#3 Patrik S

Nice insights describing the learning about the Appium for the beginners. One more tool I would like to suggest for Mobile app testing through automation is TestingWhiz. This is a code-less test automation tool for web, database, cloud, mobile apps, etc.

#4 Holly martin

you have done gud work for sharing this appium tutorial for beginners..It is exactly what i was looking for.
Thank You . keep going .

Leave a Comment