Latest post from this blog

Test Scenarios vs. Test Cases: Understanding the Basics

What Are Test Scenarios Test scenarios represent high-level ideas or conditions that need to be validated to ensure the application works as expected. They provide a broader perspective and are typically used during the test planning phase. Purpose: To capture the "what to test" without going into granular details. Example of a Test Scenario: Verify that a user can successfully log in to the application using valid credentials. Verify the behavior of the login page when invalid credentials are entered. Verify the application behavior when the login button is clicked without entering any credentials. What Are Test Cases Test cases are detailed documents that define the specific steps to execute a test. They cover inputs, execution steps, expected results, and actual outcomes. Purpose: To guide the tester step-by-step on "how to test." Example of a Test Case (for the first scenario): Test Case ID TC_01_Login_Valid_Credentials Test Scenario Verify user login with val...

How to Use Global Variables in Datadog

How to Use Global Variables in Datadog API Tests

1. Access an Existing API Test

  • Navigate to the Synthetic Monitoring section in Datadog.
  • Open the API Tests tab and select an existing test or create a new one.

2. Reference the Global Variable in Test Steps

  • When configuring the test steps, you can use global variables in fields such as:
    • URL: For endpoints, reference variables like {{baseURL}}.
    • Headers: For dynamic data like API keys, reference variables like {{apiKey}}.
    • Body Payload: Use variables in JSON or other payload formats for dynamic values.

3. Syntax for Using Global Variables

  • Global variables are referenced using double curly braces: {{variableName}}.
  • Example:
    json
    {
    "url": "{{baseURL}}/endpoint",
    "headers": {
    "Authorization": "Bearer {{apiKey}}"
    },
    "body": {
    "userId": "{{userId}}"
    }
    }

4. Validate the Test Setup

  • After adding the global variables, preview the API test to ensure the variables resolve correctly.
  • If the variable is not set for the environment, you will see a placeholder or error.

5. Test Across Environments

  • Ensure your test dynamically resolves the global variable values based on the selected environment (e.g., dev, staging, prod).
  • Example:
    • Dev Environment: {{baseURL}} = https://dev.example.com
    • Prod Environment: {{baseURL}} = https://api.example.com

6. Use Variables in Assertions

  • You can also use global variables in assertions to validate expected responses.
  • Example Assertion:
    • Expected response contains {{expectedStatusCode}}.

7. Update and Reuse Variables

  • If a global variable value changes (e.g., apiKey expires), update it in the Global Variables section, and all associated tests will automatically use the updated value.
Example API Test Using Global Variables


  1. Global Variables Created:

    • baseURL = https://api.example.com
    • apiKey = abc123xyz
  2. Test Configuration:

    • Request URL: {{baseURL}}/users
    • Headers:
      json
      {
      "Authorization": "Bearer {{apiKey}}",
      "Content-Type": "application/json"
      }
  3. Response Assertion:

    • Expected statusCode: {{expectedStatusCode}}

Using global variables in this way enhances the flexibility and maintainability of your API tests in Datadog

Comments

Popular posts from this blog

Common Exception in Selenium

Test Scenarios vs. Test Cases: Understanding the Basics

Handling Shadow DOM in Selenium WebDriver

Handling HTTPS Websites and SSL Certificate Errors in Selenium

Normalize-space Function In Xpath