In this section, you will learn how to parameterize/correlate the session ID and transaction ID so that they are correlated with the dynamic values instead of static ones. You will learn more about parameterization and correlation for the access token, retrieval arguments, and ESQL parameters in the section called “Parameterization and correlation”.
This section will reuse the test plan and thread group that was just recorded in the section called “Recording scripts automatically (using Recorder)”.
Clean up the recorded test plan by removing any duplicated and unnecessary requests. Suppose the test plan looks like this after cleanup:
Now you will add two other thread groups:
-
setUp Thread Group: contains the pre-test actions such as creating the session, connecting to the database, starting the transaction etc. Normally the setUp Thread Group runs only once.
-
tearDown Thread Group: contains the post-test actions such as committing a transaction, disconnecting from the database, destroying the session etc. Normally the tearDown Thread Group runs only once.
The setUp Thread Group is used when you need to run initial actions to prepare the testing environment, prior to starting your main test. These actions should be configured within the setUp Thread Group and not within the regular Thread Group that you will use for running your load test.
In this guide, you will run the following pre-test actions via setUp Thread Group:
-
Create the user session
-
Connect to the database
-
Start the transaction
To add a setUp Thread Group to the test plan, right click on the test plan that you added just now, and then select Add > Threads (Users) > setUp Thread Group.
Make sure this setUp Thread Group is listed as the first thread group under the test plan, so it starts before the other thread groups. You can drag the item in the tree to adjust its level and order.
You can use the default settings for the setUp Thread Group.
Now you can move (by drag & drop) the following HTTP requests from Thread Group to the setUp Thread Group.
To correlate the session ID, you can first add a Regular Expression Extractor to save the session ID to a local variable; and then add a BeanShell PostProcessor to set the local variable as a global property, so that it can be shared in all thread groups.
To add a Regular Expression Extractor, right click on the CreateSession request and then select Add > Post Processors > Regular Expression Extractor.
Specify the Regular Expression Extractor like this.
-
Name of created variable: "session" or any name you prefer
-
Regular Expression: "sessionid":"(.+?)"
-
Template: $1$
-
Match No.: 1
The session ID will be saved to the "session
"
variable.
To add a BeanShell PostProcessor, right click on the CreateSession request, and then select Add > Post Processors > BeanShell PostProcessor.
Input the following script:
${__setProperty(session,${session},)}
The "session
" variable can be accessed as a
JMeter global property.
Find the session ID in all thread groups, and then replace
the static value of session ID with the global property
${__property(session,,)}
. See Correlating the session
ID for more instructions.
Similar to the session ID, you can first add a Regular Expression Extractor to save the transaction ID into a local variable; and then add a BeanShell PostProcessor to set the local variable as a global property, so that it can be shared in all thread groups.
To add a Regular Expression Extractor, right click on the ConnectAndCreateTransaction request and then select Add > Post Processors > Regular Expression Extractor.
Specify the Regular Expression Extractor like this:
-
Name of created variable: "transaction" or any other name you prefer
-
Regular Expression: 7,0,null,"(.+?)",0,0,null,null],"content
-
Template: $1$
-
Match No.: 1
The transaction ID will be saved to the
"transaction
" variable.
To add a BeanShell PostProcessor, right click on the ConnectAndCreateTransaction request and then select Add > Post Processors > BeanShell PostProcessor.
Input the following script:
${__setProperty(transaction,${transaction},)}
The "transaction
" variable can be accessed as a
JMeter global property.
Find the transaction ID in all thread groups, and then
replace the static value of transaction ID with the global
property ${__property(transaction,,)}
. See Correlating the
transaction ID for more instructions.
The tearDown Thread Group is used to perform post-test actions. These actions should be configured within the tearDown Thread Group and not within the regular Thread Group that you will use for running your load test.
In this guide, you will run the following post-test actions via tearDown Thread Group:
-
Commit the transaction
-
Destroy the user session
To add a tearDown Thread Group to the test plan, right click on the test plan that you added just now, and then select Add > Threads (Users) > tearDown Thread Group.
Make sure this tearDown Thread Group is listed after Thread Group, so it starts when Thread Group has finished.
You can use the default settings for the tearDown Thread Group. Normally the tearDown Thread Group runs only once.
Now you can move (by drag & drop) the following HTTP requests from Thread Group to the setUp Thread Group.
You can first add a Regular Expression Extractor to save the transaction ID into a local variable; and then add a BeanShell PostProcessor to set the local variable as a global property, so that it can be shared in all thread groups.
To add a Regular Expression Extractor, right click on the CommitAndCreateTransaction request and then select Add > Post Processors > Regular Expression Extractor.
Specify the Regular Expression Extractor like this:
-
Name of created variable: "transaction" or any other name you prefer
-
Regular Expression: 9,0,null,"(.+?)",0,0,null],"content
-
Template: $1$
-
Match No.: 1
The transaction ID will be saved to the
"transaction
" variable.
To add a BeanShell PostProcessor, right click on the CommitAndCreateTransaction request and then select Add > Post Processors > BeanShell PostProcessor.
Input the following script:
${__setProperty(transaction,${transaction},)}
The "transaction
" variable can be accessed as a
JMeter global property.
Find the transaction ID in all thread groups, and then
replace the static value of transaction ID with the global
property ${__property(transaction,,)}
. See Correlating the
transaction ID for more instructions.
After moving requests to the setUp Thread Group and the tearDown Thread Group, now the regular Thread Group contains only one RetrieveWithParm request.
Go to the Body Data of the RetrieveWithParm request, and make sure the session ID and the transaction ID are replaced with the global property:
${__property(session,,)}
${__property(transaction,,)}
Configure the Thread Group according to your needs.
For example, set the number of users to 100, ramp-up period to 50 seconds, which means 2 requests are made in every second (set ramp-up to 0 will start all 100 users at one time). Set loop count to infinite and duration to 86400 seconds, which means the test will be run repeatedly in 24 hours.