Wednesday, 7 May 2014

Loop Controller and Counter in JMeter

By the end of this post you will be able to add a Loop Controller and Counter to your script which will loop a request n no of times.

Loop Controller
Loop Controller is a Logic Controller which determines the order in which Samplers are processed.You can use Loop Controller, if you want to loop a request/logic a certain number of times in addition to the loop value specified for the Thread Group.

Counter
Counter can be used anywhere in the Thread Group. User can set a start point, maximum value of counter and the increment using counter config.Counter will start from start point and reach the maximum value and then reset back to the start value, it will continue like that until the test is ended.

Example:
We will loop a request 10 times using Loop Controller. And we will set Counter values start with 1, Increment by 1 and reach Maximum 10.
So JMeter will send 10 request with counter values 1 to 10 as shown below in results.
Please follow below steps to add loop Controller and counter.

Add Components:
  1. Add Loop Controller to Thread Group
    Right click on Thread Group > Add > Logic Controller > add Loop Controller.


  2. Add Counter to Loop Controller
    Right click on Loop Controller > Add > Config Element > add Counter


  3. Add HTTP Request Sampler to Loop Controller
    Right click on Thread Group > Add > Sampler > HTTP Request


  4. Add View Results Tree to Thread Group
    Right click on Thread Group > Add > Listener > add View Results Tree


Loop Controller:
Using Loop Controller, JMeter will loop through a certain number of times, in addition to the loop value you specified for the Thread Group.
Set Loop counters value to 10



Counter:
The counter configuration lets the user configure a starting point, a maximum, and the increment. The counter will loop from the start to the max, and then start over with the start, continuing on like that until the test is ended.
Set Values:

Start: 1, Increment: 1, Maximum: 10, Format: 00, Reference Name: Count


Note: If the counter exceeds the maximum, then it is reset to the Start value. If your loop count is 10 and maximum value is 5, then you will get output 1,2,3,4,5,1,2,3,4,5

HTTP Request Sampler:
Change request name to say: Counter value - ${Count}
Set Server Name: google.com


Save and Run Script:
Save the above script and Select "View Results Tree" and click on "Start"


Results:



Tuesday, 6 May 2014

Record and Play script in JMeter

By the end of this post you will be able to record and Play script in JMeter.  So for recoding we have to do the following:

Add Components:
1. Add Thread Group to Test Plan
    Right click on Test Plan > Add > Threads (Users) > add Thread Group


2. Add Logic Controller to Thread Group
    Right click on Thread Group > Add > Logic Controller > add Recording Controller


3. Add View Results Tree to Thread Group
    Right click on Thread Group > Add > Listener > add View Results Tree


4. Add Script Recorder to Workbench
    Right click on Workbench > Add > Non-Test Elements > add HTTP(S) Test Script Recorder


Browser Proxy Settings:
We need to configure browser to use Proxy, so that JMeter Test Script Recorder can record the events happening on browser. For Firefox

Menu > Options > Advanced (Network tab) > Settings (under Connections)
  •        Select “Manual proxy configuration”
  • ·         HTTP Proxy: localhost and Port: 8080 
  •       Select check-box “Use this proxy server for all protocols



Start Proxy Server on Port 8080:
Start HTTP(S) Test Script Recorder



As we start Script recorder a dialog with Root CA certificate message will appear.
Click OK.


Browse to record the event

 Open up your browser (Firefox, where the proxy is configured),
Open the URL say (www.google.com) you want to record, if you get “Connection Untrusted” message then do the following:

 


Visit the necessary links and do the required actions, all actions will be recorded under 'Recording Controller' node of 'Thread Group'.


Stop the Script recorder


Finally Save your TestPlan.

Play the recorded script
      
      Now select the “View Results tree” and click on Start icon in green to play the recorded script (Ctrl+R)
  
      If test run successfully you will see all executed requests in Green.


Run JMeter – GUI Mode | Server Mode| Non GUI


We can run JMeter in 3 modes:
  • GUI Mode
  • Server Mode
  • NON GUI or command line mode

GUI Mode:
Run JMeter in GUI mode by running the JMETER_HOME/bin/jmeter.bat


GUI appearance

Server Mode
This mode is used to for distributed testing; it follows client-server architecture
Client - the system running Jmeter GUI, which controls the test
Server – the system running jmeter-server, which takes commands from the GUI and send requests to
the target system(s)
Target– the webserver we plan to Stress/Load test

We can start the JMeter server component by running the JMETER_HOME/bin/jmeter-server (unix) or JMETER_HOME/bin/jmeter-server.bat (windows)


NON GUI - Command line mode
We can run JMeter in command line mode as:

  • Open command prompt
  • Navigate to JMETER_HOME/bin directory
  • Run the following cmd

jmeter -n -t scriptname.jmx -l filename.jtl

-n, --nongui (run JMeter in nongui mode)
-t, --testfile <argument> (the jmeter test(.jmx) file to run)
-l, --logfile <argument> (the file to log samples to)


Install JMeter | Setup JMeter | Configure JMeter


By the end of this post, you will be able to install/configure and run JMeter on your system.
Jmeter is Java application and it should run on any system that has a compatible Java implementation.

Pre-requisites:
Java must be installed to run JMeter

Java:
Download and Install latest JRE (Java Runtime Environment) from Oracle



Download JMeter:
Download the latest version of JMeter from Apache, download .zip file (apache-jmeter-2.11.zip)



Install JMeter:
To install JMeter, unzip the .zip file into the directory where you want JMeter to be installed. After unzipping, installation directory structure should look like as shown below.


Run JMeter:
To run JMeter in GUI mode navigate to the JMeter installation directory/bin and run jmeter.bat