Monday, December 19, 2011

JMeter Plugins - JMeterPlugin-0.4.2

Introduction:

During a load test, it is important to know the health of the servers loaded. It is also nice to see if you are targeting a cluster if the load is correctly dispatched. To address this, the plugin package now supports server monitoring! Using it, you can monitor CPU, Memory, Swap, Disks I/O and Networks I/O on almost all platforms!
Download Link : http://code.google.com/p/jmeter-plugins/downloads/detail?name=JMeterPlugins-0.4.2.zip

The prerequisite is to run JMeter 2.4 or above with a JRE 1.6 or above.

Installation :
First of all, download the latest version of plugins.

To install the JMeter Plugins, you simply have to copy the JMeterPlugins.jar file from JMeterPlugins-VERSION.zip inside JMETER_INSTALL_DIR/lib/ext. Now you can restart your JMeter and see jp@gc-prefixed plugins in menus.

Metrics Collected:
This is the description of the metrics the plugin is collecting.



CPU:
This graph displays the CPU usage in percent. Multi core / Multi processors are suported, but the value displayed will aggregate them.
Memory:
            This graph displays the memory used in MB. The value is calculated with this formula: <total bytes>/(1024 x 1024)





Sunday, December 18, 2011

Parameterization Using User Variables

Now we will learn how to parameterize the values using User Variables.
For this parameterization also we will use a public site as an example i.e. www.redbus.in.
Follow the following steps :
To Parameterize the Booking scenario, first record the Booking scenario.
1] Add Thread Group Recording Controller and HTTP Request.
            In HTTP Request > Server Name or IP : Enter http://www.redbus.in
2] Add a HTTP Proxy Server for the Workbench
3] Start the Proxy Server and open Mozilla Firefox and go to http://www.redbus.in.
4] After recording a few transactions, close the browser and stop the Proxy server in Jmeter. U get the below recordings.
5] Here we have seen the tickets from Mumbai to Goa on 07-Dec-2011
6] Now we will parameterize the values of fromCityName and toCityName using User Parameters.

For this do the following steps:

7] After recording the script first save it.
8] Create a new file in “text document” form in bin folder.
9] Enter the values for each thread or user in separate rows with fields separated by commas as shown in the screen shot.
10] Save the file as (file => save as) uservar.csv file in the same bin folder.
11] Now in the Apache_Jmeter   window go to Options > Function Helper Dialog
12] Create new function with function type __CSVRead.
13] In the values column for CSV file to get values from give the file name (i.e. uservar.csv) from where values are retrieved. Give the complete path incase the file is not created in bin folder. In Column number of CSV file give 0 as user ids are stored in first column and count will be started from “0”.
14] Then click on generate option to generate a function. Then copy the function string generated.

15] Now again goto Apache_Jmeter window.
Right click on thread group.
Then click on Add > Pre Processor > User Parameters to create a new userparameter.
16] The following window will be opened. Click on Add Variable tab to add a new variable.

17] Now in the name column give the name of the variable you want to replace (fromCityName) as “A” in this example and in the user_1 column paste the function string that was copied previously from the function helper window i.e., (${__CSVRead (uservar.csv, 0)}).

18] To parameterize more than one more variable then click on Add Variable. For parameterizing toCityName filed in Name field enter “B” and in User_1 column paste the generated function but change the column number to 1 i.e.,(${__CSVRead (uservar.csv,1)}).

19] After entering all the values that are to be parameterized click on Add Variable and in Name field enter “next” and in the User_1 column paste the function string and replace 0 in the string with next i.e.(${__CSVRead (testdoc.csv, next)}).
20] Find and replace the variable values that are to be parameterized with function strings.

In this example find fromCityName value and replace it with the function string that is ${A} and find toCityName value and replace It with function string ${B}.
21] Save the script and Run the Test.
22] See and Check the results with new modifications.

Tuesday, December 6, 2011

Parameterization using CSV data set Config

Now we will learn how to parameterize the values using CSV data set Config.
For parameterization also we will use a public site as an example i.e. www.redbus.in.
Follow the following steps : 

1] Add Thread Group Recording Controller and HTTP Request.

            In HTTP Request > Server Name or IP : Enter http://www.redbus.in

2] Add a HTTP Proxy Server for the Workbench
3] Start the Proxy Server and open Mozilla Firefox and go to http://www.redbus.in.

4] After recording a few transactions, close the browser and stop the Proxy server in Jmeter. U get the below recordings.
5] Here we have seen the tickets from Mumbai to Goa on 07-Dec-2011
6] Now we will parameterize the destination Mumbai to Goa, Bangalore, Chennai and Delhi.

Now add a CSV Data set Config and a Listener element to the thread group.

7] Add->Config Element->CSV Data Set Config

8] Add->Listener->View Results Tree
9] Now open a notepad (inside bin) and enter your keywords.

10] Save the file as tocity.csv. The extension csv makes it a comma separated Value (CSV) file.
11] Now select the CSV Data set Config element and fill in the fields as follows
          Filename: tocity.csv
(Give the path name if you have put it inside a subfolder e.g. foldername\tocity.csv)
           Variable Names: A
(This variable name is referenced in the search sample.)
Delimiter: ,

12] Now go to the Booking/select bus.aspx and change the value of variable toCityName to ${A}.In Jmeter we reference a variable using ${} .For each iteration the value of toCityName will be replaced as fetched by variable A.

We need to do the necessary changes of the value of these variables wherever they are present in recorded script.
13] Now go to thread group and make the number of threads (users) to 4.

14] Save the script and Run the script (ctrl + R).

15] See the Results, Check the Destination Places.





This is how parameterization is done. Hope it helps you in practicals.

Monday, December 5, 2011

What is Parameterization and how it is done...



Parameters can be set at both the Test Plan and Thread Group levels.

At the Test Plan level, parameters can be used as constants to minimize changes throughout the test plan when a server or port changes.
Within Thread Groups, the User Parameters Pre-Processor can be used to set different parameters for each simulated user.


Parameterization can be done in two ways.

1)                      Using CSV data set config:
 The CSV Dataset module allows data to be stored in a CSV file on disk. This is read in at runtime and the data is available in variables in the test plan. This makes it easy to change the data "behind" the test application. By keeping the tests generic to the software and the actual info about the data being tested in CSV files, these CSV files can be easily replaced to use a another application dataset. Using sets of CSV files, we can then have test for variations of data, such as production, test or development.

2)                      Using User Parameters:
This allows specifying values for User Variables specific to individual threads.

User Variables can also be specified in the Test Plan but not specific to individual threads. This panel allows you to specify a series of values for any User Variable. For each thread, the variable will be assigned one of the values from the series in sequence. If there are more threads than values, the values get re-used. For example, this can be used to assign a distinct user id to be used by each thread. User variables can be referenced in any field of any JMeter Component.

Regular Expression

A regular expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager.

? - Matches zero or one of preceding element
eg.: colou?r  =  color 
                          colour
                          coloour (wrong)

* - Matches zero or more of the preceding elements
eg.: ab*c  =  ac
                     abc
                    abbbc
                    abcdefc

+ - Matches one or more of preceding element
eg.: ab+c  =  abc
                      ac (wrong)
                      abbbc

. - Matches any single character
eg.: .at  =  hat
                  cat
                  bat

[ ] - Matches single character contained within the brackets.
eg.: [hc]  =  hat
                    cat
                    bat (wrong)

[^] - Matches a single character that is not contained within the bracket.
eg.: [^b]at  =  cat
                       hat
                       bat (wrong)

^ - Starting position within the string.

$ - ending position within string.

Thursday, December 1, 2011

Correlation - Regular Expression Extractor

After the script is recorded on replay of the same script correlation problem will occur for most of the webapplications.
1] As we have recorded a script in Recording script post, now run the same script again. It should give you some error i.e. Correlation problem.
2] To resolve this problem we need to correlate the dynamic values sent by the server like EngineID and SessionID in this example.


3] To exactly locate the dynamic values see in the “response code” and “requests” in  the view results tree of the corresponding failing page.
4] Now Create a RegularExpressionExtractor before the failing “http request” i.e.(http://www.irctc.co.in/cgi-bin/bv60.dll/irctc/booking/planner.do)
5] The fields of RegularExpressionExtractor are filled as below:
                ReferenceName: Give variable name that should be given to the dynamic value i.e.,”sessionid”
               Capture the Dynamic value that is to be correlated along with its left and right boundaries.In this example the http request looks like this in the request part of the view results tree of the corresponding failing page.
 https://www.irctc.co.in/cgi-bin/bv60.dll/irctc/booking/planner.do?screen=fromlogin&BV_SessionID=@@@@0584060878.1322216046@@@@&BV_EngineID=cccgadfffemkmldcefecehidfgmdfjm.0

Dynamic Value: @@@@0584060878.1322216046@@@@
Left bound: BV_SessionID=
Right bound: &
We need to replace the dynamic value with a regular expression i.e.,(.+?) in this example.

RegularExpression: BV_SessionID=(.+?)&
Template :Enter $1$
Match No. : Enter 1
Make sure that URL is enabled as the dynamic values are captured from the url part of the request data.
Same procedure is repeated for EngineId also as we have EngineId and SessionId as dynamic values.

ReferenceName: engineid 
Regular Expression: BV_EngineID=(.+) 
Template: $1$ 
matchNo.: 1


6] Now find and search wherever this dynamic values are present and replace the values with the reference variable name.
Now run the script again and see the results in View Result Tree.
In this way we can resolve the problem of Correlation using Regular Expression Extractor in JMeter.


Thanks For Reading...

Recording a Test Plan

In this post we will learn how to record a test plan in JMeter.
Follow the steps below. I have kept it in simple and interactive way, so follow each step following the screen to cross-check with yours.

1] Go to jakarta-jmeter-2.5.1 > bin > ApacheJMeter (Executable Jar File)

                                                                     OR

    Go to jakarta-jmeter-2.5.1 > bin > jmeter.bat (Windows Batch File)
     You will get started to JMeter Screen.

2] Add Thread Group
                        Right Click on Test Plan > Add > Threads (Users) > Thread Group


3] Add HTTP Request to the Thread Group 
            Right Click on Thread Group > Add > Sampler > HTTP Request

            A HTTP Request element will be added below Thread Group in element tree and now Add the Server Name or IP as “ http://www.irctc.co.in



4] Add Recording Controller to the Thread Group
                     Right Click on Thread Group > Add > Logic Controller > Recording Controller


5] Add Proxy Server to the Workbench
                  Right Click on Workbench > Add > Non-test Elements > HTTP Proxy Server


6] On HTTP Proxy Server, click 3 times the “Add” button in “URL Patterns to Exclude”. This will          create 3 blank entries.
                  Enter “.*\.png” pattern, “.*\.gif” pattern and “.*\.ico” pattern


   Add Listener View Results Tree
              Click on Thread Group > Add > Listener > View Results Tree



7] Now Start the HTTP Proxy Server



8] Now go to Mozilla Firefox and type http://www.irctc.co.in



9] Now Login in as a user and do some actions on the Mozilla Firefox and just logout and Stop the recording from proxy server in JMeter and then the recordings would be generated as a script in the JMeter Window.






10] Applying Load :
            Select Thread Group
            Number of threads – enter 5
            Ramp up period – do not change
            Loop count – 5






11] At this point, we are ready to run our test plan and see what happens. But first Save the test   plan. When you're ready to run the test, there's two ways:
            Run menu > Start          OR
            Ctrl + R
While the test is running, in the upper right-hand corner, there should be a green square.
When the test is done, the box should be grey.





12] Now check the results of the script which we just run in the “View Results Tree” element below Thread Group element.





This is the way we record a test plan in JMeter. I hope you will not get any problems in recording if you follow all steps in flow.

Configuring the Browser (Mozilla Firefox)

Now when we all know the basics of JMeter, lets workout with the tool practically and record a test plan.
For recording we will be using any of the public site and a Mozilla Firefox browser.
But before we record we need to configure the browser...
Follow the following steps for configuration:


  • Start Mozilla Firefox
  • From the tool bar, Click Tools > Options
  • An Options window will open.
  • Select “Advanced tab” and “Network tab” from that window.


  • Click on “settings…” button and “connection settings” window will open.
  • On the new popup, check “Manual proxy configuration”. The address and port fields should be enabled now.
  • Address – enter “localhost” or the IP address of your system.
  • Port – enter “8080”.
  • Check “Use this proxy server for all protocols”

  • Click “ok” button
  • Click “ok” button again. This should return you to the browser

Now your browser is capable of recording test plan.
At this point now we are ready to record using Mozilla Firefox browser.
In this way we configure our browser to record with JMeter.

Tuesday, November 29, 2011

Building a Test Plan

Now in this post we will learn how to build a test plan in JMeter, in brief.
This will be just a basic way to build a simple test plan.


Ø      Adding Elements : Right-Click on an element in the tree and choose new element from ‘Add’ list. We can also load elements from a file and add by choosing ‘merge’ or ‘open’ option.

Ø      Removing Elements : Right-Click on the element to be removed and select ‘remove’ option.

Ø      Loading Elements : To load an element from file, right click on the existing tree element to which you want to add the loaded element, and select the "merge" option. Choose the file where your elements are saved &click on ‘Open’ button. JMeter will merge the elements into the tree.

Ø      Saving Elements : Right-Click on the tree elements that you want to save and choose ‘Save Selection As ...’. JMeter will save the element selected, plus all child elements beneath it.

Ø      Configuring Elements : Any element in the test tree will present controls in JMeter's right-hand frame. These controls allow you to configure the behavior of that particular test element.

Ø      Saving the Test Plan : To save the Test Plan, select ‘Save’ or ‘Save Test Plan As ...’ from the File menu.

Ø      Running a Test Plan : To run your test plan, choose ‘Start’ from the ‘Run’ menu item. When JMeter is running, it shows a small green box at the right hand end of the section just under the menu bar. The numbers to the left of the green box are the number of active threads / total number of threads.

 This is the way we basically built a simple test plan in JMeter.
Now work it out on JMeter to know it better.

Monday, November 28, 2011

Elements of JMeter

Now we will learn what are the Elements of JMeter and why they are there in JMeter.


Elements of JMeter:


v     Test Plan
v     Thread Group
v     Controllers & Samplers
v     Listeners
v     Timers
v     Assertions
v     Configuration tool
v     Pre-processor elements
v     Post-processor elements

v     Test Plan describes a series of steps JMeter will execute when run.

v     Thread Group elements are beginning points of any Test Plan. Everything must be under Thread Group.

v     Types of Controllers:-
Ø      Samplers
Ø      Logical Controllers

Ø      Samplers tell JMeter to send a request to a server and wait for response.
                                            e.g. HTTP Request sampler.

Ø      Logical Controllers let you customize the logic that JMeter uses to decide when to send requests.

v     Listeners provide access to the information JMeter gathers about the Test cases while JMeter runs.

Ø      Graph Result Listener plots the response time on graph.
Ø      View Result Tree shows details of sampler request and response.

v     Timers are useful to specify a delay between requests send (to thread group).

v     Assertions allow you to assert facts about responses received from the server being tested. Using Assertion, you can essentially test that the application is giving result that we expect.

v     Configuration element works same as samplers but does not send request. It can modify/add requests.

v     Pre-processor executes some action prior to a sampler request being made.

Post-processor is not often used to process the response data, often to extract values from it.

I hope the above information of the elements is quite enough to start with JMeter.
Now we will get into each element, in depth, later.