Sunday, 25 August 2013

HP QTP versus Selenium : Bird eye comparison

This article demonstrates bird eye comparison between HP QuickTest Professional and Selenium. These are popular test automation tool, specially, for functional & regression testing. Purpose of this comparison is not to say which is better tool, it consists of comparison of tool based on different criteria like supported O/S, browser, object spy, object repository, license cost etc. This article is targeted for readers having prior working knowledge of automation approach & at-least one automation tool. Quick overview of tools is as follows –

HP QuickTest Professional is a graphical user tool & provides solution for functional test and regression test automation. This next-generation automated testing solution deploys the concept of keyword-driven testing to enhance test creation and maintenance. QuickTest Professional meets the needs of both technical and non-technical users. It works hand-in-hand with HP Business Process Testing to bring non-technical subject matter experts into the quality process in a meaningful way. Plus, it empowers the entire testing team to create sophisticated test suites. QTP users don’t enjoy a freedom of scripting language like their counterparts using Selenium. It supports only VB Script.

QTP supports the following environments
·        Active X
·        Delphi
·        Java
·        .Net
·        Oracle
·        People Soft
·        Power Builder
·        SAP
·        Siebel
·        Stingray
·        Terminal Emulator
·        Visual Basic
·        Visual Age
·        Web
·        Web Services

Selenium is a family of tools, comprised of multiple software components, used only for automating web based application, they are as follows –

Selenium 2 or Selenium WebDriver –It is a product of merger between Selenium & WebDriver.  It supports the WebDriver API, along with the Selenium 1 technology. WebDriver is a tool for writing automated tests of web based applications. It aims to emulate the behavior of a real user, and as such interacts with the HTML of the application. It provides object oriented support & WebDriver API. This is latest/ newest addition in Selenium family.

Selenium 1  or Selenium RC or Remote Control -  It allows to write automated web application UI tests in any programming language (Java, JavaScript, Ruby, PHP, Python, Perl and C#) against any HTTP website using any mainstream JavaScript-enabled browser. It comes in two parts. 
  •      A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them.
  •       Client libraries for your favorite computer language.

It is suitable for testing complex AJAX-based web user. It is also an ideal solution for users of Selenium IDE who want to write tests in a more expressive programming language than the Selenese HTML table format.

Selenium IDE - Selenium IDE (Integrated Development Environment) is a rapid prototyping tool for building test scripts. It is a Firefox plugin and provides an easy-to-use interface for developing automated tests. Selenium IDE has a recording feature, which records user actions as they are performed and then exports them as a reusable script in one of many programming languages that can be later executed.

It is not designed to run your test passes nor is it designed to build all the automated tests you will need. It doesn’t provide iteration or conditional statements. It is recommended that for scalable & robust test automation use Selenium 2 or Selenium RC.

Selenium-Grid - Selenium-Grid facilitates to run test suites in multiple environments simultaneously. It allows executing tests in parallel, that is, same or different tests can be run at the same time on different remote machines. It benefits in following ways –

1.  Suppose there is a large test suite, or a slow-running test suite, you can boost its performance substantially by using Selenium Grid to divide your test suite to run different tests at the same time using different machines.
2.  Suppose requirement is to run test suite on multiple environments, you can have different remote machines supporting and running your tests in them at the same time.

QTP is a proprietary, licensed software and comes in following type of license -

1.  Seat License: It is a machine locked license. This license can be used only for a machine it was generated.
2.  Floating License: It can be used on any machine which has network access to the floating license server. At any point in time the machines using the QTP license cannot exceed maximum license count on the server.

Selenium is an open source tool that doesn’t cost anything. Anybody can download selenium library, plug-in  & start using it. There is no limitation on number of license use & usage time.

Object Spy
QTP Object Spy helps to view properties & supported method of an object in an open application. Selenium IDE object locator provides feature to view objects properties & method. Apart from this, an user can use add-in Firebug with Firefox and Chrome built in development tool bar to view object properties & test element locator.

Code Debug
QTP has built-in editor to debug code. Selenium does not have built-in code debugger. It provides plug-in with editors like Intellij, Eclipse, Visual Studio. User needs to learn these editors to perform code debug.

Exception Handling
QTP provides recovery scenario to handle exception during script execution. Selenium does not provide recovery scenario. User needs to write custom function to handle run-time exception.

QTP generates nice test reports (html, XML, pdf etc) using built-in reporter object. Selenium does not have built-in reporting feature. It is dependent on framework like TestNG, Junit, SauceLab, Testing bot for test reporting.

Integration with Test Management Tool
QTP comes bundled with test management & source code control tool Quality Center. Selenium offers no test management tool. There are few options like xStudio, but user needs to explore.

It provides screenshot feature to take picture during test execution of exception & error. No screenshot feature in Selenium.

Resource Availability
It is quite easy to find engineers having expertise on QTP. Selenium resources are bit scarce.  
Ease of Use
QTP is very user friendly can be used by less code-savvy people, online help is easily available. Selenium requires good coders for writing and maintaining the tests.

Browser Support
QTP provides full support for IE; limited feature support for Firefox & Chrome (requires installing patch), Selenium supports almost all browsers, list is as follows -
  •         Firefox 2 to 17
  •         IE  7,8,9
  •         Safari 2,3,4
  •         Opera 8,9,10
  •         Google Chrome

O/S Support

QTP supports only Windows platform. Selenium supports Windows, Linux and Mac.

QTP Best Practices

HP Quick Test Professional is a test automation tool, also known as QTP. It is used to automate functional, regression & smoke test cases. It is a very popular tool and works on MS windows O/S, supports development technologies like Active X, Delphi, Java, .Net, Oracle, People Soft, web, Web services etc. This article discusses about best practices while doing automation using QTP.
  1.     Don’t use msgbox function, this function pauses the script execution & requires user intervention. This defeats the objective of unattended script execution. To store or display error message and execution log use QTP inbuilt Reporter object.
  2.       Follow coding guidelines like comments, variable & function name declaration.
  3.       Use option explicit to enforce variable declaration. Always define variables at the top of script & function file
  4.       Neither hard code test data nor read value using custom function like Inputbox. Use parameterization to enhance reusability of code. QTP provides inbuilt support for Microsoft excel files, store test data in excel file, import excel sheet in QTP DataTable, read value using “DataTable.value” function
  5.       In large tests, define reusable codes as function in external .vbs file. It consumes less memory than QTP Action.
  6.       QTP is a hardware hungry application, machine should be hardware rich.
  7.       Use synchronization (like exist, sync etc.) to mitigate timing issue between script & Application under test. Don’t use wait (10) statement. Don’t increase global synchronization time out value; it slows down QTP execution speed.  Ideal solution is implement synchronization at object level not at global level.
  8.       Create reusable function instead of reusable action; minimize number of actions in a test. Ideally, a test should not contain more than few actions. An action takes more time to load and run. Its limited use improves execution speed.
  9.       Be tactful in using QTP features like Descriptive Programming or Object Repository or mixed approach. Each approach has its own merit & demerit. Try to use mix of both.
  10. .   Don’t use inbuilt feature like “Save still image capture to results” and “Save movie to results”. These options decrease QTP run time performance. If required, use VB Script code to take screenshot of script failure.
  11.     User relative paths while calling library file, reusable action, data files. It makes script portable and easy to manage.
  12. .    Don’t overuse recovery scenario, recovery scenario slow down script execution time
  13. .   Do not load un-necessary Add-ins. When QTP starts, it shows list of add-in available, select only required add-in. This will improve performance while learning objects and during run sessions.
  14. .    Run your tests in "Fast mode. From the Run pane in the Options dialog box, select the Fast option. This enables QuickTest, run test faster.
  15.   .  Hide Active Screen. If you are not using the Active Screen while editing your test, hide the Active Screen while editing your test to improve editing response time.
  16.    Save the test results report to a temporary folder to overwrite the results from the previous run session every time you run a test. 

Friday, 23 August 2013

Selenium WebDriver Configuration Maven/Eclipse/Java

  1. Create a folder [POMFOLDER] to contain your Selenium project files, within this folder create a file [pom.xml] file & Paste following code in it.
  1. Type “Download Eclipse” on or go to URL - downloads/ & download Eclipse Classic 3.7.1. Unzip file. Create a shortcut of “eclipse.exe”, right click on “Shortcut to eclipse.exe” icon & click on properties. In Target field append value [ -vm "C:\Program Files\Java\jdk1.7.0_02\bin\javaw" -vmargs -Xms256m -Xmx768m -XX:PermSize=256M -XX:MaxPermSize=512M ].
  2. Download [jdk1.7.0_02] & install it.
  3. Download [] & unzip it. Open Readme.txt and follow the steps to install maven.
  4. Go to Environment Variables [My Computer -> Properties -> Advance -> Environment Variables -> System Variable, update/create following variables -
                JAVA_HOME = C:\Program Files\Java\jdk1.6.0_25 ‘path of JDK
                PATH=C:\SeleniumProject\apache-maven-3.0.4\bin;%PATH% ‘path of                               Maven Folder
                CLASSPATH= %JAVA_HOME%\lib ‘Path of JDK Library folder
                M2_HOME = C:\SeleniumProject\apache-maven-3.0.4 ‘Path of Maven

  1. Open Command prompt (Start -> Run -> CMD), type mvn clean install. It takes 5-10 minutes to install, check for [build successful] message at the end of deployment.
     7.   Go the folder where you had created pom.xml file (Refer Step 1) & type mvn ec             lipse:eclipse -DdownloadSources=true  -DdownloadJavadocs=true.  It 
           takes 5-10 minutes to install, check for [build successful] message at the end of 
  1. Open Eclipse by clicking on [Shortcut to eclipse.exe], Go to [File -> Import -> General -> Existing Projects into Workspace], click on [Next] button, Click on [Browse] button & select folder [POMFOLDER] (refer step 1).
  2. Under [Eclipse -> Project Explorer] tab Maven project [MySel20Proj] is displayed.
  3. Go to [Help -> Install New Software] & Enter URL - & click on [Next -> Finish] button, Eclipse prompts for restart, restart it.
  4. Create a [Source Folder] (Right click on MySel20Proj, go to New & click on Source Folder)
  5. Create a Class File (Right click on Source Folder, go to New & click on Class). New Java Class wizard get opened, enter class name, select checkbox for public static void main (String[] args) & click on Finish button.
  6. You are ready to write first selenium program, paste following code within public static void main function –
                                       WebDriverdriver = new FirefoxDriver();


  1. Click on Crtl+F11, Firefox browser gets opened & URL is displayed.

Selenium WebDriver :- What are Drivers for Firefox, IE, Chrome, Opera, Safari

List of Driver for Firefox, Chrome, Opera and Safari browser are as follows -

Name of Driver Server
Driver Server is not required
Driver Server is not required
Internet Explorer
Internet Explorer Driver Server
Available in 32 and 64-bit versions

 It is another headless browser just like HTMLUnit.

Selenium WebDriver : - How to capture screenshot

#SeleniumWebDriver  #TakeScreenshot #TheBuddhaTree

The Problem
When we do nightly test execution, we need historical evidence to analyze & debug script failure. Sometime, it can be challenging to track down the issue that caused a failure using failure message along with stack trace. Especially when you run the test again and it passes.

A Solution
A simple way to gain insight into your test failures is to capture screenshots of AUT at the moment of failure and add the screenshots into test execution result. 

How to Implement using Selenium
Selenium WebDriver provides the TakesScreenshot interface for capturing a screenshot of a web page. This helps in test runs, showing exactly what happened when an exception or error occurred during execution, and so on.

TakesScreenshot interface provides the getScreenshotAs() method to capture a screenshot of the page displayed in the driver instance.  Example code is as follows –


import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class TakeScreenshotOfApplication {
                WebDriver driver;

       public void compareTitle() {
              driver = new FirefoxDriver();


            // compare title & take screenshot of application if it fails
       if (driver.getTitle().contains("facebook")) {
                 System.out.println("Title matched!!");
       } else {
                 System.out.println("Title did not match");

        private void takeScreenshotMethod() {
             // code to take screen shot of browser
            File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

             // file name where image to be saved
             String screenshotpath = "C:\\google.png";
               try {
                       // save image to drive
                        FileUtils.copyFile(scrFile, new File(screenshotpath));
               } catch (IOException e) {


Expected Behavior
  1. Load the URL
  2. Take Screenshot
  3. Save Screenshot Image to local drive
Happy Learning

Selenium : Read Excel file using JExcel API

Code to read  value from Excel file using selenium WebDriver & Java is as follows -

inputWorkbook = new File("C:\\Controller.xls"); //specify excel file path

    Workbook w;
    try {
            try {

                        w = Workbook.getWorkbook(inputWorkbook);

                        sheet = w.getSheet("Sheet1"); //Worksheet name

                        } catch (IOException e) {
                                    error("Reading Master Sheet :-" +e);
                        suite = new String[sheet.getRows()][sheet.getColumns()];
                        for (int j = 0; j < sheet.getColumns(); j++){
                                    for (int i = 0; i < sheet.getRows(); i++){
                                                Cell cell = sheet.getCell(j, i);
                                                if (cell.getContents()!= null){
Note – Suite[][] is two dimensional array which stores value read from Excel Worksheet.