Professional Documents
Culture Documents
What Is Appium?
What Is Appium?
What is Appium?
Appium supports all languages that have Selenium client libraries like- Java, Objective-
C, JavaScript with node.js, PHP, Ruby, Python, C#, etc.
Appium is an 'HTTP Server' written using a Node.js platform and drives iOS and an
Android session using Webdriver JSON wire protocol. Hence, before initializing the
Appium Server, Node.js must be pre-installed on the system.
When Appium is downloaded and installed, then a server is set up on our machine
that exposes a REST API.
It receives connection and command request from the client and executes that
command on mobile devices (Android / iOS).
It responds back with HTTP responses. Again, to execute this request, it uses the
mobile test automation frameworks to drive the user interface of the apps. A
framework like:-
o Apple Instruments for iOS (Instruments are available only in Xcode 3.0
or later with OS X v10.5 and later)
o Google UIAutomator for Android API level 16 or higher
o Selendroid for Android API level 15 or less
Appium Studio is an Open source GUI app to install Appium Server. It comes bundled with
all the pre-requisites to install and use Appium Server. It also has an Inspector to get basic
information on your Apps. It comes with a Recorder to create boilerplate code to automate
your mobile apps.
Step 2) For Windows, select the exe file and download. The file is around 162MB will take
time to download based on your internet speed.
Step 3) Click on the downloaded exe.
Step 4) On a Windows machine, there is no need to install Appium. It runs directly from the
exe. Once you click the exe you will see the following image for few minutes.
Step 6) On clicking the Start Server Button, a new server is launched on the specified host
and port. Server log output is shown.
APPIUM Inspector
Similar to Selenium IDE record and playback tool, Appium has an 'Inspector' to record and
Playback. It records and plays native application behavior by inspecting DOM and generates
the test scripts in any desired language. However, currently, there is no support for Appium
Inspector for Microsoft Windows. In Windows, it launches the Appium Server but fails to
inspect elements. However, UIAutomator viewer can be used as an option for Inspecting
elements.
Step 1) Download and start your Appium server with the default IP Address 0.0.0.0 and the
port 4725.
Step 4) Click 'Launch' button from a top right corner, which enables a blue color icon. Again,
click on this blue color icon, it will open the Appium inspector and Simulator with a pre-
selected application.
Step 5)- Launching your Appium Inspector will show the element hierarchy in column-wise
structure. Also, a user can apply actions using buttons like Tap, Swipe, etc.
Step 6) Click on 'Stop' button to stop recording.
Go to Control panel >> System and Security >> System and from the left panel click on
'Advanced System Settings'. From 'System Properties' pop up, click on 'Advanced' tab and
then click on "Environment Variables" button.
Step 2) Now, from 'Environment variables' pop up, 'double click on 'Path' and set
ANDROID_HOME variable that point to your SDK directory. In the path append the whole
SDK folder path.
e.g. -
C:\User\ABC\Desktop\adt-bundled-windows-x86_64-20140321\sdk
Step 3) Start your Android emulator or any attach any Android device to your system (Make
sure you have Android Debugging option enabled in your Android device. To check
Debugging Option. Go to Device Settings >> Developer Options >> Check "Debugging
Option").
Step 4) Open Command Prompt and navigate to your Android SDK's \platform-tools\
directory (E.g. D:\adt-bundle-windows-x86_64-20130514\sdk\platform-tools).
Step 5)- Run 'adb devices' command. You can see your connected device listed in Command
Prompt window. (In CMD write '>adb devices'- This command will list the connected
emulator instances. E.g.: adb –s emulator-5554 install <Location of .apk file>)
Step 6)- Run 'adb start-server' command. It will start ADB server that will be used by
Appium to send commands to your Android device.
Step 7) Now, navigate to Appium directory in your system and start Appium by clicking an
Appium.exe file.
Step 8) Do not alter the IP address or port number and click 'Launch' button. Your Appium
console starts at 127.0.0.1:4723 as shown in below.
Step 9) Click on 'Start' button, Appium server started running on your system.
APPIUM Test Case for Native Android App(Calculator)
Step 1)) Download ADT eclipse plugin or download ADT bundled separately here
Step 2) Open Eclipse and Create a new Project >> Package >> Class
Step 4) Now Create a small test Program for 'Calculator.app' to sum two numbers.
package src_Appium;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
@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","Emulator");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
// This package name of your app (you can get it from apk info app)
capabilities.setCapability("appActivity","com.android.calculator2.Calculator"); //
This is Launcher activity of your app (you can get it from apk info app)
//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.tagName("EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match
with expected value: 6";
@AfterClass
public void teardown(){
//close the app
driver.quit();
}
}
Appium Server and Android Emulator from 'AVD Manager' and Click Run >> TestNG.
Above program will run the 'Calculator.app' on selected emulator and Result displayed under
Eclipse console using a TestNG framework.
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.
What is UiAutomatorViewer?
"Uiautomatorviewer" is a part of the Android SDK manager and will be accessible once you
install the SDK manager. Download and install Android SDK manager from here
c:\users\<username>\AppData\Local\Android\sdk\tools
You'll notice a batch file with name
uiautomatorviewer.bat
. Double click on it to launch "Uiautomatorviewer" GUI
How to use Uiautomatorviewer to find objects in my application
Upper panel contains node hierarchy the way the UI components are arranged and contained,
clicking on each node gives properties of UI elements in the lower panel
7. Select 'Quiz' button in the above image to view different properties (text, resource-
id...)
How to use these properties to identify elements for automation
Well, you cannot use the properties directly, each property has other names. Let's see how to
use those properties values to work. Following attributes can be used to identify 'Quiz' button
in Guru99 app.
Along with above attributes, we can write xpaths for object identification
Error one might encounter while using Uiautomatorviewer
I see the error- "No Android devices were detected by adb" as shown in below
screenshot how I can resolve this
This tutorial will help you to understand APPIUM automation tool. It will cover desired
capabilities and APPIUM with Maven uses.
'Desired Capabilities' help us to modify the behavior of server while Automation. In Appium,
it is a type of hashmap or key-value pair, used to send a command to APPIUM server. In
APPIUM, all the client commands are running in the context of a session.
For example, a client sent POST/session request containing JSON object to APPIUM server.
Hence, to send any desired request or to maintain any desired session with the server, a set of
Key and value pair is used. This is known as 'Desired Capabilities.'
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
}
'DesiredCapabilities' help the user to control the session request with the server. For
example- if we want iOS session then we might set Capability as PlatformName =
iOS. Or if we want Android session then we might set Capability as PlatformName =
Android.
'DesiredCapabilities' are used to set up the Webdriver instance eg: FirefoxDriver,
ChromeDriver, InternetExplorerDriver etc.
DesiredCapability is very useful for Selenium Grid. Eg: It is used to access different
test cases on a different browser and different operating system. Based on mentioned
DesiredCapability Grid, hub will point to the corresponding node. Here, these nodes
are defined using 'set' property method eg:-
DesiredCapabilities obj = new DesiredCapabilities();
obj.setBrowserName("firefox");
obj.setVersion("18.0.1");
obj.setPlatform(org.openqa.selenium.Platform.WINDOWS);
A desired capability is a library defined package. Prior to use 'DesiredCapabilities',it
should be imported from below mentioned library
Org.openqa.selenium.remote.DesiredCapabilities
APPIUM supports both Android and iOS. Therefore there are a separate set of Appium server
capabilities.
Below table depicts some commonly used Android capabilities and its value to use-
Below table depicts some commonly used iOS capabilities and its value to use-
Capabilities Description
LaunchTimeout Total time (in ms) to wait for instrumentation.
UDID To identify unique device number for connected physical device
Packages are related to bundled files or classes. It gives an organized structure to modular
programming. In Java, different packages are stored in a single Jar file. The user can easily
call the jar file for full execution. Similar concepts followed in Mobile application
development world.
In Android operating system, all applications are installed in the form of JAVA packages.
Hence, to extract packages path information, Android PackageManager class is used.
It retrieves package and activity information of pre and post installed application. It is
installed in Android devices.
You can get an instance of PackageManager class By calling getPackageManager().
This method can access and manipulate the packages and related permission of the installed
applications.
For example -
Summary:
What is ADB?
Using any real device for mobile automation Testing is always been a challenge for testers.
But, Android offers a handful solution to connect a real device over USB i.e. Android Debug
Bridge (ADB).
ADB is a command line tool. It is used to bridge communication between an emulator
instance (Android device) and background running daemon process (server).
APPIUM offers an advantage to execute test on real devices. But prior to run the test, we
need to setup following pre-requisite.
Here we will see both, connecting to emulator as well as with real device for testing. See
steps below for connecting to an emulator.
Pre-Requisite- SDK (Software Development Kit) should be installed on the machine. ADB is
packaged with Google's Android SDK (Software Development Kit). Steps to enable ADB
from SDK Manager.
Step 3) From the list of all packages select Tools and mark the checkbox for
Step 1) Enable USB debugging option from 'Developer Option' in Android phone.
Step 2) Open the local folder where Android SDK files has been saved 'Android SDK >>
Platform-tools' eg: C:\android-sdk\platform-tools
Step 3) Inside folder hold Shift + Right click menu >> Select 'Open command window
here' option.
Note- you can also open the folder path directly from the Run command in command prompt.
This command window will directly open the folder in command prompt window.
Step 4) Now, prior to check the device, user have to connect an external Android device
(mobile phone). To connect use the device USB cable connector to the system. Then in above
command prompt type command-
When server starts, it always bind the local TCP port 5037. All ADB clients listen to 5037
TCP port to communicate with server request.
Now, the running ADB server can scan all connected emulator or device instances by
scanning the port.
Always remember that ADB daemon runs on odd numbered port between the ranges of 5555
to 5558.
ADB daemon process runs with console connection that acquires even number port for
connection.
For example: If single device connected then server automatically scan the device and get
connected but if multiple device or emulator running the user need to give ADB command
line instruction to connect.
The emulator instance connected on odd numbered port 5557 has the same console running
over even numbered 5556 port ie. Each running devices has 1 odd and 1 even connected port.
So, this way user can set up a successful connection to access ADB instances using ADB
commands.
Just like configuring ADB over USB, user can also configure ADB over wi-fi.
Pre-requisite
Both Android device and the host computer should be connected to same wireless
network and
Device Bluetooth option should disabled.
Steps to connect-
1. Connect device using USB cable to the host computer. Confirm USB debugging is
enabled in device.
2. Set target device to connect TCP/IP on port 5555
Hence, the final configuration done and 'adb' successfully configured over wireless network.
NOTE- If any connection error occurred just reset or kill the adb host connection. For that
use following command
Using Maven framework, we can easily manage following tasks in any project-
Build cycle
Project Documentation
Report Checks
Scrums management
Release Information
Before start writing APPIUM test with Maven, we have to download the JAR file
from Maven central repository website.
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>3.4.1</version>
</dependency>
1. Group Id
2. Artifact Id
3. Version
4. Packaging
5. Name and Description
6. Finish
Clicking on Finish button. It will open a new class on the defined Group Id
(AppiumTest) name.
Step 3) To start with Appium script. Right click on 'src/main/java' from left side
explorer window. Then select New >> class. Write the Appium code inside the
selected class.
Step 4) In the same project, click over pom.xml from left explorer menu. All
dependencies will be visible by default in 'pom.xml' tab. Refer to the Image below-
If in the case of default pom.xml does not exist then just add all Maven Appium
dependencies. (extracted from Maven central repository website}
http://search.maven.org/#search|gav|1|g%3A%22io.appium%22%20AND
%20a%3A%22java-client%22
Step 5) Now, right click on 'pom.xml' from left explorer or over the xml code for
'AppiumTest' project. Then click 'Run As >> Maven Clean' option.
While running, the user could see all Maven related jar files and success message.
Hence, this way the user can run APPIUM test with Maven configured
environment.
Summary: