Professional Documents
Culture Documents
PARAMETERIZATION IN JMETER 9
BEANSHELL SCRIPTING 40
1. Launch Jmeter from the Jmeter bin folder (Test plan is shown)
a. Test plan is the container of all things needed in a performance test
2. Right click on the Test plan
3. Click on the add button
4. Select Threads and choose thread group from the list
5. Right click on the thread group
6. Click on the add button
7. Choose sampler and select HTTP REQUEST
Setting up HTTP request: number of threads = number of users
Ramp up period = Time for each user to wait before running (i.e ramp up period/number of
threads)
Loop count = no of iteration each user should go
8. Right Click on the Thread group
9. Click on the add button
10. Click on Listener and select Listener of choice to display your result
11. Run the test
3. Add HTTP Header Manager to the HTTP Request(Add>>Config element>> HTTP Header
Manager)
Setup the Authorization Header Manger as follows:
Click the Add button
Name: Authorization
Value: Basic ${auth}
PARAMETERIZATION IN JMETER
Parameterization[ Data driven test] is an execution strategy, which allows us to run a test case
automatically, multiple times with different input values.
Steps to parameterize in jmeter
1. Put test data in csv file
2. Configure Jmeter to read the data from CSV file
Note: parameterization is used while searching.
1. Create CSV file which would be used as data source
2. Right click on the HTTP request which the data source would be used
3. Select Add
4. Select Config element and select CSV DATA Set config from the config element section
5. Setting up the CSV DATA Set config
Filename: contains the path to the CSV data file
Set the hardcoded name to be searched to the title in the csv file with a dollar sign before
it ${title in csv file}
Note: Ensure title in csv file is in curly braces
All place that contain the hardcoded value like the path should be change to the title of
csv file
First Level Is the JSON values that are not nested in $.name e.g $.id
other value(s)
Second Level JSON values that are nested in other $..name e.g $..id
value(s)
Match No. is to identify specific value to be taken if there are multiple values of the Json path
expression in the response e.g from image above to get the value 8 as the id we use 2 as the value
for Match No.
Default Value: is what should show if the JSON path expression doesn’t have any match.
4. Add a debug sampler to the thread group to confirm the value saved after running the HTTP
request, then use the variable in any other request required.
NB: Using a Debug sampler is optional and the user should proceed to using the variable in
HTTP Request immediately after completing setup. Debug sampler shows the JMeter variable in
the listener(as shown in image below), which is the reason for the recommendation.
NB: To Extract two value(s) but save then in a single variable check the screenshot property bellow
More on Timer
HOW TO USE LOGIC CONTROLLER IN JMETER
Logic Controllers let you customize the logic that JMeter uses to decide when to send requests. Logic
Controllers can change the order of requests coming from their child elements. They can modify the
requests themselves, cause JMeter to repeat requests, etc.
Logic controllers are of different types which can help make request classification and grouping easier.
Logic controller can be added by:
1. Right click on thread group
2. Click on Add button
3. Select logic controller
4. Select preferred logic controller from options
The once only controller will only run once when the test is executed.
HOW TO USE TEST FRAGMENT
The Test Fragment element is a special type of controller that exists on the Test plan tree at the same level
as the Thread Group element. It is distinguished from a Thread Group in that it is not executed unless it is
referenced by either a Module Controller or an Include_Controller. Test fragment can be used to handle
the execution of a script which will be used by multiple scripts e.g order script requires to login, cancel
order also requires login script therefore login script can be placed in the test fragment.
Using Test Fragment with Module controller.
1. Right click on Test plan
2. Click Add
3. Select Test Fragment
7. Add the Module controller into all necessary points it’s needed.
3. Load the saved test fragment(login script) in the include controller by clicking browse and
navigating to the test fragment and click open on the file selector dialogue.
Selector dialogue pops up which is where you navigate to file and select the file the click open
Note: The local file content can also contain the full path including name of the file to be downloaded e.g
“/Users/seamlesshr/Downloads/demo2.txt” also, it doesn’t only contain the above format only.
HOW TO UPLOAD USING FTP
1. Change the request type to put(STOR)
2. Enter the local file path which is to be uploaded as seen above
3. Enter the path which the file is to be uploaded on the ftp server
NB: When uploading or downloading zip, check the use Binary checkbox
The Beanshell function can be used to save a variable. Process is shown bellow:
The image above shows the beanshell function in the Request name field which saves the value of 88*100
into variable1, then variable1 becomes a variable name which can be used in another request
The image above shows the calling of variable1 which was saved using the Beanshell function. When the
request are ran we have:
Note: It is better to use the the function helper in the tools section while dealing with function to make it
easy to use.
Read More
To use the Perfmon plugin the server agent needs to be installed on the server which the Application
under test is hosted on. Server agent can be downloaded here
HOW TO INSTALL ON SYSTEM LOCALLY
WINDOWS:
● Extract downloaded file
● Click/ Double click on startAgent.bat
MAC/LINUX:
● Extract downloaded file
● Launch terminal in the extracted folder
● Run the command sh startAgent.sh
NB: Press control+c to stop the running server
HOW TO DO REMOTE DISTRIBUTED TESTING
In the event that your JMeter client machine is unable, performance-wise, to simulate enough users to
stress your server or is limited at network level, an option exists to control multiple, remote JMeter
engines from a single JMeter client. By running JMeter remotely, you can replicate a test across many
low-end computers and thus simulate a larger load on the server. One instance of the JMeter client can
control any number of remote JMeter instances, and collect all the data from them. This offers the
following features:
➢ Saving of test samples to the local machine
➢ Management of multiple JMeterEngines from a single machine
➢ No need to copy the Test plan to each server - the client sends it to all the servers
Pre-Requisites
1. Master & slave machine must have similar version of Jmeter Installed
2. Master & slave machine must have similar version of Java Installed
3. Master and slave machine must connect to each other(same subnet)
Configurations
1. Check Jmeter bin folder for Jmeter.properties file
2. Open file with any preferred editor
3. Search (cmd+f/ctrl+f) for Remote_hosts
4. Launch terminal and run command ipconfig on windows ifconfig on mac
5. Copy IP address from the above command on terminal and Place in Jmeter.properties
6. Duplicate Remote_hosts (step 4 above) and give value as the copied ip address. (can be separated
by comma(,) for multiple slave machines
7. Launch Jmeter
8. Click on the run button on the header tab
9. Click on run then hoover on remote start (should show the newly added ip address)
WHY BEANSHELL
To customize jmeter script in user defined or preferred way
NOTE: Displaying on the log viewer requires enabling the log viewer in the Option tab of jmeter
Getting the assigned value of a variable: vars.get(“variable_name); : can also be used for assigning a
previous variable to the new variable as seen above.
Getting the name of executing thread:
ctx.getThread().getThreadName(); can also be assigned to a value
var h = ctx.getThread().getThreadName();
NOTE: the beanshell pre-processor will be used to create a flow whereby HTTP Request_2 will
not run unless HTTP Request_1 is run bcos the beanshell pre-processor is executed first.
4. Write script in the beanshell pre-processor e.g.
var responsecodeof1 = prev.getResponseCode();
var responsemessageof1 = prev.getResponseMessage();
log.info("Response code of request1 is: " + responsecodeof1);
log.info("Response code of request1 is: " + responsemessageof1);
if(!rresponsecodeof1.equals("200")){
ctx.getEngine().stopTest();
}
Note: The beanshell post-processor is used to write if a test passed in a csv file in this
documentation.
4. Write flow code in the script section of the beanshell post-processor