dotenv configuration (loads environment variables) - IvanBezrukavyi/ts-playwright GitHub Wiki

Step 1: Install Playwright and dotenv packages

npm install playwright dotenv

Step 2: Create a .env file in the root directory of your project

Add the following environment variable to the .env file, e.g.: AUTH_FILE=./srs/auth/defaultStorageState.json

Step 3: Import dotenv and access environment variables

Import dotenv and access the AUTH_FILE environment variable in your playwright.config.ts file, e.g.:

import { defineConfig, devices } from '@playwright/test';
import dotenv from 'dotenv';

dotenv.config();
const authFile = process.env.AUTH_FILE || "./srs/auth/defaultStorageState.json";

Review and update property in playwright.config.ts file in general