Closed Antoine-Regembal closed 11 months ago
Does your dotenv have to be specified in the package.json? I load my dotenv at the top of my playwright.config.ts
. Would that work for you? See https://stackoverflow.com/questions/70861292/playwright-tests-using-variable-from-env-file.
Hi @gofr
I updated my playwright.config.ts
file like so:
import dotenv from "dotenv";
import path from "path";
dotenv.config({ path: path.join(process.cwd(), ".env.test") });
....
It works well, I didn't think about it
Thank you 🥂
This was a helpful thread, thanks!
Hi @gofr
I updated my
playwright.config.ts
file like so:import dotenv from "dotenv"; import path from "path";
dotenv.config({ path: path.join(process.cwd(), ".env.test") });
.... It works well, I didn't think about it
Thank you 🥂
You can also now natively achieve the same:
import process from 'node:process';
try {
process.loadEnvFile(`${import.meta.dirname}/.env`);
} catch {
console.log('No .env file found');
}
Context:
Code Snippet
package.json scripts
Describe the bug
Hello people of Playwright,
In my application I need to use a different .env file for testing my application. I use the
dotenv
package to define a.env.test
(as you can see in the code snippet) file that my application should use to launch for testing. When I launch tests with CLI it works perfectly, but the Playwright for VSCode extension doesn't follow this script obviously and I was not able to find a way to ask Playwright for VSCode extension to launch tests with the.env.test
file instead of the.env
for the environment variables.Is there any way to achieve that ? That would be great for me to be able to launch tests with the extension
Cheers 🥖