I am using Playwright with Typescript. I am trying to set sessionStorage and authToken env variables in playwright in a setup step and trying to reuse them in a test project as shown here: https://playwright.dev/docs/test-global-setup-teardown#option-1-project-dependencies
Setup.
- I have a setup project that runs a script to store sessionStorage. Apart from this, I am setting the authToken as “process.env[“ADMIN_ID_TOKEN”] = responseJson.idToken; “.
If I run below command, I see the env variable together with all other env variables.
for (const [key, value] of Object.entries(process.env)) {
console.log(`${key}: ${value}`);
}
If I try to console log process.env after setup, I also see it available in the logs (together with all the other ones I set in this setup.ts file.
- Inside projects, I set it up this “setup” project as dependencies in another project say “chromium”.
The setup file runs and the sessionStorage file is created. Which I can successfully use inside the tests of this project. However when I try to access process.env. ADMIN_ID_TOKEN or any of the other variables I set inside the setup.ts file, all of them come as undefined.
If I run the below command again to print all env variables, I do see all of them as missing.
for (const [key, value] of Object.entries(process.env)) {
console.log(`${key}: ${value}`);
}
I have two questions.
- Why does this happen?
- How can I make this work?
P.S: Coming from a Java world I am still new to the nodeJS landscape, so it’s possible I am overlooking some basic core concept here. All help is appreciated.