First, create a .env
file in your project directory and set your email variable, like so: [email protected]
.
Next, in your playwright.config.ts
file, import and configure the dotenv
package to read the .env
file:
import dotenv from 'dotenv';
import path from 'path';
dotenv.config();
dotenv.config({ path: path.resolve(__dirname, '..', '.env') });
In your configuration options, you can now access your environment variables using process.env
:
export default defineConfig({
use: {
baseURL:
process.env.STAGING === '1'
? 'http://staging.ray.run/'
: 'http://ray.run/',
email: process.env.EMAIL,
},
});
When you run your tests with npx playwright test
, Playwright will use the updated values from the .env
file.
Alternatively, you can set environment variables directly in your command line:
[email protected] npx playwright test
This will override the .env
file. Playwright provides multiple ways to set and update environment variables, so choose the method that suits your needs best.
If you still have questions, please ask a question and I will try to answer it.
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].