Outstanding explanation. I've been reviewing all the different approaches to multi-environment testing that people have come up with for Playwright, and I consider this one of the best ones out there. Thank you for creating this tutorial You get a sub!
Thank you so much for the wonderful feedback! This approach also very useful when you have to run test based on parameter and combinations through Jenkins. Like, if environment is qa/prod/staging and suit is sanity/regression and again any parameter based on project need.
Hi Divyansh,Thank you for watching the tutorial and for raising this question. You're absolutely right that the use case for parameterizing the testDir folder wasn't fully explained in this video.The primary purpose of this approach is to address complex, real-world project scenarios where we need to set up tests for specific environments. Additionally, it allows us to run tests based on multiple parameters, such as env=prod and role=admin or role=customer. This enables Playwright to execute scripts specifically for the production environment while targeting workflows relevant to the selected role, as the UI and flow may vary.In summary, parameterizing the testDir folder, along with other parameters, provides the flexibility to run tailored tests for different environments and roles, making it invaluable for managing complex testing scenarios.
so can we store the command < $env:ENV="qa"; npx playwright test > to package.json under scripts{} ? Not quite related to the tutorial but, if we run via Jenkins, will it look under what commands are in package.json scripts{} section ?
Hi ! Yes, you can store the command $env:ENV="qa"; npx playwright test under the scripts section of your package.json, but you need to ensure it's formatted correctly for your operating system. if Windows(powershell) then write like this "scripts": { "qatest": "powershell -Command \"$env:ENV='qa'; npx playwright test\"", "prodtest": "powershell -Command \"$env:ENV='prod'; npx playwright test\"" } if bash(macOS) then write like this "scripts": { "test:qa": "ENV=qa npx playwright test" }.Then just use npm run qatest or prodtest where you wanted to run.While running through jenkins i will suggest you create parameterized jobs and write script to run the jobs then no need of writing commands in package.json like above. simply set environment based parameter like qa, dev, prod and write jenkins script, then run through jenkins job.
I'm not sure what I'm doing wrong. I set the value in the environment variable as shown in the video, but when I try to use it, it comes back as undefined. Do I need to install any packages?
No need to install any packages.it’s only simple typescript syntax.make sure that you have imported all files correctly and whatever name that you have given for environment variables object keys , same you are using in command line.
I believe you have not watched the entire video with attention. Since I haven't used.env files, so no question putting inside the env folder. I'm surprised where you have seen .env file. Its .ts file. I have used object concept from typescript to run test in multiple environment. One of the way I shared with viewer's and its very robust and anyone can use in real time project also, specially if anyone wants to run test based on parameter also instead of specific environment. Also useful while running test in remote machine in docker container on aws triggered via Jenkins parameterization .So you please don't misguide to others by commenting like this
@@EasyQAAutomation Yeah, so that's the point. You don't put ts files in env folder, only .env files...and the way you showed (using ts files) is not at all professional and should never be used in actual projects. There is a difference between actual project and hobby project.
Outstanding explanation. I've been reviewing all the different approaches to multi-environment testing that people have come up with for Playwright, and I consider this one of the best ones out there. Thank you for creating this tutorial You get a sub!
Thank you so much for the wonderful feedback! This approach also very useful when you have to run test based on parameter and combinations through Jenkins. Like, if environment is qa/prod/staging and suit is sanity/regression and again any parameter based on project need.
Excellent video, really very helpful
Thanks. Share with others
Great video.
Thanks!
Why are we parameterizing the testDir pathdid not get the use case for it to make it env specific
Hi Divyansh,Thank you for watching the tutorial and for raising this question. You're absolutely right that the use case for parameterizing the testDir folder wasn't fully explained in this video.The primary purpose of this approach is to address complex, real-world project scenarios where we need to set up tests for specific environments. Additionally, it allows us to run tests based on multiple parameters, such as env=prod and role=admin or role=customer. This enables Playwright to execute scripts specifically for the production environment while targeting workflows relevant to the selected role, as the UI and flow may vary.In summary, parameterizing the testDir folder, along with other parameters, provides the flexibility to run tailored tests for different environments and roles, making it invaluable for managing complex testing scenarios.
so can we store the command < $env:ENV="qa"; npx playwright test > to package.json under scripts{} ? Not quite related to the tutorial but, if we run via Jenkins, will it look under what commands are in package.json scripts{} section ?
Hi ! Yes, you can store the command $env:ENV="qa"; npx playwright test under the scripts section of your package.json, but you need to ensure it's formatted correctly for your operating system. if Windows(powershell) then write like this "scripts": {
"qatest": "powershell -Command \"$env:ENV='qa'; npx playwright test\"",
"prodtest": "powershell -Command \"$env:ENV='prod'; npx playwright test\""
} if bash(macOS) then write like this "scripts": {
"test:qa": "ENV=qa npx playwright test"
}.Then just use npm run qatest or prodtest where you wanted to run.While running through jenkins i will suggest you create parameterized jobs and write script to run the jobs then no need of writing commands in package.json like above. simply set environment based parameter like qa, dev, prod and write jenkins script, then run through jenkins job.
I'm not sure what I'm doing wrong. I set the value in the environment variable as shown in the video, but when I try to use it, it comes back as undefined. Do I need to install any packages?
No need to install any packages.it’s only simple typescript syntax.make sure that you have imported all files correctly and whatever name that you have given for environment variables object keys , same you are using in command line.
You put .env files in env folder. Don't misguide. This is not very professional way to do it.
I believe you have not watched the entire video with attention. Since I haven't used.env files, so no question putting inside the env folder. I'm surprised where you have seen .env file. Its .ts file. I have used object concept from typescript to run test in multiple environment. One of the way I shared with viewer's and its very robust and anyone can use in real time project also, specially if anyone wants to run test based on parameter also instead of specific environment. Also useful while running test in remote machine in docker container on aws triggered via Jenkins parameterization .So you please don't misguide to others by commenting like this
@@EasyQAAutomation Yeah, so that's the point. You don't put ts files in env folder, only .env files...and the way you showed (using ts files) is not at all professional and should never be used in actual projects. There is a difference between actual project and hobby project.