Adding Request Information (Response Extraction)
For example, in an e-commerce flash sale scenario, after you search for a product and purchase it, you can use the response extraction function to extract the product ID obtained from packet search and use the ID as the input parameter of the next purchase packet.
- Cross-case extraction is not supported. That is, the output extracted from case A's packet cannot be used for the input of case B's packet.
- The variables from a response extraction are local variables.
Procedure
- Log in to the CPTS console and choose CPTS Test Projects in the left navigation pane.
- Locate a CPTS test project to be edited and click Edit Test Task.
- On the Test Tasks tab page, expand a task, expand the test case to which you want to add request information, and click Add Request.
- Select Response Extraction for Request Composition and configure the other parameters by referring to Table 1.
Table 1 Response Extraction parameters Parameter
Description
Response Extraction
After response extraction is enabled, if multiple packets exist in the same case, you can use regular expressions to extract the output of the previous packet for the input of the next packet.
Variable Name
The name must be unique. The value of the response extraction is assigned to this variable.
Expected Value
Expected variable value of the response extraction.
When the function is enabled, the response extraction value is compared with the expected value. If they are different from each other, the URL verification will fail.
Extraction Range
Range of the content to be extracted.
The Packet content, Header, and URL can be extracted using regular expressions.
Regular Expression
A regular expression specifies a type of logical expressions performed on strings. In a regular expression, you use certain predefined strings and a combination of these strings to form a rule string used to specify filtering logic.
A complete regular expression consists of two types of characters: special characters (also called meta characters) and literal or common text characters (such as letters, numbers, and underscores). For details about meta characters, see Regular Expression Metacharacters.
NOTE:() indicates extraction. Enclose the content to be extracted in parentheses. The content between each () indicates a sub-expression.
Sequence Number of Matching Item
This parameter indicates the sequence number of the matched content extracted through a regular expression.
Value range: positive integer
NOTE:This parameter cannot be set to 0.
Expression Value
This parameter indicates the sequence number of the parsed sub-expression.
Value range: natural number
NOTE:- Value 0 indicates that the entire regular expression is matched.
- Value 1 indicates that the first sub-expression of the regular expression is matched, that is, the content extracted by the first "()".
After extracting content through Regular Expression and Sequence Number of Matching Item, use Expression Value to obtain the final content.
Key Name
Enter the key name to be obtained.
For example, {"key":{"key1":"v1","key2":{"key3":"v3"},"key4":[{"key41":"v41","key42":"v42"},{"key41":"v43","key42":"v44"}]}}. If you want to obtain v42, enter key.key4[0].key42.
NOTE:This parameter is valid only when the Extraction Range is Parameter values in .json files.
Default Value
Indicates the value extracted when a regular expression match or JSON extraction fails.
Condition Expression
This parameter is used together with the Key Name to be obtained.
For example, {"key":{"key1":"v1","key2":{"key3":"v3"},"key4":[{"key41":"v41","key42":"v42"},{"key41":"v43","key42":"v44"}]}}. If you want to describe that when key42 is equal to v42, extract the target value v41, you can enter key.key4[].key42 = v42 in the Condition Expression box, and enter key.key4[].key41 in the Key Name box.
Table 2 Common regular expressions Regular Expression
Description
Example
(\d+)
Matches non-negative integers.
String:
bTivm2wu9jih1LBKR4osZGrjjlMatch results:
2914([A-Za-z]+)
Matches a string of letters.
String:
bTivm2wu9jih1LBKR4osZGrjjlMatch results:
bTivmwujihLBKRosZGrjjl([A-Za-z0-9]+)
Matches a string of digits or letters.
String:
bTivm2wu9jih1LBKR4osZGrjjl:asdasd22Match results:
bTivm2wu9jih1LBKR4osZGrjjlasdasd22(\w+)
Matches a string of digits, letters, or underscores (_).
String:
bTivm2wu9jih1LBKR4osZGrjjl:asdasd22Match results:
bTivm2wu9jih1LBKR4osZGrjjlasdasd22([\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+)
Matches email addresses.
String:
bTivm2wu9jih1LBKR4osZGrjjl:abc@abc.comMatch results:
abc@abc.com - (Optional) A request can contain one or more variables. If you need to add multiple variables for a request, click Add Variable and set related parameters.
- When the configuration is complete, click OK.
Response Extraction Example 1
The response content of the previous packet is as follows:
Figure 1 Packet content

To extract the token value, use the regular expression "token"\s*:\s*"(.*?)"..
Response Extraction Example 2
The response content of the previous packet is as follows:
javawind:9javawind:12javawind:16javawind:17javawind:46javawind:22
To extract the value 16, see the response extraction settings as follows:
- The following data is extracted using the regular expression javawind:(.*)javawind:(.*).9 1216 1746 22
- The following data is extracted using the second matching item.16 17
- The following data is extracted using the first expression.16
- Procedure
- Response Extraction Example 1
- Response Extraction Example 2