SoftwareQA

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 😉

Advertisements

Selenium Grid: An Introduction

Hola Testers!

Today we are going to talk about Selenium Grid!

What is Selenium Grid

Selenium Grid is a part of Selenium Suite which used to running multiple browsers on multiple environment at same time. There are two types of grid Grid 1 and Grid 2. Grid 1 is now deprecating by selenium team. So it is better to learn Grid 2.

Difference Between Grid 1 and Grid 2

Selenium Grid 1 Selenium Grid 2
Has own remote control Bundled with Selenium Server jar files
Need to install and configure Apache Ant before use Grid 1 No need to install Apache Ant
Only support Selenium RC Commands/scripts Support both Selenium RC and WebDriver scripts
Can only automate one browser per RC One RC can automate upto 5 browsers

Selenium Grid using hub-node concept to run.

What is Hub?

  • Is the central point where you need to keep your test scripts
  • There should be one hub for grid
  • All the nodes connect to the hub
  • Hub is running test, but browsers being automated in node

What is Node?

  • Selenium instances that executes tests which stores in hub
  • There can be one or more nodes per grid
  • Nodes can be launches in different platforms and different browsers

We’ll run a sample Selenium Grid test soon!

Run a TestNG project with Maven

Hola Testors!

Today I’m gonna show you how to run TestNG project with Maven. I’m taking my previous TestNG project for this one. You can download it from here.

I tried to run it in maven. Build got success. But you won’t see run anything.

Screen Shot 2015-09-20 at 2.54.58 PM

There is a solution for this: surefire plugin 😀

You need to add testng dependency to pom.xml and add below plugin too.


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>crossbrowsing.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

Here suiteXmlFile is out testng xml. You can pass many parameters with this plugin according to your scenarios. For more info about maven testng surefire plugin visit maven page.

See you soon!

Cross Browser Testing with TestNG

Hola Testors!

Cross browser testing become important when you are executing automation script on regression. Because your customer may request to work the particular web application on different browsers. So you need to automate the application to run in different browsers. As with our current script it will support only one browser at a time. So you have to change your browser parameter and have to run it again and again. That is why cross browser concept came to picture. By using TestNG we can easily do cross browser testing. Let’s do it!

There are two ways to do cross browser testing;

  1. Sequential order
  2. Parallel order

Sequential

First we look at how to do it on sequentially.

First Create a sample project (I’m creating sample maven project called crossbrowserTest )and apply all the dependancies.

Since this is TestNG, we have to include TestNG dependancy to our pom.xml.

<dependency>
     <groupId>org.testng</groupId>
     <artifactId>testng</artifactId>
     <version>6.9.6</version>
</dependency>

You can download TestNG repositories or JAR from maven repository by clicking here.

Then I’m creating a class to test google home page in different browsers. So, I’m creating a java class called VerifyTitle under src/test/java

package com.daz.crossbrowserTest.crossbrowserTest;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class VerifyTitle {
    WebDriver driver;
    static String CHROME_PATH="drivers/chromedriver";
    static String URL="http://www.google.lk";
    
    @Test
    @Parameters("browser")
    public void VerifyPageTitle(String BrowserName)
	{
		if(BrowserName.equalsIgnoreCase("Firefox"))
		{
			driver=new FirefoxDriver();
		}
		else if(BrowserName.equalsIgnoreCase("Safari"))
		{
			driver=new SafariDriver();
		}
		else if(BrowserName.equalsIgnoreCase("Chrome"))
		{
			System.setProperty("webdriver.chrome.driver", CHROME_PATH);
			driver=new ChromeDriver();
		}
		driver.manage().window().maximize();
		driver.get(URL);
		System.out.println(BrowserName+" : "+driver.getTitle());
		driver.quit();
	}

}

Make sure to create @Test and @Parameter annotations with TestNG

Screen Shot 2015-09-16 at 10.13.58 PM Screen Shot 2015-09-16 at 10.17.54 PM

Our class is ready now. What Next?

We have to pass the browser to our test class. That is the place we do cross browsing.

Right Click on Class > TestNG > Convert to TestNG.

It will display “Refactoring” dialog box. There you can give a any name for the xml (I’m giving crossbrowsing.xml) and click Finish

Screen Shot 2015-09-16 at 10.50.14 PM    Screen Shot 2015-09-16 at 10.50.39 PM

Open the crossbrowsing.xml and add tests to the suite as below

<?xml version="1.0" encoding="UTF-8">
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
    <test name="FirefoxTest">
  	<parameter name="browser" value="Firefox"/>
  	<classes>
  		<class name="com.daz.crossbrowserTest.crossbrowserTest.VerifyTitle">
  	</classes>
  </test>
  <test name="SafariTest">
  <parameter name="browser" value="Safari"/>
  <classes>
  	<class name="com.daz.crossbrowserTest.crossbrowserTest.VerifyTitle"/>
  </classes>
  </test>
  <test name="ChromeTest">
  	<parameter name="browser" value="Chrome"/>
  	<classes>
  		<class name="com.daz.crossbrowserTest.crossbrowserTest.VerifyTitle"/>
  	</classes>
  </test>
</suite>

Here I explain what the <class name> in above xml. That is your test class name. You can give it as <package_name>.<class_name>.

Now you can run the test by right click on crossbrowsing.xml > Run As > TestNG Suite

Screen Shot 2015-09-16 at 11.09.44 PM

Since this is sequential, it will run according to the order of browsers giving on crossbrowsing.xml.

In our example it will Firefox, Opera and Chrome. Here I add console output and TestNG output

Screen Shot 2015-09-16 at 11.12.59 PM  Screen Shot 2015-09-16 at 11.13.09 PM

Parallel

Now we can look how to do parallel test. Now it is easy 😉

Open crossbrowsing.xml file and do below change

<suite name="Suite" parallel="tests">

Save the xml

Right click on crossbrowsing.xml > Run As > TestNG Suite.

In this scenario all the browsers will open parallel. But you can see test results will differ from sequential order. Because fastest browser will finish the test first.  Here I attach my parallel test results as well.

Screen Shot 2015-09-16 at 11.18.29 PM    Screen Shot 2015-09-16 at 11.18.42 PM

You can find sample code for this project from my GitHub by clicking here

See you soon!

Getting Start with SoapUI

Hola Testors!

I thought to getting start of SoapUI with some example scenario rather than introducing the interface first. So shall we do a little exercise today? Previously I told we mainly we use two kind of web protocols to test (SOAP and REST). Today I’m gonna use SOAP service to test. Let’s begin:

Download and configure SoapUI

First, you need to download and install SoapUIto your computer.
Go to soapui official page and download a version which match with your computer (I’m using Mac OS X installer (64-bit) version)
SoapUI official site: http://www.soapui.org/.

Screen Shot 2015-08-16 at 1.10.06 PM

After the download happens, you can install it as a normal application. In Mac it will installed to your /Application directory by default. In windows > Program Files

Create a workspace

After the installation you can use SoapUI. First of all open the application. Then create a workspace by

File> New Workspace

Screen Shot 2015-08-16 at 1.20.26 PM

Create a SOAP Project

Now you have a workspace to work. As I mentioned earlier we’re gonna create a SOAP project. How to do it

File> New SOAP Project

Screen Shot 2015-08-16 at 1.24.58 PM

Screen Shot 2015-08-16 at 1.26.41 PM

  1. Project Name: Currency Converter
  2. Initial WSDL: http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
  3. Keep checked for “Create Request”
  4. Click “OK”

It will create two version of services (CurrencyConvertorSoap and CurrencyConvertorSoap12). First one follows older standards of SOAP.

Screen Shot 2015-08-16 at 1.52.36 PM

Remove CurrencyConvertorSoap12 version since no use of it.

Expand CurrencyConvertorSoap version, there you can see a “ConversionRate” method.By expanding that method you’ll be able to see “Request1” request.

So let’s make it useful, Right click on it and rename to “GBP To LKR”

Screen Shot 2015-08-16 at 1.40.41 PM

Double click on the Request, it will display you a simple xml request

Screen Shot 2015-08-16 at 1.57.11 PM


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
  <soapenv:Header/>
  <soapenv:Body>
     <web:ConversionRate>
        <web:FromCurrency>?</web:FromCurrency>
        <web:ToCurrency>?</web:ToCurrency>
     </web:ConversionRate>
  </soapenv:Body>
</soapenv:Envelope>

In the request xml you can see “?” marks for “FromCurrency” and “ToCurrency”.

You can test the request by replacing question mark of “FromCurrency” parameter by “GBP” and “ToCurrency” parameter by “LKR”.


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
  <soapenv:Header/>
  <soapenv:Body>
     <web:ConversionRate>
        <web:FromCurrency>GBP</web:FromCurrency>
        <web:ToCurrency>LKR</web:ToCurrency>
     </web:ConversionRate>
  </soapenv:Body>
</soapenv:Envelope>

By clicking “Submit request” button of request window (upper left corner) you’ll be able to get the response xml with GBP to LKR exchange rate.


<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
     <ConversionRateResponse xmlns="http://www.webserviceX.NET/">
        <ConversionRateResult>207.3026</ConversionRateResult>
     </ConversionRateResponse>
  </soap:Body>
</soap:Envelope>

Create a Test Suite/ Test Case

My request is working correctly. hope your one too. Now we have to test this service for GBP to LKR conversion. So we’re are gonna create a test case.

Right click on “GBP To LKR” request > Select “Add to TestCase”

Screen Shot 2015-08-16 at 1.58.57 PM

Oh, It is saying we don’t have a test suite to add the test case :O Okay we’ll create a test suite first.

Screen Shot 2015-08-16 at 1.59.57 PM

Then we create a test case

Screen Shot 2015-08-16 at 2.00.16 PM

Screen Shot 2015-08-16 at 2.00.23 PM

Screen Shot 2015-08-16 at 2.00.42 PM

Your test case will display in the tree as below

Workspace> Project> Test Suite > Test Case

There you can see Test Step, Load Test and Security Test. We’re gonna do a functional test. So our section is “Test Steps”. By default SoapUI creates a test step for us. Lets see what is inside there.

Screen Shot 2015-08-16 at 2.10.40 PM

Ahh it is same like the request XML! We change the xml to testable format that what we need. Change web:FromCurrency to GBP and web:ToCurrency to LKR as below


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:ConversionRate>
         <web:FromCurrency>GBP</web:FromCurrency>
         <web:ToCurrency>LKR</web:ToCurrency>
      </web:ConversionRate>
   </soapenv:Body>
</soapenv:Envelope>

Shall we check whether we get a correct output.

Click on the submit request button on top left corner. (Refer below screenshot)

It will generate an response xml

Screen Shot 2015-08-16 at 2.41.21 PM


<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <ConversionRateResponse xmlns="http://www.webserviceX.NET/">
         <ConversionRateResult>210.6568</ConversionRateResult>
      </ConversionRateResponse>
   </soap:Body>
</soap:Envelope>

You can see the results in between ConversionRateResult tags it is 210.6568 now.

Add Assertions

Our test step is done now. But how we can verify whether this s correct out put or not while we’re running on this test? To do that we need assertions

Click on the Assertion tab on the bottom

Screen Shot 2015-08-16 at 2.48.17 PM

It will expand the assertion pane . Then click on the “Adds an assertion on item” button (shows in following screenshot)

Screen Shot 2015-08-16 at 2.48.32 PM

It opens Add Assertion window and you can add Assertions by selecting assertions in there.

Screen Shot 2015-08-16 at 2.48.52 PM

We will see how to use assertions and how to test a test case/ test suite on next posts. 🙂


If you have any comment/ suggestions please comment below. We need to be improve with your ideas and suggestions. See you soon folks 🙂

Introduction to Web Services

Hola Testors!

I think to start my first blog post with web services testing which I’m currently doing 😉

So first we need to understand what is a web service. Ya In today most of developers are using this web services or APIs to build web applications. For mobile they use mobile SDKs. It is actually like a library which we can use their methods.

Today when you are developing an application you do not need to build it from the scratch. There are lots of ready made services available which you can directly plug in to your application and deal with those values. For example think you need to build an application which use to display currency exchange rate from one currency to another one. You can use a web service to get the exchange value. And some organizations builds their own APIs for the applications. Some organizations allows to public (developers) to use their APIs (eg: google map).

So if you wants to memorize what is web service;

Web Services is the mechanism or the medium of communication through which two applications / machines will exchange the data irrespective of their underline architecture and the technology.

Web service can implement in different ways, but there are two popular ways among other methods. Those are;

  1. SOAP (Simple Object Access Protocol)
  2. REST (REpresentational State Transfer architecture)

 

SOAP

SOAP is the standard protocol defined by W3C standard for sending and receiving web service request and response. SOAP uses the XML format to send and receive the request and hence the data is platform independent data. SOAP messages are exchanged between the provider applications and receiving application within the SOAP envelops. And it uses HTTP protocol.

 

REST

REST  is an architecture that generally runs over HTTP. REST is an alternative to SOAP and instead of using XML for request REST uses simple URL in some cases. Unlike SOAP, RESTFUL applications uses HTTP build in headers to carry meta-information. All API request parameters and method parameters can be sent via either POST or GET variables.

REST API supports both XML and JSON format. It is usually preferred for mobile and web apps as it makes app work faster and smoother. REST returns some HTTP code values to user to understand the nature of response.

HTTP Code Meaning Description
1xx Informational Request received and continuing process
2xx Success Action was success
3xx Redirection Further actions must be taken in order to complete the request
4xx Client Error Request contain bad syntax/ cannot fulfill the request
5xx Server Error Server unable to fulfill the request

 

WSDL

WSDL (Web Services Description Language) is an XML based language which will be used to describe the services offered by a web service. WSDL describes all the operations offered by the particular web service in the XML format. It also defines how the services can be called.

 

Web Service Testing

In order to do a web service testing for a particular web service you need to know 5 things

  • Understanding of the WSDL file
  • Understanding the operation that particular web service do
  • Understanding of the request XML format
  • Understanding of the response XML format
  • Using an appropriate tool for test

For the last point we can use SoapUI which we will discuss about in near future 😉


 

I hope by reading this post you will get some understand about what is web service and why we are using it. In next couple of posts I hope to explain about how to do a web service test with SoapUI with example. Please if you have any comments or suggestions please throw to me. I like to improve it with your suggestions and ideas. See you soon!

 

Hola Testors!

 

Hola Folks!

This is the beginning of “El Testor”. The blog for Software QA Engineering from the beginning. You can give us comments/ ideas how we can improve or any areas/ subject you would like to learn. We would like to start with basic Software QA principles and then we would like to talk about Automation, Performance, Mobile testing with guidance. Hope you will be with us.

See you soon with our first article…!