In actual stress testing scenarios, you can extract output parameters from the response of a request and use the extracted information as the input of the next request. You can define multiple output parameters in a single API. This topic describes how to extract output parameters.
Configure output parameters
The following table describes the elements in an output parameter.
Element | Description |
|
Output Parameter Name |
The name of the output parameter. The name can contain letters, digits, underscores (_), and hyphens (-). The name must start with a letter. |
|
Source |
The parsing method of the response. You can select one of the following parsing methods:
|
|
Parsing Expression |
The parsing expression that is used to extract the content that you want to use as the output parameter from the response. |
|
Nth match |
This parameter applies only when Source is set to Body : TEXT. If the parsing expression finds multiple matches, use this parameter to select one. Indexing starts at 0. A negative number, such as -n, selects the nth match from the end. The value must be in the range [-99, 99]. To select a random match, enter random. |
Body : JSON parsing method
The Body : JSON source type supports responses with Content-Type headers of application/json and text/json.
PTS supports both the new and old versions of the JSONPath syntax. To highlight the differences between the new and old versions of JSONPath expressions, the following sections provide the sample JSONPath structure and the syntax and descriptions of JSONPath expressions for both versions.
We recommend that you use the new version of the JSONPath syntax.
JSONPath expressions (new version)
The following sample code provides an example of the new version of the JSONPath structure. The following table describes the syntax and descriptions of the new version of JSONPath expressions.
JSONPath syntax | Description |
$ | The root object. For example, if you specify the |
[num] | Retrieval of an element in an array. The num variable specifies a number. For example, if you specify the |
[num0,num1,num2...] | Retrieval of multiple elements in an array. The num variable specifies a number. In this case, multiple elements in the array are returned. For example, if you specify the |
[start:end] | Retrieval of a range of elements defined by a start element and an end element in an array. For example, if you specify the |
[?(@.key)] | Retrieval of non-empty object attributes. For example, if you specify the |
[?(@.key > 123)] | Retrieval of numeric-type object attributes by a comparison operation. The supported comparison operators include equal to (=), not equal to (!=), greater than (>), greater than or equal to (>=), less than (<), and less than and equal to (<=). For example, if you specify the |
[?(@.key = '123')] | Retrieval of string-type object attributes by a comparison operation. The supported comparison operators include equal to (=), not equal to (!=), greater than (>), greater than or equal to (>=), less than (<), and less than and equal to (<=). For example, if you specify the |
[?(@.key like 'aa%')] | Retrieval of string-type object attributes by a like clause. You can use only a percentage sign (%) as the wildcard. The not like clauses are supported. For example, if you specify the |
[?(@.key rlike 'regexpr')] | Retrieval of string-type object attributes by a regular expression. The Java Development Kit (JDK) syntax is used and the not rlike clauses are supported. For example, if you specify the |
[?(@.key in ('v0', 'v1'))] | Retrieval of object attributes by an in clause. String- and numeric-type objects are supported. The not in clauses are supported. For example, if you specify the |
[?(@.key between 234 and 456)] | Retrieval of object attributes by a between clause. Numeric-type objects are supported. The not between clauses are supported. For example, if you specify the |
length() or size() | Retrieval of the number of elements in an array. For example, if you specify the |
.. | Retrieval of a specific attribute. For example, if you specify the |
* | Retrieval of all attributes in an object. For example, if you specify the |
randomIndex() | Retrieval of a random element in an array. For example, if you specify the |
['key'] | Retrieval of an attribute. For example, if you specify the |
['key0','key1'] | Retrieval of multiple attributes. For example, if you specify the |
The semantics of the $.store.book[0].title and $['store']['book'][0]['title'] expressions are the same.
JSONPath expressions (old version)
The following sample code provides an example of the old version of the JSONPath structure. The following table describes the syntax and descriptions of the old version of JSONPath expressions.
{
"info": "success",
"message": "Succeeded.",
"data": {
"id":13509, "code":0,
"items": [
{"name": "name1", "value": "1234"},
{"name": "name2", "value": "8448"},
{"name": "name3", "value": "1298"},
{"name": "name4", "value": "3049"},
{"name": "name5", "value": "7648"}
]
}
}
Output parameter value | Old version of the parsing expression | New version of the parsing expression (for comparison) |
The value of the info object. |
|
|
The ID value in the data array. |
|
|
The value of the first element in the items array. Relative position is supported. |
|
|
The value of the second to last element in the items array. Relative position is supported. |
| Not supported |
The entire items array. |
|
|
A random element in the items array. |
|
|
Body : TEXT parsing method
The Body : TEXT source type supports any text format and uses a regular expression to extract data. If the regular expression finds multiple matches, you can specify which one to use by its index. The default index is 0, which selects the first match.
The following sample code provides an example API response:
<input name="id" value="34729XXXX">
<input name="token" value="acdfo4dfopasdf44dXXXX">
...
<script>
var planId=4587;
var planId=5689;
var planId=8906;
</script>
|
Desired value |
Parsing Expression |
Nth match |
The value whose name is id. |
| 0 |
The value whose name is token. |
| 0 |
The value of the third PlanID element. |
| 2 |
The value of a random PlanID element. |
| random |
Format conventions:
-
The scan starts from the beginning of the response body. The first value that matches the expression is used, and the scan stops. Therefore, ensure your parsing expression is specific enough to match only the desired value, unless any of the multiple matches is acceptable.
The matching text cannot contain special characters, such as braces ({}) and parentheses (()).
When you use a regular expression to extract information from a JSON response, you do not need to add a space after the colon between the key and value in a key-value pair. You can add a space after the colon between the key and value in each key-value pair to optimize the visual effects of JSON data.
Cookie : K/V and Header : K/V parsing methods
The Cookie : K/V and Header : K/V parsing methods are used to extract the Cookie field and Header field, respectively. You can specify the keys that you want to extract in the parsing expression. For example, if the Cookie field contains token=1234;path=/ and you want to extract the value of the token, enter token in the parsing expression.
Status Code parsing method
You can use the Status Code parsing method to extract the response status codes of requests. In most cases, use this parsing method for check points or conditional jumps. Different page information is returned for different status codes.
Output parameters of JDBC nodes
To extract an output parameter from SQL query results, select the Body : JSON source. The results are structured as the following JSON object:
{
"data": [
{
"Column 1": "value",
"Column 2": "value"
},
{
"Column 1": "value",
"Column 2": "value"
}
...
]
}
For example, the following table describes the SQL query results. Assume that you want to parse the value (name1) in the name column of the first row as the output parameter.
id | name |
1 | name1 |
2 | name2 |
Use the following parsing expression:
$.data[0].nameDebug output parameters
If you cannot determine whether a parsing expression is correct, you can debug the parsing expression and the associated output parameter in scenario debugging. Perform the following steps:
-
On the PTS Scenario page, click Debug at the bottom. In the Debug Scenario dialog box that appears, click the scenario name. In the details pane on the right, select an API and click Click to test the regular expression for the output parameter.
-
In the dialog box that appears, select the source type, enter the parsing expression, specify the nth match, and enter an output parameter name. Click Test Expression. Check the matching result against the response details to verify that the extracted content is correct.
-
To save the configuration, click Sync Output Parameter to add this expression to the API's list of output parameters.
NoteAfter scenario debugging is complete, if you synchronized any output parameters, return to the Scenario settings tab of the stress test. On the Output Parameter Definition tab for that API, you must set a name for the synchronized output parameter.
Example: Configure output parameters
In the financial management business, you want to recommend appropriate services based on the consumption capability of customers. In this case, you must extract the consumption capability level of each customer as the output parameter and use the output parameter to recommend services.
Perform the following steps:
-
Log on to the PTS console, choose , and then click PTS.
-
On the PTS Scenario page, add APIs for retrieving spending power and recommending products. For example, name them Spending Power (with output parameter) and Product Recommendation, and enter their respective URLs.
-
For the Spending Power (with output parameter) API, configure an output parameter to extract the spending power information from the response. Enter an output parameter name (for example,
output) and the parsing expression (for example,data.items[0].value). -
In the lower-left corner of the PTS Scenario page, click Parameter list. On the Custom parameters tab, you can view the output parameter that you created. Click the parameter name (for example,
output) or the copy icon
to copy the parameter reference to your clipboard. -
In the configuration for the Product Recommendation API, go to the Body Definition tab. Paste the copied parameter reference into the body.

You can also edit the body content, such as combining strings, parameters, or functions.