Parameterization and correlation are required for unique/dynamic values that are generated by the server. In the case of PowerServer, the access token, session ID, and transaction ID are all unique/dynamic values generated by PowerServer at runtime. If you re-play the scripts without first changing the value recorded, the scripts will fail, because the dynamic value generated by PowerServer does not match with the value recorded.
Therefore, after the scripts are recorded, you need to find out all occurrences of the access token, session ID, and transaction ID in the script and replace them with variables.
In some cases, dynamic values also refer to the retrieval arguments, ESQL parameters etc.
To correlate the access token, you can use the following
-
a Regular Expression Extractor that saves the access token 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 GetToken request gets the access token, therefore, you add a Regular Expression Extractor to the GetToken request to get and save the token into a local variable.
A GetToken request will look like this:
To add a Regular Expression Extractor, right click on the GetToken request and then select Add > Post Processors > Regular Expression Extractor.
Specify the Regular Expression Extractor like this.
-
Name of created variable: “token” or any name you prefer
-
Regular Expression: "access_token":"(.+?)"
-
Template: $1$
-
Match No.: 1
The access token will be saved to the “token
”
variable. You can invoke the local variable by typing
${token}
in the requests (bodies and headers).
If you want to make the “token
” 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 can set the
“token
” 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(token,${token},)}
The “token
” variable can be accessed as a JMeter
global property.
Use the Search menu to search
for all occurrences of “access_token” in all thread groups, and
replace the static value of token with the global property
${__property(token,,)}
.
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.
Use the Search menu to search
for all occurrences of “session” in all thread groups, and replace the
static value of session ID with the global property
${__property(session,,)}
.
For example,
Similar to the session ID, you can use the following to correlate the transaction ID:
-
a Regular Expression Extractor that saves the transaction ID to 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 following requests will update/change the transaction ID and contain the new ID in the response body:
-
Connect
-
DisConnect
-
Commit
-
Rollback
When Commit or Rollback failed, the response body will still contain the old transaction ID, which means the old transaction ID is still valid.
In the case of PowerServer, the Connect, DisConnect, Commit, and Rollback request will update/change the transaction ID, therefore, you need to add a Regular Expression Extractor to each of these requests to get and save the transaction ID into a variable.
Let’s take the ConnectAndCreateTransaction request as an example.
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: "transactionid":"(.+?)"
-
Template: $1$
-
Match No.: 1
The transaction ID will be saved to the
“transaction
” variable. You can invoke the local
variable by typing ${transaction}
in the requests
(bodies and headers).
If you want to make the “transaction
” 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 “transaction” 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(transaction,${transaction},)}
The “transaction
” variable can be accessed as a
JMeter global property.
Use the Search menu to search
for all occurrences of “transactionid” in all thread groups, and
replace the static value of transaction ID with
${__property(transaction,,)}
.
If your application uses multiple transactions, then each transaction will have its unique transaction ID. The transactions can be differentiated by their transaction names, and their transaction IDs shall be assigned with different variables, so that each variable will correlate with its own transaction.
Suppose your application has two transactions: SQLCA, and lstr_trans1. You will need to define two variables to store the ID of each transaction.
For transaction name “SQLCA”
-
Add a Regular Expression Extractor to store the ID of the “SQLCA” transaction to a variable. Suppose the variable name is “
transaction
”. -
Add a BeanShell Sampler to call the JMeter “setProperty” function to set the variable as a global property:
${__setProperty(transaction,${transaction},)}
For transaction name “lstr_trans1”
-
Add a Regular Expression Extractor to store the ID of the “lstr_trans1” transaction to a variable. Suppose the variable name is “
trans
”. -
Add a BeanShell Sampler to call the JMeter “setProperty” function to set the variable as a global property:
${__setProperty(trans,${trans},)}
Make sure to replace the transaction ID with the appropriate variable according to the transaction name. (You can use the Search menu to search for the transaction name and then replace its ID with the corresponding variable.)
After execution, you can view the View Results Tree to double check the transaction ID.
For example, in the Connect and Disconnect request pair, the transaction ID should be the same.
There are many ways for JMeter to parameterize the script. In this section, you will learn how to parameterize the retrieval argument using a CSV file.
In this section, you will first need to prepare a CSV file that contains test data for the retrieval argument. Suppose there is only one retrieval argument (so there will be only one column in the CSV file).
Then, you will need to add a CSV Data Set Config element to read the data value from the CSV file:
To add a CSV Data Set Config element, right click on Thread Group, and then select Add > Config Element > CSV Data Set Config.
Specify the CSV Data Set Config like this:
-
Filename: File name and path of the CSV file (if the file is in the bin folder, then enter the filename, or use the full path of the file).
-
Variable name: “value” or input any name you prefer (if there are multiple columns in the CSV file, define multiple variables and separate them with commas “,”)
Now, you can replace the initial value by typing
${value}
in the request.
Another common way to parameterize the script is to use the user defined variables and user parameters.
Unlike CSV Data Set Config which can access an external file, user defined variables and user parameters are used when you have less number of test data, because you need to manually insert the test data.
In user defined variables, only one value can be defined for a variable; in user parameters multiple values can be defined for a variable.
In this section, you will learn how to define the user defined variables and user parameters.
You can define variables in the User Define Variables for Test Plan (then the scope is global) or Thread Group or Sampler (then the scope is local).
For example, select Test Plan, and then input the name and value of the variable.
To add the User Parameters, right click on the Thread Group, and then select Add > Pre Processors > User Parameters.
Suppose you have set the number of users to 3. You can define different test data for the 3 users like this.
Now you can replace the initial value with the user defined variables and user parameters in the request.
Take the Select request as an example.