Updated on 2023-03-14 GMT+08:00

Setting Test Case Parameters

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 API automation 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}.

To set local parameters, perform the following steps:

  1. Go to the Scripting tab page and click .

  2. 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

  • Checkpoint property field.
  • Property field for parameter passing.
  • Checkpoint: Check whether the value of id in the response body is 100.
  • Settings: Set Source to Response body (JSON), Property to id (only if the id field exists in the JSON string), Comparison Operator to Equals (case insensitive), and Target Value to 100.

Response Header

Response header returned by an API.

Yes

  • Checkpoint property field.
  • Property field for parameter passing.
  • Checkpoint: Check whether the value of token in the response header is abcd.
  • Settings: Set Source to Response Header, Property to token (only if token exists in the response header), Comparison Operator to Equals (case insensitive), and Target Value to abcd.

Response Code

Response code returned by an API.

No

  • Property or value of a checkpoint.
  • Property field of a variable.
  • Checklist: Check whether the response code is 200.
  • Settings: Set Source to Response Code, Comparison Operator to Equals, and Target Value to 200.

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 Response Extraction.