Use of Dynamic Variables in Datadog Synthetic API Tests
In Datadog, Dynamic Variables are placeholders that can be used to reference values obtained from previous steps in your API test or predefined values like timestamp, random values, etc. These can be considered similar to "local variables."
Steps to Use Dynamic Variables:
1. Create a Synthetic API Test:
- Go to Synthetic > API Tests in Datadog.
- Click on Create Test and select API Test.
2. Set Up API Test Steps:
- In the Test Steps, configure the API call you want to test.
- You can define various API requests (e.g., GET, POST, PUT, etc.) and set the request headers, body, and parameters.
3. Use Dynamic Variables:
- Datadog allows you to use dynamic variables within your API test configuration.
Some examples include:
- {{uuid}} : Generates a random UUID for use in API parameters or headers.
- {{timestamp}} : Inserts the current timestamp.
- {{random}} : Generates a random number within a specified range.
Example 1: Using Dynamic Variables with Local Scope
Scenario: send a name field with a timestamp and another name field with a random 5 - Character string, using them as local variables for a POST request.
Step 1: Dynamic Variables
In Datadog, you can use Dynamic Variables like {{timestamp}} or {{random}} directly in the API test configuration. These will serve as your inbuilt variables. Automatically generated by Datadog and can be directly used in test steps.
Step 2: POST Call with name
and timestamp
Endpoint:
https://api.createusers.com/user
Request Type:
POST
Header:
{
"Content-Type": "application/json"
}
Body:
{
"name": "User_{{timestamp}}",
"email": "user_{{timestamp}}@example.com",
"unique_name": "User_{{random | string(5)}}",
"role": "test-user"
}
Another way we can add the timestamp, character and numeric etc
Step 1: Create the Local Variables
I will create a local variable named TESTING and assign it the value timestamp. After saving the local variable, I will use the same variable in the POST call.
Body:
{
"name": "User_{{TESTING}}",
"email": "abc@gmail.com"
"role": "test-user"
}
- {{timestamp}} will be used to generate a dynamic name with the current timestamp.
- {{random | string(5)}} will create a 5-character random string to use for unique_name.
Comments
Post a Comment