Become a JMeter and Continuous Testing Pro

Start Learning

Test Your Website Performance NOW! |

arrowPlease enter a URL with http(s)

Creating Realistic Test Scripts - What Inquiring Minds Need to Know

Generally, we discuss using different elements of JMeter. But often, JMeter is used for implementing more complex tasks.

So today, we'll show you how to create an entire script.

For script creation, we've used the Mantis bug tracker as an application under test. it's been set up at a local web-server to avoid the influence of network connections. In other words, we only want to see the behavior of the application itself.

So, what's our use case? We're testing a bug tracking system. Our supposed users are project managers that create and delete projects. To better follow along, we suggest a quick, local Mantis BT set up so you can replicate the scenario.
Mantis BT is an open source application.
Let’s jump right in:

Loading the Main Window of the Application.

 Loading main window of application.


Switch to the “Manage” Tab.

Switching to the “Manage” tab.


Switch to the “Manage Projects” Page.

 Switching to the “Manage projects” page.


Create A New Project.

Creating a new project
In general, the app interface is very simple. The operation of a project deletion is nearly the same, just go to a particular project and press the “Delete” button.

Two Thread Group Test Scenarios: Creators and Deleters.

Our test scenario will also contain the “Action Storage” Thread Group. As seen below, the “Action Storage” Thread Group is disabled, which means it cannot run.
We use it to store pieces of script that can be used via Module Controllers in other active Thread Groups.
This is what we will have at the end (collapsed):
Store pieces of script that can be used via Module Controllers in other active Thread Groups
We've used the support elements: HTTP Request Defaults, User Defined Variables and the HTTP Cookie Manager.
HTTP Request Defaults
HTTP Request Defaults
We've selected a “localhost” because we have installed Mantis BT locally.
User Defined Variables:
User Defined Variables
Full URL to Mantis -> http://localhost/mantisbt/login_page.php
So, the “localhost” is placed into the HTTP Request Defaults. “mantisbt” is defined as JMeter variable PATH. The last part is the precise path-to-page that we need. 
HTTP Cookie Manager: We need this element to perform a login operation only once per test execution. As you know, it should be used for storing cookies and we don't mean in the cookie .jar.

“Creators” Thread Group

This group is responsible for creating projects. 
“Creators” Thread Group
Note that the “Login to Mantis” operation consists of two sub-items: “Open Login Page”(2.1.1) and “Login as Administrator” (2.1.2)
“Open Login Page” is Module Controller.
Open Login page is Module Controller
It is linked to “Open Login Page” in “Action Storage”.
“Open Login page” in “Action Storage”.
As you see, it includes HTTP Request to login_page.php and HTTP Header Manager. Nothing difficult.
Next step. “Login as administrator” (2.1.2). 
It is Parametrized controller, note that this is NOT the default element for JMeter, but a part of a Google Plugins project.
Parametrized Controller
Here we added two parameters for login operations to Mantis BT. 
                  - username = administrator
                  - password  = root
It has a child element, “Login as Administrator”(
Login as administrator
It refers to “Action Storage”->”Login(username, password)”
“Action Storage”->”Login(username, password)”
Here we transfer parameters from “Login as Administrator” Parametrized controller.
Then we have another request with parameters that should be displayed.
Login as administrator
Third request in this controller does not have any parameters.
The main part of “Creators” Thread Group IS “Creating project” in the Module Controller. 
 parameters that should be displayed
Create project -> Module Controller.
It contains 6 HTTP Request samplers.
Let’s walk through each of them to review details.
HTTP Request samplers
“manage_overview_page.php” and “manage_proj_page.php” do not contain any parameters.
The next piece of script is very important. Here we will use correlation.
Note that “manage_proj_create_page” does not take any parameters. However, this request is key in the creating project process. If you open its HTML code, you will see that it has a hidden field “manage_proj_create_token”.
We need to capture this value and transmit it further because we won’t be able to create project without it.
Transmitting values from  one request to another is called correlation.
So, the Regular Expression Extractor is what we need. Let’s look into it.
Regular Expression Extractor
Here we see that the value needed is stored in variable ${manage_proj_create_token}. Go further, the value we’ve captured earlier is used in POST request.
POST request
And now we’ve come to last request in this group.
last group request POST
Here is full list of parameters:
  • manage_proj_create_token = ${manage_proj_create_token}
  • name = ${__Random(0,1000000)}
  • status = 50
  • view_state = 10
  • inherit global = on
  • file_path = 
  • description = ${__RandomString(15,sdKSDJHGKJHGlkjhalkjdhlkjhqoieuroqiuery)}
After that we have a simple GET request
GET request
Let’s go to the second part of script.

“Deleters” Thread Group 

Deleters Thread Group

There is no need to describe the “Login Once Only” element with its tree, because it is the same as in “Creators” Thread Group.
The key differences are in “Deleting project” module controller. So, let’s turn to Action Storage and see the details.
Action Storage Details
“manage_proj_page.php” request has no interest for us as a standalone request because it is an empty GET request. But we do need to extract the "project_id" that we want to delete.
So, for this purpose we will use the Regular Expression Extractor. 
Using JMeter variables, we’ll pass “project_id” to “manage_proj_edit_page” as a parameter for POST Request.
POST Request
And again, we need to extract the hidden value, “manage_proj_delete_token”.
Now, we are ready for the deletion project.
Send “manage_proj_delete” POST request.
It has the following parameters:
“manage_proj_delete_token” = ${manage_proj_delete_token}
“project_id” = ${project_id}
The next POST request is almost the same, but it has additional parameter “_confirmed”=1
The last request is simple GET request, which returns us page with the list of projects, “manage_proj_page.php”
Viewing this example should help you create your own test scripts. If you need an expert to create them for you, BlazeMeter has a team of scripting experts who can help.
arrowPlease enter a URL with http(s)

You might also find these useful:

Interested in writing for our Blog?Send us a pitch!