Skip to Content
E2E Test AutomationAPI Environment Variables and Datasets

E2E Test Automation Environment Variables and Datasets

Managing API Environment Variables at the Collection Level

Environment Variables in E2E test automation allow you to define and manage configuration values at the API collection level. These variables help maintain flexibility when testing APIs across different environments such as Development, Staging, and Production.

Collection-level environment variables centralize configuration settings that can be reused across multiple requests, ensuring consistency and simplifying test maintenance.


What Are Environment Variables at the Collection Level?

Environment variables at the collection level are key–value pairs used to store configuration data that can be referenced throughout an entire collection.

Common examples include:

  • Base URLs
  • Authentication tokens
  • Session IDs
  • Environment-specific parameters

Key Advantages

  • Centralized Configuration: Update values once and reuse them across all requests.
  • Environment Flexibility: Easily switch between Development, Staging, and Production.
  • Consistency: Maintain uniform configuration across all API tests.

How Environment Variables Work at the Collection Level

1. Create Collection-Level Environment Variables

Define variables that are available to every request in a collection. Example:

base_url = https://dev.api.example.com

2. Reference Variables in API Requests

  • In URL
{\{base_url\}}/users?id=1
  • In Headers
Authorization: Bearer {\{access_token\}}
  • In Request Body
{ "session_id": "{\{session_cookie\}}" }

3. Switch Between Environments

Select different environments to automatically apply the correct values for URLs, tokens, and credentials.

4. Maintain Configuration Consistency

Update a variable once and the change reflects across all requests using it.


Managing Environment Variables at the Collection Level

Creating an Environment

  1. Navigate to API Env Variables in E2E test automation.
  2. Click the “+” button to create a new environment.
  3. Provide a name such as Development, Staging, or Production.
  4. Define variables:
    • base_url
    • access_token
    • session_cookie
  5. Click Save to store the environment.

Using Variables in API Requests

Example: Base URL

{\{base_url\}}/users?id=1

Example: Authorization Header

Authorization: Bearer {\{access_token\}}

Example: Request Body

{ "session_id": "{\{session_cookie\}}" }

Switching Between Environments

Before executing tests:

  1. Select the desired environment from the Environment dropdown.
  2. E2E test automation automatically applies environment-specific values to all requests.

Benefits of Collection-Level Environment Variables

  • Centralized Management: One place to manage all configuration values.
  • Easy Environment Switching: No manual updates per request.
  • Reduced Errors: Consistent values across tests.
  • Improved Test Scalability: Ideal for large and complex API collections.

Conclusion

Collection-level environment variables in E2E test automation simplify configuration management, improve consistency, and make it easy to run the same tests across multiple environments. By centralizing environment-specific data, teams can build more reliable, scalable, and maintainable API tests.


API Environment Variables and Datasets | Documentation