In this section, you will learn how to add a setUp Thread Group to configure the pre-test actions (such as creating the session, connecting to the database, starting the transaction etc.).
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 add setUp Thread Group to run the following pre-test actions:
-
Create the user session
-
Connect to the database
-
Start the transaction
Normally the setUp Thread Group runs only once.
This section will reuse the test plan and thread group that was 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:
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.