To correlate the session ID, you can use the following
-
a Regular Expression Extractor that saves the session ID into a local variable
-
a BeanShell Sampler that calls the "setProperty" function to set the local variable as a global property, so that it can be shared in all thread groups
In the case of PowerServer, the CreateSession request creates the session ID, therefore, you add a Regular Expression Extractor to the CreateSession request to get and save the session ID into a local variable.
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. You can invoke the local variable by typing
${session}
in the requests (bodies and headers).
If you want to make the "session
" variable a global
property that can be accessed by all threads and thread groups, you
can add a BeanShell Sampler or
BeanShell PostProcessor to call the
JMeter "setProperty" function. The "setProperty" function will set the
"session
" variable as a global property. the section called “Modifying the scripts” has instructions for how to add a
BeanShell PostProcessor. This section
will show how to add a BeanShell
Sampler.
To add a BeanShell Sampler, right click on setUp Thread Group, and then select Add > Sampler > BeanShell Sampler.
-
Use the default name or input any name you prefer.
-
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 replace the value
of session ID with the global property
${__property(session,,)}
. For how to find the session ID
in different requests, refer to Where to find
session ID and transaction ID.
Following shows how to correlate the session ID in the ConnectAndCreateTransaction request.
Find the value of session ID in the request (notice that the session ID is an encrypted string before it is correlated with a variable):
Replace it with the global property
${__property(session,,)}
:
When you replay the scripts, and view the response data of CreateSession, the session ID is generated in plain text.
And this session ID is exactly the same one in the subsequent request ConnectAndCreateTransaction.