Setting the Response Extraction of an API Script
Response extraction is to extract a part of the API response result and name it as a parameter for invoking in subsequent test steps. Response extraction needs to be defined in the previous test steps and used in subsequent test steps.
- In the Pre-steps tab page, create the parameters to be passed on the Extract Response tab page. Built-in parameters are used for response extraction. For details, see Built-in Parameters. Response extraction also supports regular expression matching and extracts the return value that matches the given regular expression.
- In subsequent test steps, use ${parameter name} to reference the response extraction created in the previous test steps. This parameter can be referenced in the URL, request header, and request body in subsequent steps. If this parameter is referenced in the request body in JSON format, enclose the parameter with quotation marks. For example:
{ id: "Test case ID" name:"${name}" }
- The response extraction function can obtain strings based on the specified key:value. For details, see Example: Obtaining a String from the Response Body Based on the Specified key:value.
Parameter
Description
Output Parameter
${Output Parameter}, which will be referenced later. The name consists of letters, digits, and underscores (_).
Source
Source of the detected field, such as the response body (JSON), response header, and response code.
Property
Enter $ to invoke global variables, local variables, and built-in functions.
- If the source is a response code, this parameter can be left empty. For details, see Response Code Check.
- If the source is a response header, the property is the name of the field in the response header. For details, see Response Header Check.
- If the source is the response body (JSON), the property can be set in either of the following ways:
- Common extraction expression (not starting with $), for example, item.name.
Obtain the value of a field. Nested values are supported. For details, see Response Body (JSON) Check.
When an array is extracted from the response body, the index can be a number or a key:value expression. For details, see Example: Obtaining a String from the Response Body Based on the Specified key:value.
- JSONPath expression (starting with $. or $[), for example, $.store.book[0].title.
For details, see Example: Obtaining Data from the Response Body Based on JSONPath.
- Common extraction expression (not starting with $), for example, item.name.
Advanced Extraction Type
(Optional) Use the advanced extraction type to assist in extracting response information. If N/A is selected, no additional matching mode is used.
Currently, there are two modes:
- Character string extraction (truncation). For details, see Character String Extraction Description.
- Regular expressions to filter source strings. For details, see Regular Expression Description.
For the advanced extraction type, the string extraction function is preferred. If the function cannot meet the requirements, you can use the regular expression.
Assign Value to Dynamic Environment Parameter
Assigns the value extracted from the response to the dynamic parameter so that the dynamic parameter can be referenced in subsequent tests.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot