This thread is trying to answer question "How can I handle a large number of environment variables, particularly for storing sensitive information?"
I found this solution, but looking for other alternatives https://dev.to/playwright/a-better-global-setup-in-playwright-reusing-login-with-project-dependencies-14
https://www.vaultproject.io vault could be used if it's already used in your company
Related Ask AI answer for "How can I manage and securely store a large number of environment variables in @playwright/test?".
You can manage a large number of environment variables in @playwright/test in several ways.
One way is to use command line arguments when running tests. For instance, you can pass the secret username and password like this:
USERNAME=me PASSWORD=secret npx playwright test
Another way is to use a configuration file, such as playwright.config.ts
. Here, you can define different configurations for each environment.
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
baseURL: process.env.STAGING === '1' ? 'http://staging.ray.run/' : 'http://ray.run/',
},
});
To make managing environment variables easier, consider using .env
files. You can use a package like dotenv
to read these variables directly in your configuration file.
import { defineConfig } from '@playwright/test';
import dotenv from 'dotenv';
import path from 'path';
dotenv.config();
dotenv.config({ path: path.resolve(__dirname, '..', 'my.env') });
export default defineConfig({
use: {
baseURL: process.env.STAGING === '1' ? 'http://staging.ray.run/' : 'http://ray.run/',
},
});
Lastly, you can use a CSV file to store and manage your environment variables. Since Playwright runs in Node.js, you can directly read files from the file system and parse them with your preferred CSV library.
These approaches provide effective ways to handle a large number of environment variables across multiple environments while ensuring sensitive information is securely stored.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].