Jmeter Tutorial
Jmeter Tutorial
Lab Guide
Getting Started with Apache<course
JMeter™
code>
Lab Guide
88BLZ20010
Table of Contents
TOC-1
Goals During this lab, you will learn how to install and configure Apache JMeter™.
Time 20 minutes
Instructions
Click Lab Resources to download the lab resources required to run the Apache JMeter™ labs.
You must install the Java SE Development Kit (JDK) version 7 or later before installing JMeter. Complete
these steps to install the JDK:
Note: If you already have JDK version 7 or newer installed on your system, you can skip Part 1 of this lab.
1. Go to [Link]
2. Click the Accept License Agreement radio button in the JDK download section of the web page.
3. Click the correct version of JDK for your operating system to download the installation files.
4. When the file is finished downloading, double-click it to begin installing JDK. The User Account Control window
opens.
5. Click Yes in the User Account Control window to allow this app to make changes to your device. The Java SE
Development Kit setup window opens.
6. Click Next to start the installation wizard. The Custom Setup window opens.
8. The Complete window opens when the installation finishes. Click Close.
3. When the download is complete, double-click apache-jmeter-3.1_src to open the zip file. Your application for
managing zip files opens.
Note: If you do not have an application installed for opening zip files, you can download and install a trial version if
the WinRAR archiver application at [Link]
4. Create a new folder named JMeter on your desktop and extract the files to the folder.
5. Open your JMeter folder and then open the bin folder.
7. Right-click the JMeter Windows batch file and select Send to Desktop to create a shortcut to JMeter on your
desktop.
2. Click [Link] in the middle of the page to download the installation files.
3. When the download is complete, move the file to the lib/ext directory of your JMeter folder.
4. Launch JMeter and select Options Plugin Manager to verify that the Plugin Manager launches properly.
5. You have finished this lab when the JMeter Plugins Manager opens properly and displays a list of already installed
plugins in the Installed Plugins tab.
Goals During this lab, you will learn how to configure Thread Groups and Ultimate Thread Groups.
Scenario A Thread Group is one of the most basic elements of a JMeter script. You cannot run a JMeter
script without a Thread Group. The Thread Group initiates the thread that runs the scenario that
you specify in the script.
In this lab, we examine two types of thread groups: standard and ultimate. The standard Thread
Group is included in the JMeter installation by default. It is simple to configure and includes a ramp
up time, loop count, and duration.
The Ultimate Thread Group is more advanced and allows you to specify the ramp down time and
the ramp up time. An Ultimate Thread Group can also be used to configure more complex thread
scenarios.
Complete these tasks to learn how to configure Thread Groups and Ultimate Thread Groups:
Install the Dummy Sampler and the jpgc - Standard Set Plugins
Create a new JMeter test
Add a Thread Group
Add a Dummy Sampler
Configure the Thread Group
Add an Ultimate Thread Group
Add an Additional Dummy Sampler
Add a View Results Tree listener and run the test
Time 20 minutes
Note: The jpgc – Standard Set plugin includes the Ultimate Thread Group that you will use in this lab.
4. Check the Dummy Sampler and the jpgc - Standard Set checkboxes in the list of available plugins.
5. Click Apply Changes and Restart JMeter to install these plugins. JMeter installs the plugins, closes, and restarts
automatically.
8. Click New Folder to create a new folder on your desktop and name the folder JMeter Scripts.
12. Check the Run Thread Groups consecutively checkbox in the center of the screen.
13. Select Edit Add Threads (Users) Thread Group to create a new thread group. The Thread Group
configuration pane opens.
Note: By default, a Thread Group is configured to have one thread with a ramp-up period of one second and a loop
count of one.
Add a Dummy Sampler
Complete these steps to add a Dummy Sampler to your JMeter test:
14. Select Edit Add Sampler Dummy Sampler to add a Dummy Sampler to your Thread Group. The Dummy
Sampler configuration pane opens.
15. Change the name of the dummy sampler to Sampler in TG #1 to indicate that this is the Dummy sampler for
Thread Group one.
16. Click Thread Group in the Test Plan pane to view the thread group configuration screen.
17. From the Thread Group screen, select the Stop Thread radio button in the Action to be taken after a Sampler error
section of the screen.
20. Right-click Test Plan and select Add Threads (Users) Ultimate Thread Group. The Ultimate Thread Group
configuration pane opens.
21. Click Add Row three times to add three rows to your Ultimate Thread Group.
24. Select Add Sampler Dummy Sampler. The Dummy Sampler configuration pane opens.
25. Enter Sampler in TG #2 in the name field to indicate that this is a Dummy sampler in Thread Group two.
28. Select Add Listener View Results Tree. The View Results Tree configuration pane opens.
31. Click View Results Tree in the left pane. The View Results Tree pane opens and displays your test results for Thread
Groups one and two as they are generated.
Goals During this lab, you will learn how to simulate Internet browser behavior by using a cookie
manager and a cache manager. You will then test your Internet browser response time.
Scenario In this scenario, you will create a basic, realistic user scenario in which multiple virtual users enter
a website and navigate the site. You will do this by sending HTTP requests to a web page. You will
then send a second HTTP request to a second page.
Using the Cookie Manager and the Cache Manager, you will configure JMeter to behave like a real
browser. You can clear your cache and cookies with each iteration to imitate the behavior of
multiple users entering the website. At the end of the lab, you will run your test and view results
for multiple users, noting the maximum response times.
Complete these tasks to configure and test this basic scenario:
Time 20 minutes
1. Launch JMeter.
2. Select File Save Test Plan As. The Test [Link] window opens.
3. Enter JMeter Lab 1-3 - Basic [Link] in the File Name field and click Save.
Note: Save the lab periodically throughout this exercise to preserve your work.
5. Right-click Test Plan and select Add Threads (Users) Thread Group. The Thread Group configuration pane
opens.
8. Right-click Test Plan and select Add Config Element HTTP Cache Manager to add a cache manager to the
test.
9. Check the Clear cache each iteration? checkbox and accept all other default settings.
11. Right-click Test Plan and select Add Config Element HTTP Cookie Manager to add a Cookie Manager to the
test.
12. Check the Clear cache each iteration? checkbox and accept all other default settings.
Note: Adding a cache manager and a cookie manager to the test plan allows you to better simulate real Internet
browser behavior.
14. Right-click Test Plan and select Add Config Element HTTP Request Defaults.
Note: You can also enter the protocol in the Server Name or IP field and leave the Protocol field blank. For example,
enter [Link] in the Server Name or IP field.
17. Right-click Test Plan and select Add Listener View Results Tree to listen to traffic. The View Results Tree
configuration pane opens.
19. Right-click Thread Group in the left pane and select Add Sampler HTTP Request. The HTTP Request
configuration pane opens.
Note: When the fields of the HTTP Request configuration pane are left blank, the HTTP Request Default values are
automatically applied. For example, the HTTP Request will use the Server Name [Link] provided in the
Server Name field of the HTTP Request Defaults configuration pane.
20. Right-click HTTP Request in the left pane under Thread Group.
21. Select Add Timer Constant Timer from the right-click menu. The Constant Timer configuration pane displays.
22. Enter 10000 in the Thread Delay (in milliseconds) field to run the timer for ten seconds.
23. Click HTTP Request in the left pane. The HTTP Request configuration pane opens
24. Select the Advanced tab. The HTTP Request Advanced configuration pane opens.
27. Right-click Thread Group in the left pane and select Add Sampler HTTP Request. The new HTTP Request
configuration page opens.
32. Select Add Timer Constant Timer. The Constant Timer configuration pane opens.
33. Enter 3000 in the Thread Delay (in milliseconds) field to apply a wait time of three seconds.
35. Click View Results Tree in the left pane. The View Results Tree configuration pane opens and the test results begin
to display.
Note: Each thread executes two http requests. You should see the results for twenty total http requests.
37. Click the Request tab to view the Get request and the URL. Your Request tab should look like this:
38. Click the Response data tab to view the response data. What was the maximum response time in your test? The
response time is also known as the load time. You can manually check the load time for each http request to
discover the maximum load time. You can also add an additional listener to capture this information.
41. Select Add Listener Aggregate Report. The Aggregate Report configuration pane opens.
43. Click Start in the tool bar to run the test again.
44. As data appears in the Aggregate Report pane, note the maximum response time in milliseconds in the Max
column of the report.
Goals During this lab, you will learn how to use a JSON Assertion, a Response Assertion, and a Duration
Assertion.
Scenario Assertions are used to verify that you accessed the web page that you wanted to access and that
you received the response and the value that you wanted to receive. For example, when you login
to a website, you see welcome text with your username on the home page. If you want to verify
that the sign in completed properly, you may verify that the word “welcome” is included in the
sign in request response.
During this lab, you will complete these tasks:
Time 20 minutes
In Part 1 of this lab, you will use a JSON Assertion to verify information. A JSON Assertion is a dedicated and
more convenient method for handling JSON responses that are common and popular in web apps.
Create a New JMeter Test
Complete these steps to create a new JMeter test:
2. Select File Save Test Plan As. The Test [Link] window opens.
Note: See JMeter Lab 1-1 Installation for instructions about installing the JMeter Plugins Manager if it is not
available in your Options menu.
5. Click the Available Plugins tab of the JMeter Plugins Manager window.
6. Click Apply Changes and Restart JMeter. JMeter closes and reopens automatically with the plugin that you
selected installed.
Add a Thread Group
Complete these steps to add a Thread Group:
8. Right-click Test Plan and select Add Threads (Users) Thread Group. The Thread Group configuration pane
opens.
11. Select Add Sampler HTTP Request. The HTTP Request configuration pane opens.
13. Right-click HTTP JSON 1 and select Add Assertions JSON Path Assertion. The JSON Path Assertion
configuration pane opens.
16. Right-click HTTP JSON 1 and select Add Listener View Results Tree. The View Results Tree configuration pane
opens.
17. Click Start to run the test and view the results as they appear in the View Results Tree listener pane.
Note: Because the default thread group configuration was applied to this test, only one thread group will run one
time.
18. Note the test results in the Sampler results tab of the View Results Tree listener. Note that the test failed.
19. Click the Response Data tab. The test failed because the assertion expected to find ‘us-east-1’ in the
$.prefixes[0].region, but found the value ‘GLOBAL’ instead.
In Part 2 of this lab, we will recreate the test in Part 1, change the expected value, run the test, and note the
new results.
Create an HTTP Request
Complete these steps to create an HTTP GET Request to [Link]/[Link]:
21. Right-click Thread Group and select Add Sampler HTTP Request. The HTTP Request configuration pane
opens.
23. Right-click HTTP JSON 2 and select Add Assertions JSON Path Assertion. The JSON Path Assertion
configuration pane opens.
Your JSON Path Assertion configuration for HTTP JSON 2 should this:
26. Right-click HTTP JSON 2 and select Add Listener View Results Tree. The View Results Tree configuration pane
opens.
28. View the test results in the Sampler results tab of the View Results Tree listener. Note that the test passed.
Click the Response data tab to view the Response data and note that the region in the first prefix matches the expected
value field of GLOBAL.
In Part 3 of this lab, we will apply a Response Assertion to verify whether specific text is contained in the
response or not.
Create a Duplicate and Configure an HTTP Get Request
Complete these steps to create a duplicate HTTP GET request to the BlazeMeter website:
29. Right-click HTTP JSON 2 and select Duplicate to create a duplicate of this HTTP Request.
31. While pressing, and holding the Shift key, click JSON Path Assertion and View Results Tree under HTTP Response 1
to highlight both items.
34. Right-click HTTP Response 1 and select Add Assertions Response Assertion.
36. Click Add to add a row to the Patterns to Test section of the Response Assertion pane.
37. Enter departure in the row and accept all other default settings.
Your Response Assertion configuration for HTTP Response 1 should look like this:
39. Right-click HTTP Response 1 and select Add Assertions Response Assertion.
41. Click Add to add a row to the Patterns to Test section of the Response Assertion pane.
42. Enter apache in the row and accept all other default settings.
Your second Response Assertion configuration for HTTP Response 1 should look like this:
44. Right-click HTTP Response 1 and select Add Listener View Results Tree. The View Results Tree configuration
pane opens.
45. Click Start to run the test and view the results as they appear in the View Results Tree listener pane. Note that the
test fails.
In Part 4 of this lab, we will utilize a Response Assertion to verify receipt of a 404 code.
Create a Duplicate HTTP Get Request
Complete these steps to create a duplicate HTTP GET Request to the BlazeMeter website:
47. Right-click HTTP Response 1 and select Duplicate to create a duplicate of this HTTP Request.
48. Remove one of the Response Assertions for your new HTTP Request.
50. Click the Response Assertion for HTTP Response 2 to select it.
52. Click Add to add a row to the Patterns to Test section of the Response Assertion pane.
53. Enter 404 in the row and accept all other default settings.
Your Response Assertion configuration for HTTP Response 2 should look like this:
54. Click View Results Tree for HTTP Response 2 to select it.
55. Click Start to run your test. Note that the test passes and the Response Code of 404 is found.
In Part 5 of this lab, we will use a Duration Assertion to verify that the outcome matched the expectation of
the test.
Add a Dummy Sampler
Complete these steps to add a Dummy Sampler to your test:
57. Right-click Thread Group and select Add Sampler Dummy Sampler.
58. Enter 1000 in the Response Time field and accept all other default settings.
59. Right-click Dummy Sampler and select Add Assertions Duration Assertion.
60. Enter 1200 in the Duration in milliseconds field and accept all other default settings.
62. Right-click Dummy Sampler and select Add Listener View Results Tree. The View Results Tree configuration
pane opens.
63. Click Start to run the test and view the results as they appear in the View Results Tree listener pane
Goals During this lab, you will learn how to extract a CSRF token from a response header, the body of a
response, and so on. You will then learn how to use the extracted token in another HTTP request.
Scenario This is a more advanced lab that builds on everything that you learned in the previous labs. In this
lab, you will use a regular expression extractor to extract a token while using timers, login, logout,
and a data file with random delays between requests to mimic real world scenarios.
You will accomplish this by completing these tasks:
Time 20 minutes
2. Select File Save Test Plan As. The Test [Link] window opens.
5. Right-click Test Plan and select Add Thread Groups Thread Group. The Thread Group configuration pane
opens.
Complete these steps to add and configure an HTTP Request that will be used to extract the CSRF token:
7. Right-click Thread Group and select Add Sampler HTTP Request. The HTTP Request configuration pane
opens.
Field Value
Name HTTP Request Homepage
Server or IP [Link]
Path /register
Method GET
Complete these steps to extract the CSRF token from the GET request response received from the
[Link]/register web page:
9. Right-click HTTP Request Homepage and select Add Post Processors Regular Expression Extractor. The
Regular Expression Extractor configuration pane opens.
Complete these steps to register a new account and create a new HTTP Request:
12. Right-click Thread Group and select Add Sampler HTTP Request. The HTTP Request configuration pane
opens.
Field Value
Name company
Value BlazeMeter
d. Configure row three as follows:
Field Value
Name email
Value jsmith@[Link]
e. Configure row four as follows:
Field Value
Name password
Value abcd1234
f. Configure row five as follows:
Field Value
Name password_confirmation
Value abcd1234
14. Right-click HTTP Request Register and select Add Config Element HTTP Cookie Manager. The HTTP Cookie
Manager configuration pane opens.
16. Click Add to add a row to the User-Defined Cookies section of the pane.
Complete these steps to add a View Results Tree listener that will capture and display the results of your
test:
19. Right-click Thread Group and select Add Listener View Results Tree. The View Results Tree configuration
pane opens.
Click Start to run the script. The test results appear in the Sampler result tab of the View Results Tree pane. The test
successfully extracts the token from the first request and posts a cookie to the second request.
21. Right-click Thread Group and select Add Sampler HTTP Request. The HTTP Request configuration pane
opens.
Complete these steps to add an HTTP Request Sampler to logout of the website and pass the token as a
parameter:
24. Right-click Thread Group and select Add Sampler HTTP Request. The HTTP Request configuration pane
opens.
26. Right-click the HTTP Cookie Manager in the Test Plan pane on the left and select Copy.
27. Right-click HTTP Request Logout in the Test Plan pane and select Paste. A copy of the HTTP Cookie Manager
appears in the HTTP Request Logout.
29. Right-click Thread Group and select Add Timer Uniform Random Timer. The Uniform Random Timer
configuration pane opens.
32. Right-click Test Plan and select Add Listener View Results Tree. The View Results Tree configuration pane
opens.
You must add a Debug Sampler to view what was extracted during your test. Complete these steps to add a
Debug Sampler:
35. Right-click Thread Group and select Add Sampler Debug Sampler. The Debug Sampler configuration pane
opens.
37. Click the last View Results Tree listener in the Test Plan pane to open the View Results Tree pane.
38. Click Start to run the test again. Your test results display in the View Results Tree pane.
Scroll down and click Debug Sampler in the Text section of the View Results Tree listener.
39. Click Response data to view the variables that were used in the test and note the value captured for token in the
Response data tab.
The best way to create an initial script before adding parameters is to record it using the BlazeMeter chrome extension
recorder. See the knowledge base article Chrome Extension for more information.
For more information about how to create login scenarios, see How To Use JMeter For Login Authentication. There are at
least two good options to generate unique login credentials for multiple sign ups and logins. For this exercise, we used a
comma separated value (CSV) file to create a data set which holds the username, email address, and password. For more
information about the JMeter CSV Data Set Config option, see Using CSV Data Set Config in the [Link] online
knowledge base.
Goals During this lab, you will learn about and apply these JMeter functions: log, time, counter &
ThreadNum, UUID, Property, and instanceId.
Scenario Create a standard test in JMeter using these JMeter functions: log, time, counter & ThreadNum,
UUID, Property, and instanceId.
You will accomplish this by completing the following tasks:
Time 20 minutes
2. Select File > Save Test Plan As. The Test [Link] window opens.
5. Right-click Test Plan and select Add Thread Groups Thread Group. The Thread Group configuration pane
opens.
8. Right-click Thread Group and select Add Sampler Dummy Sampler. The Dummy Sampler configuration pane
opens.
9. Verify that the Dummy Sampler is configured as follows with these default values:
Field Value
Name Sampler #1
Successful sample Checked
Response Code 200
Response Message OK
Connect Time ${_Random(1,5)}
Latency ${_Random(1,50)}
Response Time ${_Random(0,500)}
Simulate Response Checked
Time (sleep)
Request Data Dummy Sampler used to simulate requests and responses without actual network activity.
This help debugging tests
Response Data Dummy Sampler used to simulate requests and responses without actual network activity.
This helps debugging test
10. Right-click Sampler #1 select Duplicate. A duplicate of Dummy Sampler 1 appears in the Thread Group.
11. Enter Sampler #2 in the name field of the new Dummy Sampler. Your second Dummy Sampler configuration
should look like this:
13. Right-click Test Plan and select Add Listener View Results Tree. The View Results Tree listener configuration
pane opens.
14. Click View Results Tree to view the test results pane.
16. Click Sampler #1 and note the load time and connect time in the Sampler result tab.
17. Click Sampler #2 and note the load time and connect time in the Sampler result tab.
Note: Load time is given in milliseconds and connect time is given in seconds.
1. Click Sampler #1 to view its configuration page. The Dummy Sampler configuration page opens.
2. Enter the log function ${__log(“hello world”)} after Sampler #1 in the Name field. Your sampler name should now
give Sampler #1 ${__log(“hello world”)}.
3. Click Sampler #2 to view its configuration page. The Dummy Sampler configuration page opens.
4. Enter the log function ${__log(“hello world”)} after Sampler #2 in the Name field. Your sampler name should now
give Sampler #2 ${__log(“hello world”)}.
5. Click View Results Tree to display the pane that will show your test results.
7. View your test results and note that the log function added “hello world” to the name of each sampler.
8. Select Options Log Viewer. The log view opens at the bottom of the View Results Tree window.
9. In the Log Viewer, note the number of times that the thread group ran and where “hello world” appears in the log.
1. Right-click Sampler #2 ${__log(“hello world”)} and select Duplicate to give you three dummy samplers in total.
Part 4: Configure a JMeter Test Using the Counter & ThreadNum Function
1. Select the second and third samplers in your thread group to highlight them.
3. Click Yes in the popup window to finish removing two samplers. Sampler 1-${__time()} is the only remaining
sampler.
5. Replace 1-${__time()} with ${__counter(false,)} - ${__threadNum} in the Name field to rename the sampler.
Note: There is no need to make any other changes to the test. The thread group should still be configured to run
one thread for one loop as it did in previously configured tests.
8. Notice that the sampler name is 1 - 1 in the Text pane of the View Results Tree page. The first number 1 in the
sampler name is a result of the counter function. The second number 1 in the sampler name gives the number of
thread groups in the test as a result of the threadNum function.
1. Click sampler ${__counter(false,)} - ${__threadNum} to view its Dummy Sampler configuration pane.
2. Replace ${__counter(false,)} - ${__threadNum} with ${__UUID} in the Name field to rename the sampler.
5. View your test results in the View Results Tree pane and note that the function generates a 128-bit universally
unique identifier. This identifier can be used to randomize logins or any other field when testing with a high level
of concurrency.
1. Right-click Test Plan and select Add Config Element User Defined Variables. The User Defined Variables
configuration pane opens.
4. Enter ${__P)PropNumOfThreads,5)} in the Value field of the same row. You now have a Property function with
two attributes, a name of threads and a default value of 5, added to your test.
6. Enter ${threads} in the Number of Threads field. The Thread Group will now use the default value of 5 that you set
in your Property function to determine how many threads to run in your test.
When you run the .jmx script, it changes the default value that you set in the Property function from 5 to 3 and
writes the results to the [Link] file.
Note: The variable name given at the command line must match the variable name in your JMeter test exactly.
Variable names are case sensitive.
10. View the test results displayed in the command line window as the command is executed. Note that the value of 3
was applied to your Property function from the command line. This value populated the threads variable to set the
number of threads to execute, overriding the value of 5 that you originally configured.
Part 7: Configure a JMeter Test Using the Property Function with an instanceId
Complete these steps to incorporate the instanceId function into your Property function:
6. View your test results in the View Results Tree pane and note that you receive the value of 1 five times. This occurs
because you are only running one engine on your local computer for five threads.
Goals During this lab, you will learn how build a script that includes several scenarios that run
consecutively.
Scenario This lab builds on what you learned in JMeter Lab 1-5 – Correlations by taking an advanced,
realistic scenario a step further. In this lab, you will apply your new knowledge of thread groups,
assertions, and so on with additional skills such as incorporating a CSV file. You will also learn
about and apply a Throughput Controller and a Logic Controller while incorporating a BeanShell
Sampler.
Time 30 minutes
2. Select File Save Test Plan As. The Test [Link] window opens.
Check the Run Thread Groups consecutively (i.e. run groups one at a time) check box.
5. Right-click Test Plan and select Add Threads (Users) Thread Group. The Thread Group configuration pane
opens.
Note: If the plugin is not found, click Installed Plugins and verify that it has already been installed and proceed to
the next [Link] the Throughput Shaping Timer checkbox and click Apply Changes and Restart JMeter to
install the plugin.
9. Right-click Thread Group and select Add Timer Throughput Shaping Timer. The Throughput Shaping Timer
configuration pane opens.
10. Click Add Row two times to add two rows to the Requests Per Second (RPS) section.
11. Configure the first row in the Requests Per Second (RPS) section as follows:
Field Value
Start RPS 5
End RPS 5
Duration 300
12. Configure the second row in the Requests Per Second (RPS) section as follows:
Field Value
Start RPS 10
End RPS 10
Duration 300
Complete these steps to add a Throughput Controller that sends 10% of test plan requests to the BlazeMeter
demonstration registration web page and signs up the users:
14. Right-click Thread Group and select Add Logic Controller Throughput Controller. The Throughput Controller
configuration page opens.
16. Right-click Throughput Controller and select Add Sampler HTTP Request. The HTTP Request configuration
pane opens.
18. Right-click HTTP Request and select Add Config Element HTTP Cookie Manager. The HTTP Cookie Manager
configuration pane opens.
21. Right-click HTTP Request and select Add Listener Simple Data Writer. The Simple Data Writer configuration
pane opens.
Note: The Simple Data Writer listener can be used to write the data from a request to a file.
23. Click Configure. The Sample Request Save Configuration window opens.
24. Check the Save Response Data (XML) checkbox and click Done.
25. Click HTTP Request to view the HTTP Request configuration pane.
26. Click the Advanced tab to view the advanced configuration options of the HTTP Request.
27. Check the Retrieve All Embedded Resources checkbox to include all embedded resources when downloading page
content.
29. Click Add five time to add five rows to the Send Parameters With the Request section.
Part 2: Configure a JMeter Test that Applies a Logic Controller and a BeanShell Sampler
36. Right-click Thread Group and select Add Logic Controller Throughput Controller. The Throughput Controller
configuration page opens.
38. Right-click Throughput Controller 50% and select Add Sampler HTTP Request.
40. Right-click HTTP Request and select Add Timer Uniform Random Timer.
The result of setting a Random Delay Maximum of 250ms and a Constant Delay Offset of 750ms is that the maximum
delay will not be longer than one second, the minimum delay will not be less than 500ms, and the average delay will be
750ms.
43. Right-click Thread Group and select Add Logic Controller Throughput Controller. The Throughput Controller
configuration page opens.
45. Right-click Throughput Controller 30% and select Add Logic Controller While Controller. The While
Controller configuration pane opens.
46. Enter ${__javaScript("${color}" != "red" && ${counter} < 30,)} in the Condition (function or variable) field.
Applying this function allows the loop to run thirty times unless the color is red. When the color is red, the function
exits the loop.
47. Right-click While Controller and select Add Config Element Counter. The Counter configuration pane opens.
50. Enter these colors in order with one color per row in Notepad:
51. Select File Save As and enter [Link] in the Filename field.
52. Navigate to the directory that contains the script that you are configuring for this lab, click Save to save the
[Link] file in the same directory, and close Notepad.
Note: You must save the [Link] file to the same directory containing the script that you are creating for this lab
to execute the script properly.
53. Right-click While Controller and select Add Config Element CSV Data Set Config. The CSV Data Set Config
pane opens. This element is used to read lines of content from a comma separated value (CSV) file.
Your CSV Data Set Config configuration should look like this:
55. Right-click While Controller and select Add Sampler BeanShell Sampler.
56. Enter [Link]("Current color is - " + color); in the Script section of the BeanShell Sampler configuration pane.
57. Right-click While Controller and select Add Sampler Dummy Sampler. The Dummy Sampler configuration
pane opens.
58. Enter ${color} - ${__P(instanceId)} in the Name field of the Dummy Sampler. This step pushes the content of the
current line being read in the CSV file to the log file.
60. Right-click Thread Group and select Add Logic Controller Throughput Controller. The Throughput Controller
configuration window opens.
63. Enter these numbers in order with one number per row in Notepad:
64. Select File Save As and enter [Link] in the Filename field.
65. Navigate to the directory that contains the script that you are configuring for this lab, click Save, and close
Notepad.
Note: You must save the [Link] file to the same directory containing the script that you are creating for this lab
to execute the script properly.
66. Right-click Throughput Controller 10% at the bottom of the Test Plan pane and select Add Config Element
CSV Data Set Config. The CSV Data Set Config configuration pane opens.
Your CSV Data Set Config configuration should look like this:
68. Right-click the last Throughput Controller 10% in the Test Plan pane and select Add Sampler BeanShell
Sampler.
69. Add this BeanShell code to the Script field on the BeanShell Sampler configuration pane. This script will write to a
new CSV file called [Link]. It will write the number variable plus one for each loop.
Field Value
Row 1 FileWriter fstream = new FileWriter("/Users/your
username/Downloads/[Link]",true);
Note: Replace your username in the URL with your username as it appears on your local drive
to force the file to download to the Downloads folder on your local drive.
Row 2 BufferedWriter out = new BufferedWriter(fstream);
Row 3 number = [Link]("number");
Row 4 [Link](number + 1);
Row 5 [Link]([Link]("[Link]"));
Row 6 [Link]();
Row 7 [Link]();
70. Right-click Thread Group and select Add Listener View Results Tree. The View Results Tree listener
configuration page opens.
72. Note the test results in the View Results Tree pane.
Note: Each Throughput Controller in this lab is an independent, mini-exercise. To verify that each step was
completed correctly, copy the contents of each Throughput Controller to a new JMeter script under a standard
Thread Group and run it as a separate script.









