Introduction to Appium

In this post, I would like to give a brief introduction to Appium and Appium design architecture. Appium is an open-source mobile application automation tool which can run the test on various platforms (cross-platform) such as Android, iOS, and Windows. Appium can use to test Native, Hybrid, and Mobile web applications.

Appium Philosophy

Appium was designed with 4 major design concepts;

  1. You shouldn’t have to recompile your app or modify it in any way in order to automate it.
  2. You shouldn’t be locked into a specific language or framework to write and run your tests.
  3. A mobile automation framework shouldn’t reinvent the wheel when it comes to automation APIs.
  4. A mobile automation framework should be open source, in spirit and practice as well as in name!

Appium Architecture

Appium is an HTTP server written in Node.js that creates and handles WebDriver sessions. Appium web server works as same as Selenium WebDriver, which receives HTTP requests from client libraries through JSON and handle those requests in different ways according to the platform.

Appium in iOS

Appium uses apples’ XCUITest (for iOS 9.3 and above) and UIAutomation (for iOS 9.3 and lower ) to interact with UI elements.

iOS-Architecture

Pic Courtesy: IBM developerWorks

  1. When the user executes the test script, It goes to Appium server as an HTTP request through JSON.
  2. Appium server sends the command to the instruments.
  3. The instruments look for the bootstrap.js file, which pushes to the iOS device by Appium server.
  4. Then, commands execute in the bootstrap.js file within the instruments’ environment.
  5. After the execution done, the client sends back the message to the Appium server with the log details of execution commands.

Appium in Android

For android, Appium use UiAutomator/UiAutomator2 (for android 4.2+) and Intrumentation (for android 2.3+) to automate the apps. Instrumentation support is provided by bundling a separate project, Selendroid.

Android-Architecture

Pic Courtesy: IBM developerWorks

Here, UiAutomator and Selendroid have in place of apples’ instruments and bootstrap.jar in place of bootstrap.js

JSON Wire protocol

It is a transport mechanism to send user-created test scripts to Appium Server as an HTTP request. It is a specific set of predefined, standardized endpoints exposed via RESTful API.

Appium Concepts

Client/Server Architecture

Appium is an HTTP server that exposes a REST API. It receives a connection from a client, listens to commands, executes it on mobile devices and responds with HTTP respond. This client/ server architecture enables you to write code in any language (Java, C#, Ruby, Python, JavaScript & PHP etc.) that has client API. But it is recommended to use one of the Appium Client Libraries. Appium extends WebDriver client libraries and adds extra commands to work with mobile devices such as multitouch, long press & screen orientation etc.

Sessions

Automation is always performed in the context of a session. The client library requests server to create a session. The server creates a session and responds to the client with a sessionId. which is used to send commands to interact with that app(s) being tested.

Desired Capabilities

Desired capabilities are JSON object which sends by the client to server to tell the server what kind of automation session we’re interested in starting up. There are also various capabilities which can modify the behavior of the server during automation. You can find a complete list of Appium capabilities from here.

Appium Server

Appium server written in Node.js. It can build and install from the source or directly install from npm

$ npm install -g appium 
$ appium

Appium Desktop

There is a GUI version of Appium server that can be download for any platform. It comes bundled with everything required to run the Appium server, so you don’t need to worry about Node. It also comes with an Inspector, which enables you to check out the hierarchy of your app. You can download Appium desktop from here.

Appium Clients

There are client libraries (Java, Ruby, Python, PHP, JavaScript, and C#) which support Appium’s extensions to the WebDriver protocol. When using Appium, you may have to use one of these client libraries. You can view the full list of libraries here.

 

Advertisements

How to Configure Selenium WebDriver

Hola Testers,

Today I’m going to to tell how to configure Selenium WebDriver. Yes, this is the first lesson for Selenium WebDriver. I hope this will be useful for new users. In here, I’m going to use Java as my programming language. I’m going to divide this tutorial for below partitions.

  • Create a project and configure .jar files
  • Configure TestNG
  • Configure Firefox browser
  • Configure Chrome browser
  • Configure Internet Explore browser

Create a project and configure .jar files

To create a project we need programming IDE. Here I’m using eclipse.

  • Open Eclipse
  • Create a new Java Project

Screen Shot 2017-04-11 at 5.25.04 PM

After create a java project we need to download selenium webdriver jars.

  • Go to seleniumhq download page
  • Download and unzip the WebDriver bindings

Screen Shot 2017-04-11 at 4.19.34 PM.png

  • Create a folder called “libs” in java project (right click on the project > New > Folder)

Screen Shot 2017-04-11 at 5.37.45 PM

  • Paste all the .jar files from extracted folder of the downloaded zip file

Screen Shot 2017-04-11 at 5.45.01 PMScreen Shot 2017-04-11 at 5.46.12 PM

Now we have to add those .jar files to build path.

Select all .jar files in “libs” folder > right click > Build Path > Add to Build Path

Screen Shot 2017-04-11 at 5.49.22 PM

  • After that you can see all the .jar files in newly created “Referenced Libraries” library folder

Screen Shot 2017-04-11 at 5.49.37 PM

Configure TestNG

Click on Help menu > Install New Software..

Screen Shot 2017-04-11 at 6.00.43 PM.png

  • Click on Add button, “Add Repository” box will appear.
  • Enter below values as inputs and click “OK”
    • Name: TestNG
    • Location: http://beust.com/eclipse

Screen Shot 2017-04-11 at 6.02.59 PM

  • Accept agreement details and install TestNG. (If it gives warning, click OK)
  • After successful installation system ask to restart eclipse, allow it.

Screen Shot 2017-04-11 at 6.15.04 PM.png

 

Configure Firebox browser

  • Download geckoDriver from seleniumhq download page Third Party Drivers, Bindings and Plugins section and unzip it

Screen Shot 2017-04-11 at 9.19.58 PM

  • Create a folder called “driver” in project and add unzipped file. Don’t copy through eclipse.

Screen Shot 2017-04-11 at 9.40.04 PM.png

  • Create a class
  • Import Firefox browser driver
import org.openqa.selenium.firefox.FirefoxDriver
  • Initialize FirefoxDriver object
System.setProperty("webdriver.gecko.driver", "path of geckodrivergeckodriver"); 
FirefoxDriver fd=new FirefoxDriver();

Sample code

@Test

  public void firefoxTest() {

 System.setProperty("webdriver.gecko.driver", "/Users/deranthika/Documents/eclipse/workspace/TestSelenium/drivers/geckodriver");

FirefoxDriver fd=new FirefoxDriver();

fd.get("http://google.lk");

  }

If you are using windows OS, you need to put location as below

System.setProperty("webdriver.gecko.driver","path of geckodriver.exe");

Screen Shot 2017-04-11 at 8.22.38 PM.png

Screen Shot 2017-04-11 at 9.42.55 PM.png

 

Configure Chrome browser

  • Instead of gecko, you need to download chromeDriver from seleniumhq download page
  • Download the latest stable version for your OS and copy it to drivers folder
  • Import chromeDriver
import org.openqa.selenium.chrome.ChromeDriver;
  • Create new test method
  • Initailize chromeDriver object
System.setProperty("webdriver.chrome.driver", "/Users/deranthika/Documents/eclipse/workspace/TestSelenium/drivers/chromedriver");

ChromeDriver cd=new ChromeDriver();

sample code

@Test

  public void chromeTest() {

 System.setProperty("webdriver.chrome.driver", "/Users/deranthika/Documents/eclipse/workspace/TestSelenium/drivers/chromedriver");

ChromeDriver cd=new ChromeDriver();

cd.get("http://google.lk");

  }

Screen Shot 2017-04-11 at 9.58.12 PMScreen Shot 2017-04-11 at 9.58.25 PM

Configure Internet Explorer browser

  • you need to download InternetExplorerDriver from seleniumhq download page
  • Download the latest stable version and copy it to drivers folder
  • Import InternetExplorerDriver
import org.openqa.selenium.ie.InternetExplorerDriver;
  • Create new test method
  • Initailize InternetExplorerDriver object
System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer.exe");

InternetExplorerDriver id= new InternetExplorerDriver();

sample code

@Test

  public void chromeTest() {

System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer.exe");

InternetExplorerDriver id= new InternetExplorerDriver();

id.get("http://google.lk");

  }

Untitled.png

I’ll add more browsers later 😉