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

CI/CD Testing with JMeter

In this post, we’ll talk about how to do a performance test in CI/CD environment with the use of JMeter.

Usually, JMeter can run in two different modes: GUI, and non-GUI. The importance of the non-GUI mode is it will allow running the test with minimum resources. For CI/CD test we use this non-GUI mode. For this example, I’m using Jenkins as the CI tool.

First of all, you need to install and start Jenkins in your CI environment.

Install Performance Plugin

  • Click on ‘Manage Plugins’

Screen Shot 2018-05-30 at 3.47.09 PM

  • Search ”Performance” in ‘Available’ tab

Screen Shot 2018-05-30 at 3.47.48 PM

  • Click on ‘Download now and install after restart’ button

Create a Jenkins Project

  • Click ‘New Item’
    Create the ‘Freestyle project’ and click ‘OK’

Screen Shot 2018-05-30 at 3.44.39 PM.png

  • ‘Add build step’ according to your environment (eg: ‘Execute Windows batch command’ for Windows & ‘Execute shell’ for mac/Linux)

Screen Shot 2018-05-31 at 2.28.32 PM.png

  • For the command space, add JMeter run command in non-GUI mode.Screen Shot 2018-05-30 at 3.46.10 PM.png

syntax:

<JMeter_location>/bin/jmeter.sh -n -t <JMX_Location>/<JMXFile>.jmx -l results.jtl

eg:

/Applications/apache-jmeter-4.0/bin/jmeter.sh -n -t /Users/deranthika/JMeterAPI/APITest.jmx -l results.jtl

-n : Non-GUI mode – this specifies JMeter is to run in non-GUI mode

-t : JMX file – location of the test plan and the name of JMX file that contains the Test Plan

-l : log file name of JTL file to log sample results to

  • ‘Add post-build action’ and select ‘Publish Performance test result report’

Screen Shot 2018-05-31 at 2.57.37 PM.png

  • For the source data file provide .jtl file name (eg: results.jtl)

Screen Shot 2018-05-30 at 4.06.49 PM.png

  • Click on ‘Save’

Build and View Graph

  • Build the project
  • You will be able to see results graph on your dashboard. NOTE: graph values will display after the second build finish.

 

Screen Shot 2018-05-31 at 3.04.51 PM.png

You can view graph by clicking ‘Performance Trend’ link in the left corner

Screen Shot 2018-05-31 at 3.05.00 PM.png

Screen Shot 2018-05-31 at 3.07.28 PM.png

Last Report

Screen Shot 2018-05-31 at 3.07.35 PM.png

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 😉

Download Files Using JMeter

Hola Testers,

Let’s talk about how to download a file from API call using JMeter. First you have to create a JMeter project by adding Thread Group, HTTP Requests and etc. Then, add a “Save Responses to a file” Listener to the download HTTP Request

  • Right click on the HTTP Request > Add > Listener > Save Responses to a file

Screen Shot 2017-03-24 at 3.41.52 PM

And Then, you can add further inputs to the save file

Filename prefix: File will download to this location (~ sign mentioned: file will download to the location where jmeter script saves in your machine)

Screen Shot 2017-03-20 at 6.42.11 PM

After run test you can see the downloaded file in the mentioned location.

Screen Shot 2017-03-20 at 6.44.32 PM

Send SOAP Request using JMeter (2)

Hola Testers,

Today I would like to show another method for send SOAP request. In my previous post I showed with “HTTP Request”. Today, I’m going to do the same request using “SOAP/XML-RPC Request”.

1. First, add a Thread Group
2. Then add a “SOAP/XML-RPC Request” by right click on the Thread Group > Add > Sampler > SOAP/XML-RPC Request
Screen Shot 2016-04-24 at 9.09.21 PM.png

3. The SOAP/XML-RPC Request allows you to add following variables,
-URL of the WSDL
-SOAP Action
-And SOAP data
I’ve add request XML, WSDL URL and SOAP Action as below. (It depends with your SOAP request)
Screen Shot 2016-04-24 at 9.10.08 PM.png

4. Then, add a listener, save the project and run it.
You’ll be able to see the response in listener (I added “View Results Tree” listener and I can see the response in “Response data” tab of the listener)
Screen Shot 2016-04-24 at 9.10.36 PM.png

Send SOAP Request Using JMeter

SOAP (Simple Object Access Protocol) is a protocol specification for exchanging structured information the implementation of web services using XML. But how we implement this on jmeter? Yes, there are some solutions. Today I’ll show one simple way to do it.

1. Open JMeter > Add a Thread Group
2. Add a HTTP Request for the Thread Group
Screen Shot 2016-04-17 at 10.04.29 AM.png

3. Fill host, port, method and path according to your WSDL name
For example I’m using http://www.webservicex.net/country.asmx?WSDL file
My variables will be,
Host: webservicex.net
Port:
Method: POST
Path:/country.asmx?WSDL
Screen Shot 2016-04-19 at 10.41.57 AM

4. Select “Body Data” tab of the HTTP Request and add request URL with parameter
Screen Shot 2016-04-19 at 10.42.10 AM

5. Add a HTTP Header Manager to the Thread Group and add needed Header requests
Screen Shot 2016-04-19 at 10.42.24 AM

6. Add a Listener to get the results. I used “View Results Tree”
7. Save and Run the test. You can see response xml on “Response data” tab of the Listener
Screen Shot 2016-04-19 at 10.42.40 AM.png

Write values in CSV using JMeter

Hola Testers,

On my last post we were talking about read values from csv external data source. I thought this time we should talk about write values on csv. Imagine our jmeter script is creating some number of files in our web application, and you need to know the names of those files to use it later. In this kind of scenario, we can use csv writer to keep our files name for future use.

Add a Beanshell PostProcessor for the HTTP request which creating files
Right click on HTTP request > Add > Post Processors > Beanshell Postprocessors
Screen Shot 2016-04-10 at 8.25.09 AM.png
(You may need a regular expression extractor to HTTP Request for extract the file name.)

Write a write script to write the file name on csv
You can write a simple beanshell script to write file’s name on csv. A sample script like below,

generatedDocID = vars.get("DocID");
filepath =vars.get("FilePath");
f = new FileOutputStream(filepath, true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(generatedDocID);
f.close();

Where “DocID” is the variable we used in regular expression extractor and “FilePath” is the variable name for the csv filepath/name. That variable you can initialise in user defined variables. 🙂