Setting Test Case Parameters of an API Script
Background
Proper test design requires that the test logic and test data be separated to maximize the reuse of the test logic and enhance the maintainability and input-to-output ratio of test cases. For example, the URL domain names of different test environments are test data independent of the test logic and related to the test environment. Test case parameters can be used to manage test data.
Parameters of automated API test cases are classified into the following types:
Local Parameters
Local parameters can be used in the current test case. For example, parameters, checkpoints, and variables of test steps can reference local parameters.
Use ${Parameter name} to reference a local parameter, for example, ${hostIp}.
The main configuration items of local parameters are as follows.
Configuration Item |
Mandatory |
Description |
---|---|---|
Name |
Yes |
The value can contain 1 to 300 characters. Only letters, digits, periods (.), underscores (_), and hyphens (-) are supported. |
Type |
Yes |
Supported types: text, random character string, random integer, timestamp, formatted timestamp, UUID, Base64 encoding, MD5 hash value, password or authentication information, and SHA-512 encoding. For details, see Table 2. |
Description |
No |
Brief description of the parameter (current parameter by default). The value can contain up to 3,000 characters. Click the text box to enter the description. Click , enter a JSON string, click JSON Parse to add line breaks and indentation, and click Fill Back. |
Value |
No |
Local parameter values. Assign values to the supported parameter types by referring to Table 2. |
Sensitive |
No |
CodeArts TestPlan encrypts sensitive parameter values during storage and overwrites them with asterisks (*) in test result logs. Sensitive data includes but is not limited to personal and authentication information, such as names, addresses, and usernames. |
Dynamic |
No |
Values of dynamic parameters can be assigned during test case execution. The initial value of a dynamic parameter can be empty. After a value is assigned, the latest value is displayed. Assigning values to dynamic parameters: In the Extract Response tab page of a test step, set the value of the Assign Value to Dynamic Environment Parameter column. The extracted value will be assigned to the dynamic parameter during test execution. |
Name |
Description |
---|---|
Text |
The value can contain up to 10,000 characters. A local parameter of text type can be set to Sensitive and Dynamic, which are not selected by default. |
Random character string |
The system randomly generates a character string of a length from 1 to 9999 digits. The parameter of this type cannot be set to Sensitive or Dynamic. |
Random integer |
The system randomly generates an integer from -999999999 to 999999999. The parameter of this type cannot be set to Sensitive or Dynamic. For example, if this parameter is set to [-9999,9999], a random integer in this range will be generated. |
Timestamp |
The system generates the current integer timestamp. No value needs to be set. The parameter of this type cannot be set to Sensitive or Dynamic. |
Formatted timestamp |
The format is yyyy-MM-dd HH:mm:ss or yyyy-MM-dd. The parameter of this type cannot be set to Sensitive or Dynamic. Example 1: For yyyy-MM-dd HH:mm:ss:33250825252000, the expected value is 3023-09-05 20:20:52. Example 2: For yyyy-MM-dd:33250825252000, the expected value is 3023-09-05. |
UUID |
No value needs to be set. The parameter of this type cannot be set to Sensitive or Dynamic. |
Base64 encoding |
The parameter of this type uses Base64 encoding method. The value can contain up to 256 characters. The parameter of this type cannot be set to Sensitive or Dynamic. |
MD5 hash value |
The system generates an MD5 hash value with the parameters of this type. The value can contain up to 256 characters. The parameter of this type cannot be set to Sensitive or Dynamic. |
Password or authentication information |
The value can contain up to 256 characters. The parameter of this type is set to Sensitive by default and cannot be changed. |
SHA-512 encoding |
The value can contain up to 256 characters. The parameter of this type is set to Sensitive by default and cannot be changed. |
Array |
The value is in JSON format and contains up to 10,000 characters. This parameter cannot be set as sensitive or dynamic. |
To set local parameters, perform the following steps:
- Go to the Scripting tab page and click .
- Click New Variable. Enter the parameter name, type, and value.
After all the parameters are set, click Save.
Built-in Parameters
Built-in parameters are used to parameterize the corresponding part of an HTTP or HTTPS response. You can select built-in parameters from the Source options in the Checkpoints and Response pages.
The following table lists the built-in parameters of CodeArts TestPlan.
Built-in Parameter |
Description |
Multi-level Values Supported or Not |
Function |
Example |
---|---|---|---|---|
Response Body (JSON) |
Response body returned by an API. |
Yes |
|
|
Response Header |
Response header returned by an API. |
Yes |
|
|
Response Code |
Response code returned by an API. |
No |
|
|
Built-in parameters support multi-level values, for example:
- If the response body is {"result":{"appId":12}}, the format of appId is as follows: Source=Response body; Property=result.appId. If the value of result is in array format, Property=result[i].appId, where i is a non-negative integer.
Response Extraction Parameters
Response extraction parameters are extracted from the response body of an API. For details about the definition and usage, see Setting the Response Extraction of an API Script.
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