Environment Variables | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Test Management
Instructor: Artem Bondar
Lesson Summary
In this lesson, we discuss environment variables and how to manage them effectively in your project. Environment variables allow you to configure different settings for various environments, such as development , QA , and production . Key Concepts Environment Variable Configuration: Use a variable like testenv to switch between environments. Security for Credentials: It's crucial to keep sensitive information, like usernames and passwords, secure, especially in production. Options for Managing Environment Variables Create a .env file to store variables locally. Pass variables via the command line during test execution, which is useful for CICD processes. Setting Up the .env File To create a .env file: touch .env Ensure to add it to your .gitignore to prevent accidental exposure: .env Reading Variables in TypeScript Install the .env package to read the variables: npm install dotenv --save-dev Define your variables in the .env file: [email protected] prod_password=prod_pass_123 Access these variables in your TypeScript code using process.env . Command Line Usage To pass environment variables via the command line: [email protected] prod_password=prod_pass_123 npx playwright test This method overrides values in the .env file, making it suitable for secure execution in CICD pipelines. This lesson covers how to manage and utilize environment variables effectively in your framework. See you in the next lesson!