Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Wednesday, November 23, 2011

JMeter - Superb Performance Test Tool

I have been working with JMeter from early days of JMeter 1.9 to date which is JMeter 2.5
Seen the tool evolve from just 4 samplers to a few listeners & much more flexbility now.

Apache JMeter is open source software, a 100% pure Java desktop application designed to (load) test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

Web Site: http://jakarta.apache.org/jmeter/index.html

License & Pricing: Open Source

Support: User mailing list (jmeter-user@jakarta.apache.org)

What can I do with it?
Apache JMeter may be used to test functional and performance both on static and dynamic resources (files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers and more). It can be used to simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types. You can also use it perform a functional test on websites, databases, LDAPs, webservices etc.

JMeter is not a browser. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc, but the timings are not included in any samples, and only one sample in one thread is ever viewed at a time).


The installation of JMeter (if you would call it an installation) is pretty straight forward. On the website is a link to the download area of stable versions. You also have the possibility to use nightly builds, but this is at your own risk. No guarantee that they work properly. So the advice is always to start with a stable version.

Download the latest version (zip or tgz) and unpack the archive to a local folder. Before starting JMeter it is wise to have a look at the configuration. The jmeter.properties file (located in the bin folder) contains a lot of settings. Most of those settings should be fine for the average user. The file is well documented and easy to read (and change where needed).

Also pay attention to needed additional jars. If you are going to use for example JDBC, JMS or JavaMail additional jars are not included in the JMeter installation. The user guide on the website explains how to use it and where to get it.

Starting JMeter is just a matter of double clicking jmeter.bat in the bin folder.


There is an extensive documentation on the web site. In all kinds of ways. User manual, Wikis, docs and user experiences. The user manual describes how to create specific testplans (Web, Database, JMS, Webservice, etc) including step by step instructions, examples, bitmaps and tips. Also additional information is described in the user manual like best practices, information about regular expressions and how to use the variables and predefined functions. And last but not least: the component reference describes in detail how every component can be used.

The principle of JMeter

The principle of JMeter is very simple. If you want to test e.g. a SOAP interface layer, all you basically need is the URL and SOAP request. Starting with that you can build your test plan. And this can be as fancy as you want. Using variables, counters, parameters, CSV files, loops, logs, etc. There are almost no limits in designing your test and making it as maintainable as possible. automationwithselenium.blogspot.com-Google pagerank and Worth

Monday, February 28, 2011

How to configure/change running other than on default port

Pogrammatically changing the default port.

RemoteControlConfiguration class which is contained in selenium-server.jar:

import org.openqa.selenium.server.RemoteControlConfiguration;


public void remoteControlConfigExample()
final int SELENIUM_PORT = 8888;
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
SeleniumServer seleniumServer=null;
seleniumServer = new SeleniumServer(rcConfig);
} catch (Exception e)
Selenium selenium=null;
selenium = new DefaultSelenium("localhost", SELENIUM_PORT, "*firefox","http://www.google.com");
//Add your piece of actions here & then followed by
} automationwithselenium.blogspot.com-Google pagerank and Worth

Saturday, February 26, 2011

Selenium RC UI Mapping

Why should we map the Elements or identifiers or locators in UI?

Imagine that if you have a case with hundreds of input in login field. Now the login text box has been changed to drop down list or the name of the identifier has been changed from Textbox_Login to txt_login.

If we execute our existing test scripts they will fail as they cannot find the locator and making changes in all scripts that involve would be hard.

Hence we map the UI objects & store them in a centralized location for making the script more efficient and maintainable.

So we create a Properties file where we store all the UI objects identifiers & for any further changes we can just tweak this properties file as against all testscripts.

Create the properties file :

Create a file like resLogin.properties and we can assign the UI element as follows:

resuser.firstname = "ctl00_txtFirstName";
resuser.middlename = "ctl00_txtMiddleName";
resuser.lastname = "ctl00_txtLastName";
resuser.loginname = "ctl00_txtLoginName";
resuser.password = "ctl00_txtPassword";

All you have to do now is make a call in your selenium scripts.

For ex :

selenium.type("resuser.middlename"," ");

In the above example for any identifiers being changed you have to make changes in the properties file & replace the one highlighted. automationwithselenium.blogspot.com-Google pagerank and Worth

Types of Framework

Any framework is made up of a number of reusable modules & function libraries that are developed with the following characteristics in mind:


Frame work has several types and most popular are the below :

a.Keyword driven frame work
b.Data driven driven frame work
c.Hybrid framework

Key word Driven Frame work :

Keyword driven framework is an action based test method used in planing and implementation of automation.

Data Driven Framework :

Data driven is the design of possible inputs what may be given by the end user.
This would cover maximum probabilities of an input data.
It can either be Spread sheet(excel)/sql/CSV.
We have to connect and pass the values to the respective field or element.
The data should be designed by the experienced person on the project. It may be a client or even non technical person but should be more familiar from an end users prospective.
We have to map the file path properly.

Hybrid Framework:

The Hybrid Automation Framework is otherwise referred to in the industry as a "Hybrid Keyword Data Driven Automation Framework". automationwithselenium.blogspot.com-Google pagerank and Worth

Strategy to setup Selenium Framework Design

Its alwayz important to set the ground rules straight & think through these factors for designing a framework:

These are my views which has worked well in my past experience.

1. We need to create UI Map.

2. Libraries for UI objects.

3. Design classes based on application under test.

4. Plan for test execution approach to minimize the time.

5. Design report generation.

6. Prepare a Step table and step suite.

7. Prepare a Data set where ever needed.

8. Design Keyword Driven action fixtures this is purely on the approach we follow if its data driven framework ignore this step.

9. Design and develop the psudo code. automationwithselenium.blogspot.com-Google pagerank and Worth

Generate JUnit report with Ant & Eclipse IDE

Reports are crucial for any tests carried out.

Steps to configure and generate the test result from java eclipse using Ant:

this post is for users who have already familiar with java and eclipse.

Generating the ANT build:
Right click on the project and
select Export --> Ant Buildfiles.-->Next-->Select the project-->Finish.

Configuring jar:

Select Windows menu-->Preference -->Global Entries -->Add External JARs-->Select the folder where the eclipse is installed. eclipse -->Plugin -->Currently its located in "org.junit_4.8.1.v4_8_1_v20100427-1100"-->"junit.jar"-->OK.

Run the Ant Build:

Create a folder "junit" in side the project folder.

Right click on the AntBuildfile-->RunAs -->AntBuild

Return to java project and run as junit test.

End of test run you will find the test result in a html file named as index.html it will be stored inside the junit folder.
automationwithselenium.blogspot.com-Google pagerank and Worth

How to does selenium work with Tabbing

Key Press and Fire Event
Imagine that if you have a function in your application that can be invoked by pressing the "Tab" key.

Eg. Values being populated on focus out.

We can use keyPress with ASCII value for the key which you want to trigger the function.

Command Target Value
keyPress Txt_Login \9

here "\9" is ascii value of horizontal tab.

Some functions may be used Onblur. It will trigger the function when the field looses the key focus.

We can use fireEvent with "blur" or "focus" command as follows:

Command Target Value
fireEvent Txt_Login blur automationwithselenium.blogspot.com-Google pagerank and Worth

Tuesday, February 22, 2011

Xpath tips !!!

Get All elements :

// Get all elements where pet equals cat
String xpath = "//*[@pet='cat']";

// Get all elements where pet contains the string dog
xpath = "//*[contains(@pet,'dog')]";
// Get all elements that have the age attribute
xpath = "//*[@age]"; 

Absolute path (would break if the HTML was changed only slightly) - xpath=/html/body/form[1]

First form element in the HTML - //form[1]

The form element with attribute named ‘id’ and the value ‘loginForm’ - xpath=//form[@id='loginForm']

First input element with attribute named ‘name’ and the value ‘username’ - //input[@name='username']

First input child element of the form element with attribute named ‘id’ and the value ‘loginForm’ - //form[@id='loginForm']/input[1]

Input with attribute named ‘name’ and the value ‘continue’ and attribute named ‘type’ and the value ‘button’ - //input[@name='continue'][@type='button']

Fourth input child element of the form element with attribute named ‘id’ and value ‘loginForm’ - //form[@id='loginForm']/input[4]
automationwithselenium.blogspot.com-Google pagerank and Worth

Monday, February 21, 2011

How to do a DDT having a Db connection in selenium

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
import java.sql.*;
import javax.sql.*;
import java.io.*;
public class contact extends SeleneseTestCase

public void setUp() throws Exception
// add details of browser & other details

public void testContact() throws Exception {
System.out.println("Connecting to the database");
String url="jdbc:mysql://localhost:/main.jsp";
Class driverClass = Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection(url,"", "");
System.out.println("Connected to the database");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp_account");
ResultSetMetaData rsmd = rs.getMetaData();
int columns = rsmd.getColumnCount
while (rs.next())
for (int i = 1; i < columns; i++)
System.out.print(rs.getObject(i + 1)+" |");
System.out.println(" ");
automationwithselenium.blogspot.com-Google pagerank and Worth