Appium was originally developed by Dan Cueller as a way to take advantage of the UI Automation framework for Apple iOS to run tests against native mobile applications. Using the same syntax as Selenium, it shares Selenium’s ability to automate interaction with a website through a mobile browser, but additionally provides a way to interact with elements that are specific to mobile applications, such as gestures. For this reason, while Appium can be used for website testing against mobile and desktop browsers, it is more commonly used for testing native and hybrid mobile applications for both iOS and Android.
- Appium is an HTTP server written in node.js which creates and handles multiple WebDriver sessions for different platforms like iOS and Android.
- Appium starts a “test case” on the device that spawns a server and listens for proxied commands from the main Appium server. It is almost same as Selenium server which perceives http requests from selenium client libraries and it handles those requests in different ways depending upon the platforms.
- Each vendor like iOS and Android have a different way and mechanism to run a test case on the device so Appium kind of hacks in to it and run this test case after listening commands from appium server.
How Appium Works on iOS?
In the above figure, we can see the architecture of the Appium in context to the iOS automation. If we talk about a command life-cycle, it goes like, Selenium webdriver picks a command form the code like (Element.click) and sends it in form of JSon via http request to the Appium server. Appium server knows the automation context like the iOS and Android and sends this command to the Instruments command server which will wait for the Instruments command client (written in node.js) to pick it up and execute it in bootstrap.js with in the iOS instruments environment. Once the command is executed the command client sends back the message to the Appium server which logs everything related to the command in its console. This cycle keeps going till the time all the commands gets executed.
APPIUM Design Concepts
- Appium is an ‘HTTP Server’ written using Node.js platform and drives iOS and 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 setup on our machine that exposes a REST API.
- It receives connection and command request from the client and execute 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. Framework like:-
- Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with OS X v10.5 and later)
- Google UIAutomator for Android API level 16 or higher
- Selendroid for Android API level 15 or less
General Prerequisite to use APPIUM
- ANDROID SDK [Link]-
- JDK (Java Development Kit) [Link]
- TestNG [Link]
- Eclipse [Link]
- Selenium Server JAR [Link]
- Webdriver Language Binding Library [Link]
- APPIUM For Windows [Link]
- APK App Info On Google Play [Link]
- Node.js (Not Required – Whenever Appium server is installed, it by default comes with “Node.exe” & NPM. It’s included in Current version of Appium.)
Basic Requirements for Appium
Eclipse or Android Studio should be installed in your system.
- iOS System Setup Requirements
- Mac OS
- Apple Developer Tools (iPhone simulator SDK)
- Android System Setup Requirements
- Android SDK & Java should be installed properly.
- Appium setup for Android as well as iOS on OS X, Linux, and Windows.
- Define desired capabilities for writing the Appium test.
How to Define Desired Capabilities?
Desired capability are the set of keys and values that store the properties such as deviceName, browserName, platformName, platformVersion and so on.
Here is the example of addition of Selenium Jars and its desired capabilities:
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.
Steps to start with Appium Inspector on Mac machine:-
1) Download Appium from link http://appium.io/ for iOS.
2) Right click on downloaded file & open it with DiskImageMounter as shown below. It will open Appium.app in different folder.
3) Drag Appium.app to Applications folder as shown below.
4) Open Appium.app by double click from Applications folder. First of all, you need to navigate to the Appium iOS settings by clicking the apple icon on the top. You won’t need to fill in all the forms. Remember to also check the round button just below the icon to make sure you are targeting the right platform.
5) The first thing you need to do is point the Appium server to the .APP file (Generated from Xcode project – Refer my doc “Appium-Run Xcode Project” for more detail) that you want to test. Simply check the “App Path” box and paste the path to the .App file in the text field, or navigate to it by clicking on the button.
6) Next, move a little further down the screen until you find the “Force Device” field, under “Device Settings”. Check the box and select the device you want to test on. Although in the end you can insert whatever text string you like, this step is mandatory.
7) Immediately below is the UDID field. Select the checkbox and open up Xcode. Navigate to Window -> Devices, the select your connected device from the sidebar on the left. You will need to copy the text in front of the “Identifier” row, go back to Appium and paste it in the UDID field.
8) Next up, you will need to check the “Full reset” box. This tells Appium to reset the state of the application we are testing every time we run a test.
9) Lastly, you will need to check if Appium knows the path to your Xcode application. Click on the “Advanced” tab and check that the path in the bottom field is correct. If there is none, just click the button and navigate to Xcode
10) You are now ready to start the server. Close the iOS settings screen and select the button. You should see some information being printed on the Appium terminal. After a couple of seconds you can click on the button with the icon, which will open up the Appium Inspector. At this point the app will be installed and launched on your device. The purpose of the Inspector is to allow you to reference the UI elements of the app you are testing so that you can interact with them.
How to use APIs to Locate elements and perform actions?
>By Name (By Content-desc)
This is also an efficient way to locate an element but again the problem is same as with ID that UI developer make it having non-unique names on a page or auto-generating the names. With this strategy, the first element with the name attribute value matching the location will be returned. If no element has a matching name attribute, a NoSuchElementException will be raised.
>By Class Name
With this you can find elements based on the value of the class attribute. If an element has many classes then this will match against each of them. A class can contain many elements.
With this strategy, the first element with the id attribute value matching the location will be returned. If no element has a matching id attribute, a NoSuchElementException will be raised. This is the most efficient and preferred way to locate an element, as most of the times IDs are unique.
Xpath is important locator in Appium, as you will end up many situation where you do not have any options but to use xpath. Xpath can be relative and absolute but it is suggested to always use relative xpath.
Use Cases and Deployment Scope
Appium is used across the whole organization by teams which own the Android and iOS native applications. We’re using it to automate large regression tests that by now we’re running manually. Appium let us improve our release process duration and increase the speed of the regression phase, giving us the option of reducing the manual testing team to one person.
At the moment, Appium is working with TestObject because with these 2 working together it’s possible to increase the device coverage and the speed of the whole release process with a nice quality level.
You can even refer the link for other explanations regarding eclipse.
With Appium you can automate tests for Android and iOS both. There is no need to learn more than 1 language.It’s really easy to configure and use Appium; it’s very useful when you’re testing strategy is based on “developers write tests”.It’s such a nice strength of Appium, because you don’t need to pay to use a good tool like Appium is.
We, at Let’s Nurture Infotech, provide custom iOS mobile app development, Android app development, website design and development, IoT based solutions and more software solutions to our clients globally. We have delivered more than 200 iPhone app development projects to our clients due to our expertise and adaptation to latest technologies and skill set.
We would be happy to help you!!