Latest post from this blog

How to Manage Test Execution Across Different Browsers and Environments (QA, UAT, Staging)

In real-time automation projects, test execution is never limited to a single browser or a single environment . Applications must be validated across multiple browsers (Chrome, Firefox, Edge) and multiple environments such as QA, UAT, and Staging before going live. A well-designed Selenium + Java + Cucumber automation framework should allow testers to switch browsers and environments easily without changing test scripts . This blog explains how to manage test execution efficiently across different browsers and environments using best practices followed in real projects. Why Multi-Browser and Multi-Environment Testing Is Important Different users use different browsers QA, UAT, and Staging environments have different configurations Bugs may appear only in specific environments or browsers Same test cases must be validated everywhere before production release Common Challenges Testers Face Hardcoded browser names and URLs Maintaining separate test scripts for each environment Browse...

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

How to Manage Test Execution Across Different Browsers and Environments (QA, UAT, Staging)

Purpose of the StepData Class in Selenium + Java Cucumber Automation Framework

Ensuring Thread Safety in Parallel Test Execution with Selenium, Cucumber, and Java