Monday, June 22, 2015

Recording in Jmeter using 'Test Script Recorder'

In this post will discuss how to setup and use the Apache JMeter HTTP(S) Test Script Recorder to record HTTP requests. Recording HTTP requests is a great way to building test plans, and can be useful in creating tests that closely mimic a normal user's behavior.

The elements that we need to set this up are:

1. Non- test Elements: HTTP(S) Test Script Recorder.
2. Browser installed in user's system.

First will add "HTTP(S) Test Script Recorder", by right click on 'workbench' then select add and then Non- test Elements: HTTP(S) Test Script Recorder.

Like this:




Now configure it:
a) Enter the site domain or its IP in 'HTTPS Domain' field.
b) Change target controller as "WorkBench>> HTTP(S) Test Script Recorder".

Like this:

Now click on the 'Start' button located at the bottom of 'HTTP(S) Test Script Recorder'.

Open your browser and enter the proxy settings as:
Proxy: localhost
Port: 8080

Click here to check, how to change browser's proxy settings.

Now run the site URL (configured under script recorder) in the browser and perform your steps.

After that view the Jmeter, all the requests are listed under "WorkBench>> HTTP(S) Test Script Recorder".

Like this:



Sunday, June 21, 2015

Import CSV Data in Jmeter

In load testing generally we have flow's in which we have login page. And in case of number of users obviously we need multiple user login credentials.
For this case, Jmeter provides a config element as 'CSV Data Set Config' in which user can pass a file containing different login credentials.

Lets take an example of google search, the scenario is we need to load google search by searching different keywords. Now what we do, will pass a file containing different keywords and pass them to HTTP request.

Open Jmeter and add following elements:
1) Thread Group
2) Config Element: CSV Data Set Config
3) Sampler: HTTP Request
4) Listener: View Result Tree

Your test plan will look like this:


Now configure 'CSV Data Set Config', by adding file path (containing keywords) and set a variable name to it.
Like this:
a) Sample TXT file containing keywords (for now we added only two keywords, you can add more to it).
b) CSV Data Set Config look like this
Now configure Sampler 'HTTP Request'
a) Add domain and pass parameter '#q' that can pick value from txt file, for that will get the value from variable 'keyword' as mentioned in the 'CSV Data Set Config'.
Like this:




Now we have two keywords in our text file so we need to set threads count as '2' in thread group.

Script is ready, save it and run the load.

On completion, you can check the requests under listener ''View Result Tree".

 






Friday, June 19, 2015

Functional Testing Using Jmeter !!

JMeter does not have a built-in browser, unlike many functional-test tools, But it can run the browser and execute the steps.

We can automate the user actions in Jmeter by using sampler named as 'WebDriver Sampler'. Its the addon feature of Jmeter, you need to add jar to Jmeter library.

On adding you will see these new elements in Jmeter:


To add this Sampler, you need to add Jmeter plugin 'WebDriver' to your Jmeter.

You can download plugin from here:

 This plugin also add some config elements, that will help in launching the browser session for your script.

Lets make a simple script and run it using Jmeter.

Open Jmeter and add following elements to it:
1) Thread Group
2) Config Element>> Firefox Driver Config.
3) Sampler>> WebDriver Sampler
4) Listener>> View Result Tree

Like this:


You don't need to configure 'Firefox Driver Config' for this test, will go with its default settings.

Now click 'WebDriver Sampler' and paste below code in it.

WDS.sampleResult.sampleStart()
WDS.browser.get('http://google.com')
WDS.sampleResult.sampleEnd()


Like this:

Your simple script is ready, it will launch firefox and opens google in it.