Rayrun
← Back to Discord Forum

Handling high amount of env variables.

mjeziorkowskiposted in #help-playwright
Open in Discord
mjeziorkowski
mjeziorkowski

Hi! I need to handle a lot of env variables. I have 3 environments and I need to store in them sensitive information - like passwords, tokens, app secrets. I'm working on proof of concept for my team and I'm looking for solutions that we can review. Thanks

This thread is trying to answer question "How can I handle a large number of environment variables, particularly for storing sensitive information?"

3 replies

https://www.vaultproject.io vault could be used if it's already used in your company

if not, then it's probably not worth it

Answer

Managing Environment Variables in @playwright/test

You can manage a large number of environment variables in @playwright/test in several ways.

Using Command Line Arguments

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

Using Configuration Files

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/',
  },
});

Using .env Files

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/',
  },
});

Using CSV Files

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.

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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].