Jmeter Handout
Jmeter Handout
Installation
• http://demo.kieker-monitoring.net/jpetstore/actions/Catalog.a
ction
• A quick overview
Demonstration of Recording
http://127.0.0.1:1080/WebTours/index.htm
Index.htm
Header.html
welcome.pl?signOff=true
nav.pl?in=home
home.html
Client
• https://www.blazemeter.com/blog/web-testing-jmeter-how-pr
operly-handle-embedded-resources-html-responses/
Recording - Different ways
• Using “HTTP(S) Test Script Recorder”
• Using Bad Boy – No proxy Required
– Bad Boy Download Links (Version 2.2)
– https://badboy1.software.informer.com/download/#downloading
– https://drive.google.com/file/d/1DB0prNuPGfWLbPCytM31CiWHtEiCiUa0/view?usp=sharing
•Stop: Abruptly stop the test that is running on the local machine
•Shutdown: Stop the test gracefully, allowing the threads / Vusers to wind down
Executing in GUI Mode
• Number of Executions: The child elements are executed until the specified count
is reached and the subsequent executions are skipped. To configure this, choose
Total Executions and specify a value for Throughput.
• Percentage of Executions: The concept is the same except that the number of
executions of the child elements is restricted by the percentage configured.
Once Only Controller
• Once Only Controller executes its child elements only once per
thread / VUser.
C:\Users\sree\
Desktop\Random.jmx
If Controller
• The If Controller is useful for decision/branching logic. The
configuration is simple, with only two checkboxes.
• The Evaluate for All Children checkbox indicates whether the
condition should be evaluated before processing each of the
child elements. If it’s not checked, the condition is evaluated
only when it is encountered for the first time.
If Controller
• "${UserVar}" == “true“
• ${Count} == 10
• ${Count} == 10 && "${UserVar}" == “true“
If Controller
• A better option (default one) is to check Interpret Condition as Variable Expression?
• Then in the condition field you have 2 options:
• Option 1 : Use a function (${__jexl3()} is advised) to evaluate an expression that
must return true or false
• Use ${__jexl3()} function
• ${__jexl3("${UserVar}" == "true")}
• ${__groovy("${UserVar}" == "true")}
If Controller
• Option 2 : Use a variable that contains true or false
Think Time
Think time is the time that a user waits between two actions, other words Mark will wait and think
between two transactions.
Lets see the example below
Here Mark entered the user name and password in HP web tours
application’s login screen.
Where to click
After the login and home page is loaded Mark is thinking to where to
click, here Think timer is started.
Think Time
After some time Mark decided to select “flight” button , he clicked on “Flights”. So the
the moment he clicked on flights option think timer stopped.
Note : Thinktime may change from user to user for the same application
www.facebook.com
2 Secs
Now Mark is “Thinking” as to how to login and where should he enter the username and password.
Think Time also includes time taken to enter the username / password and click on “login” button
10 Secs 7 Secs
2 Secs 2.5 Secs
Think Think
Time Login Transaction Time Log off Transaction
Launch Transaction
Order of Component Execution / Hierarchy
a+b*c
b*c is evaluated first and then the
addition operation
Constant Timer
• The Constant Timer introduces a specified delay before the samplers in its
scope are executed. The only configuration is the delay that is needed.
• You can achieve this by making the Constant Timer a child element of the
sampler to be delayed.
How Timers scope works
Rule 1: Timers are executed before each sampler in their scope. Constant Timer delays all the
child elements in scope.
As we can see, Timer1 is:
• Executed three times because of scoping rule
• Executed once before Sampler1
• Executed once before Sampler2
• Executed once before Sampler3
This feature allows us to have different think times for each element.
Control the execution order of Timers
Option 2: You can achieve this by making the Constant Timer a child element of
the sampler to be delayed.
Nesting timers as children of samplers is less readable since timers are executed before
Sampler
Control the execution order of Timers
Option 3: Have a random timer and put it at the same level as Sampler, thanks to
scoping rules, it would run before each Sampler.
1. BeanShell Pre-processor
2. Constant Timer
3. Constant Throughput Timer
4.BSF Sampler
5. Transaction Controller
6. CSV Data Set Config
7. HTTP Request
8. BeanShell PostProcessor
9. Aggregate Report
As you can see in the screenshot below, the position of different elements does not
impact the execution order.
More clarity on Order of Component Execution
For the given test plan, the execution order will
be:
1. Timer1
2. Timer2
3. JR1
4. Outer Postprocessor
5. Inner Postprocessor 1
6. Timer1
7. Timer2
8. JR2
9. Outer Postprocessor
10. Inner Postprocessor 2
The second rule is that outer elements are executed before inner elements of the same
Type.
Gaussian Random Timer
• The Gaussian Random Timer introduces a delay according to
the Gaussian Distribution
• The delay varies around a central mean, as illustrated in Figure
Gaussian Random Timer
Gaussian Random Timer
Let’s assume that the mean value is 10 seconds and the variance is 2 seconds.
The delay introduced would vary as follows:
• 68% of the time, the delay would vary between mean - variance and mean
+ variance (between 8 seconds and 12 seconds).
• 95% of the time, the delay would vary between mean - 2 * variance and
mean + 2 *variance (between 6 seconds and 14 seconds).
• 99% of the time, the delay would vary between mean - 3 * variance and
mean + 3 *variance (between 4 seconds and 16 seconds).
• The actual delay will range between the Constant Delay and the Constant Delay plus the
Random Delay.
• As the term “uniform” indicates, the delay varies within its range with equal probability.
• If the Constant Delay was configured to 10 seconds and the Random Delay was configured to 5
seconds, then the actual delay will vary between 10 and 15 seconds.
Notice, GRT is not added for 1st sampler, as timer is executed before the sampler
Constant Throughput Timer
• The Constant Throughput Timer calculates and introduces delays between samplers
so as to keep the throughput at the configured value.
• Target throughput(in samples per min) = 5
• Configure Number of Threads (Users) as 1 and Loop Count as 20.
• In these results, each of the requests to /jmeter/alpha has been delayed by a
varying amount so as to keep the overall throughput at the configured level
• In the Aggregate results, observe that the throughput is approx 5 requests per
minute.
Synchronizing Timer
• The Synchronizing Timer blocks VUsers and releases them all at
once, thus creating a large load at the same instant. This is very
helpful to test how the application handles simultaneous
requests.
• Number of Threads (Users) as 4, Loop Count as 12
Assertions
• The primary purpose of assertions is to validate the server response and decide if the test
passed or failed.
• The response to a sampler contains code to indicate success or error. But this is at the
protocol level.
• JMeter assertions provides a mechanism to validate the content of the response.
• The specific JMeter assertions you use depend on the response format.
• The validation check is configurable based on the assertions type.
• JMeter assertions can be a child element of a test plan, thread group, controller, or
sampler.
• Assertions will apply to all the samplers under the scope of its parent. For example, if an
assertion is a child element of a thread group, then it applies to all the samplers under
the thread group.
Assertions
• Sometimes, it makes more sense to have specific assertions for
each sampler.
• To demonstrate “NOTFOUND”, make sure first correlation fails, so that second correlation value is displayed as
“NOTFOUND”
• Infact, anything can be set as default values.
• Even we can use empty value but it has benefits to use “NOTFOUND”
Correlation
• 0 for random
• 1 for fish
• 2 for dogs
Correlation
• Capture the complete response
• (?s)(.*)
• ?s represents new lines
How properties differ from variables
• Properties and variables allow you to make data dynamic in JMeter. So the purpose
• is very similar:
• Important concepts in JMeter
• • Variables are tightly bound to their thread, meaning that every thread has its
• own copy and can manipulate their own version.
• • Properties are shared among all threads, so changing a property during a test
• should be avoided. If you really need to change it, ensure that the value is not
• corrupted by simultaneous access by synchronizing this access.
• In summary, variables and properties differ in that Properties are global and Variables
• are local with respect to threads.
• Based on this, we can define two rules:
• • Properties should be used for environment-related data
• • Variables should be used for user-related data and correlation rules. That’s why
• for example, extractors in JMeter will create variables
How properties are created
• Properties are created by JMeter reading them from:
• • jmeter.properties
• • user.properties
• • command line using “-J” option: -JpropName=propValue
• • command line using “-G” option: -GpropName=propValue
• • any file referenced through command line option “-p” or ”–propfile”
• • any file referenced through command line option “-q” or ”–addprop”
• • any file passed using command line option
• You can also create them from JMeter using function:
• ${__setProperty(propName, propValue)}
• And finally, using scripting elements like JSR223 Test Elements
• props.put("propName", "propValue");
• or:
• props.setProperty("propName", "propValue");
How variables are created
• Variables are created by JMeter using different elements:
• • User Defined Variables a config element
• • User Parameters a pre-processor
• • JMeter functions⁴⁶ that accept a variable as last argument
• • JMeter extractors⁴⁷ that create variables from response excerpts
• You can also create using scripting elements like JSR223 Test Elements:
• vars.put("varName", "varValue");
• or:
• vars.putObject("varName", objectToBeUsed);
How ${} differs from ${_P}
• Since we know the difference between Variables and
Properties, let’s see how to use
• them.
• Variables are accessed using ${varName}
• Properties are accessed using __P function, so to read property
propA, you
• would use ${__P(propA)}
Remote execution – Master / Slave
Remote execution – Master / Slave
• On both master and slave, jmeter should be available.
• Get IP Address of Master and Slave.
• Both Master Machine and Slave machine should be in the same network.
• Master Machine From the Jmeter Bin Folder - Execute “Create-rmi-
keystore” windows batch file.
• Enter pertinent information on the cmd prompt like firstname, lastname,
state, company id etc…
• Once the cmd prompt is executed, a file is created with the name “rmi-
keystore.jks”
Remote execution – Master / Slave
• Copy “rmi-keystore.jks” into the slave machine – bin folder
• Master Machine – User.properties file Copy below information.
C:\Users\Isha\
Desktop\User_properties_app
Created Remote object in the cmd line indicates that connection is established.
Note: If you wanted to use master also, run “jmeter-server” windows batch file on master also.
Remote execution – Master / Slave
From the master, test can be executed with the users of the slave as shown in the above picture.
“Starting the test on the host” on the cmd line indicates, slave is used for execution.
• Reports
• Beanshell
Create a Test Scenario
• Merge multiple scripts using Merge options
Create a Test Scenario
• Merged 3 scripts below
Create a Test Scenario
• Apply following settings for
executing for one hour.
• Here Ramp up period id 10 secs.
Which means 1 user for every 2
secs
• Make sure forever options is check
and duration as 3600 secs
• No option of ramp down.
• We need a plug-ion
Create a Test Scenario
• Make sure Aggregate Listener is added to get the response
times report
Create a Test Scenario
• Make sure Simple data writer Listener is added to get the final
report
Test Results
• For creating a report for Load Test, Some changes needs to be
done in user.properties file (GUI and also non-GUIExecution)
• In real world Non-GUI mode execution is preferred as it
consumes less resources.
C:\Users\sree\
Desktop\Jmeter_Scripts\Sdli
Test Results
• Add simple data writer listener
• Make following changes
• Jmeter –g C:\Users\sree\Desktop\Jmeter_Scripts\
DashboardReport.csv -o C:\Users\sree\Desktop\
Jmeter_Scripts\DashboardReport
Pre-processor
Pre-Processors
Pre-processors take the request and modify it (substitution, enhancement, dereferencing variables, etc.)
before the sampler sends it to the server.
Post-Processor
Post-processor
Client Web App Server DB Server
Post-Processors
Post-processors process the response from the server. They are used to process the server response and
modify the component settings or to update variables
Order of Component Execution / Hierarchy
a+b*c
b*c is evaluated first and then the addition operation
Order of Component Execution
1. BeanShell Pre-processor
2. Constant Timer
3. Constant Throughput Timer
4. Transaction Controller
5. CSV Data Set Config
6. HTTP Request
7.BSF Sampler
8. BeanShell PostProcessor
9. Aggregate Report