API Configuration File | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Building a Framework
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore how to create a configuration file to manage various variables within our testing framework efficiently. This approach centralizes values, making it easier to maintain and update them across multiple tests. Key Concepts Centralized Configuration: Instead of hardcoding values like email credentials and base URLs in multiple places, we create a single configuration file. File Creation: A new file named apitest.config.ts is created to store all configuration variables. Configuration Object: We define a constant config as an object to hold our variables, such as APIURL , userEmail , and userPassword . Using the Configuration To utilize these values in tests: Import the configuration file in the test or create a fixture that imports it. Access variables using config.userEmail and config.userPassword in the test files. Environment Management We can also manage different test environments (e.g., dev, QA, prod) by: Using process.env to read environment variables from the command line. Creating logic to switch credentials based on the selected environment. Logging the current environment to the console for visibility. Command Line Usage To run tests in different environments, use: testenv=dev npx playwright test smoke test.spec.ts For Windows, the command differs: set testenv=QA && npx playwright test smoke test.spec.ts In summary, we established a centralized configuration system that simplifies managing static values and supports switching between different test environments seamlessly.