Updated on 2024-11-13 GMT+08:00

Generating a Random String of a Specified Length

Function Name

$random_string(intA)

Function Description

Generates a random string of a specified length. Parameter A supports the following types:

  • Numbers
  • Environment parameters
  • Local parameters
  • Other built-in functions

Application Scenarios

The function for generating random strings of a specified length can be used in the following scenarios for API automation:

  • Request URL
  • Request header
  • Request body
  • Checkpoint property
  • if condition
  • for loop interrupt condition

Example

  • Request URL

    As shown in the following figure, the value of test in the request URL is the function for generating random strings of a specified length. Parameter A in the function is 3.

  • Request header

    As shown in the following figure, the value of the string parameter in the request header is the function for generating random strings of a specified length. Parameter A in the function is 3.

  • Request body

    As shown in the following figure, the request body uses the function for generating random strings of a specified length. Parameter A in the function is the binary addition operation $add(2,2).

  • Checkpoint property

    As shown in the following figure, the target value of the checkpoint property result is the function for generating random strings of a specified length. Parameter A in the function is the local parameter test. For details about how to set local parameters, see Local Parameters.

  • if condition

    As shown in the following figure, the target value of the if condition is the function for generating random strings of a specified length. Parameter A in the function is the environment variable status. For details about how to set environment parameters, see Setting Environment Parameters of an API Script.

  • for loop interrupt condition

    As shown in the following figure, the target value of the for loop interruption condition is the function for generating random strings of a specified length. Parameter A in the function is 3.