Playwright - How to work with Multiple Environments!

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ม.ค. 2025

ความคิดเห็น • 63

  • @juanjoarranz8213
    @juanjoarranz8213 ปีที่แล้ว +1

    Many thanks for your wonderful Playwright tutorials.I learnt all Playwright from you !

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว +1

      That's amazing to hear, it's what makes me continue wanting to post videos! Thank you very much for the super thanks, you are my first one😁

  • @la2126
    @la2126 ปีที่แล้ว +2

    I knew you would have the answer Jarad, as always! Exactly what I needed, thank you!

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว +1

      Always glad I can help you :)

  • @LouiseHarney-pb7ms
    @LouiseHarney-pb7ms ปีที่แล้ว +2

    This is really helpful, thank you!

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว

      Not a problem, glad I can help 😃

  • @EwelinaWes
    @EwelinaWes ปีที่แล้ว

    Exactly what I needed! Super simple explained :) Thank You :)

  • @joshuaschuster5867
    @joshuaschuster5867 ปีที่แล้ว +2

    As always great content! Is there any plans to make a video about managing automated test cases? In my work, we find it difficult to actually keep track of our test cases in an Excel sheet to understand our total test coverage. If you made a video on that it could be potentially really helpful to a lot of people :) thank you for these tutorials!

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว +2

      This is a really interesting comment. I can definitely give an example of what I do / what I would do on my test website. I will put something together for this because I really like the idea.

  • @umesh1056
    @umesh1056 ปีที่แล้ว +1

    Please let me know how to integrate with gh actions
    How to store the gh secrets to the variable present in the env files(present in env folder)

  • @ravirajug1137
    @ravirajug1137 6 หลายเดือนก่อน

    nice and detailed and short video. thanks

    • @CommitQuality
      @CommitQuality  5 หลายเดือนก่อน

      Glad it was helpful!

  • @nauta28
    @nauta28 11 หลายเดือนก่อน

    Great stuff, simple and effective. Spent an hour to trying figure this out with some random StackOverFlow comments..

    • @CommitQuality
      @CommitQuality  11 หลายเดือนก่อน

      I'm glad to hear I have helped :)

  • @arunganesh100
    @arunganesh100 11 หลายเดือนก่อน

    Instead of power shell if we use cmd then what command should I use to set the value. Please suggest the command.

  • @skf-sfg-sts-23-ghfj-jfjf
    @skf-sfg-sts-23-ghfj-jfjf 5 หลายเดือนก่อน

    Great video, please consider making another tutorial how to deal with multiple environments and variables in C#.

    • @CommitQuality
      @CommitQuality  4 หลายเดือนก่อน

      Great suggestion!

  • @jeffreydeguzman6385
    @jeffreydeguzman6385 2 หลายเดือนก่อน

    Hi, how can I add the envrioment switching on package.json? for example I want to add this on a variable called "smoke-test= npx playwright test --config=playwright.ts --reporter=list". im just new to playwright and this could help a ton. thanks! :)

  • @gdd546
    @gdd546 8 หลายเดือนก่อน

    thanks, i'm practicing playwright automation and azure pipelines and this was very easy to follow and understand.
    i've set up a practice build pipeline with a custom agent that runs my playwright tests and i have created a release pipeline aswell, but i'm struggling to get my head around how it'll work with azure releases to qa, prod and then uat. im guessing its something to do with the yaml file?

    • @gdd546
      @gdd546 8 หลายเดือนก่อน

      i found it in your azure pipeline video

  • @poosam4065
    @poosam4065 5 หลายเดือนก่อน

    Hi. This is a great video and I learned a lot.
    I have a question. Can we run tests through VS code Test Explorer and pick up the .env file values? Because when I try to do so it always says as undefined.

    • @Macrntree
      @Macrntree 5 หลายเดือนก่อน

      same error )=

    • @poosam4065
      @poosam4065 5 หลายเดือนก่อน

      @@Macrntree no luck yet for me 🙁

    • @Macrntree
      @Macrntree 5 หลายเดือนก่อน

      @@poosam4065 need to install dotenv in your proyect.... then just need import into playwright like this
      require('dotenv').config();
      ... when you create de .env like url or endpoind base in the root of your project and use in spec or page file, You want to import process.env.URL .... the vsCode mark underline error but the scripts will work

    • @poosam4065
      @poosam4065 5 หลายเดือนก่อน +2

      @@Macrntree I was able to resolve this. But not sure whether this is tha correct way.
      dotenv.config({
      path: `./environment-files/.env.${process.env.ENV || 'test'}`,
      });
      So I have set 'test' dotenv file to be default value for ENV if it's undefined. After doing this I was anle to run through Test Explorer.

  • @umskip2779
    @umskip2779 ปีที่แล้ว

    can you set default .env that will be used when not specifying the env when running the tests?

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว +1

      Yes you can do this in the playwright config file. You could set up a const that would say use whatever base env is, and if its empty, set it to something e.g. const defaultEnv = process.env.ENV || 'prod' and then use the const where you define the path of the file. So if my ENV variable is empty, it will take the base version

  • @AparnaKompella
    @AparnaKompella 6 หลายเดือนก่อน

    Hi, what is the error i see in my playwright.config.js file internal error:unable to connect to the test server playwright ? how do i fix it, could you please let know

    • @CommitQuality
      @CommitQuality  6 หลายเดือนก่อน

      Can you share the contents of your config file please

  • @aparnausa3619
    @aparnausa3619 6 หลายเดือนก่อน

    Do you have another video for js for the same topic

    • @CommitQuality
      @CommitQuality  6 หลายเดือนก่อน

      Are there any specific parts that are not working for you via JavaScript, there should be only small differences

  • @pranavpothiwala8091
    @pranavpothiwala8091 9 หลายเดือนก่อน

    Hi you make amazing videos which cleared my many doubts, I have question how can I use this as script in package.json file instead of running in command line I tried to use cross-env but didn't got it if you can share a script would be great thank you in advance

  • @tyexcel2312
    @tyexcel2312 ปีที่แล้ว

    Thanks for this great content.
    Please I have a question, I'm getting this error when I ran this command $env:ENV='local'. I don't have powershell in my terminal as I'm using Mac:
    zsh: command not found: :ENV=local
    Please what can I do. Thanks

    • @18traspie
      @18traspie 11 หลายเดือนก่อน

      for zsh use "export ENV=local"

  • @rexrexnis
    @rexrexnis ปีที่แล้ว

    Thanks for the vid. Nicely explained.
    One question, though. I can easily use the env variables in the test block of code, as presented in the video, but I cannot use them inside the setup code (in the auth.setup.ts file). Returns undefined. Any suggestions? Thanks!

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว +1

      Thank you! Where are you originally creating your variables and are you using the playwright setup approach?

    • @rexrexnis
      @rexrexnis ปีที่แล้ว

      I have them stored in a .env file (just one file, as there is one environment as for now). And as i said, they do work within a test file, but i also need to use them in the authentication setup, which is taken directly from the playwright documentation. And it does work itself (the setup I mean), but at this moment I have the secrets passed as normal strings….

    • @rexrexnis
      @rexrexnis ปีที่แล้ว

      ​@@CommitQualityany advice?;)

  • @vaishalisoni8022
    @vaishalisoni8022 ปีที่แล้ว

    Hi, is there a way to check data of file and then choose which one to use.

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว

      When you say check data of a file, do you mean the content of any file, or a specific one? I have videos on reading from CSV files and soon to be ones from pdfs

    • @vaishalisoni8022
      @vaishalisoni8022 ปีที่แล้ว

      @@CommitQuality I mean we have different env like stage, prod etc and we save json data for each env in each of these files and on the bases of req we call these files.

    • @vaishalisoni8022
      @vaishalisoni8022 ปีที่แล้ว

      Also tried above approach but env variables are not populating.

  • @andibm5623
    @andibm5623 ปีที่แล้ว

    hi, thanks a lot for your video. Is it suppose to work with bush instead of pwsh? I've got such error.
    $env:ENV="deploytest"
    bash: :ENV=deploytest: command not found

    • @7contractors
      @7contractors ปีที่แล้ว

      You have probably forgotten to fix you scripts in package.json

  • @rifattaque7301
    @rifattaque7301 ปีที่แล้ว

    Beautiful content. Could you also please show us how to change the environment file on test run command. I mean is there any way to call the desired env file with 'npx playwright test' so we can avoid switching between the env files before running 'npx playwright test' command? something like-> npx playwright test --env '.env.local'

    • @marko96
      @marko96 ปีที่แล้ว

      Try using bash instead of powershell. The command for bash would be: ENV=local npx playwright test
      The downside is that you have to write ENV=local/prod before executing every test but its still one step less than with using powershell in which you set the env and then run the test.

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว

      What I typically do is run a powershell script.
      Inside the script I can set the env variables I want and the. Also run the npx Playwright test command. I would then execute the powershell script

    • @rifattaque7301
      @rifattaque7301 ปีที่แล้ว

      @@marko96 sounds good, gonna try that. Thanks buddy.

  • @riteshkavankar
    @riteshkavankar ปีที่แล้ว

    Can we hide password in this file, so no other can see it in git commits.

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว

      You may want to look into git secret

    • @riteshkavankar
      @riteshkavankar ปีที่แล้ว

      @@CommitQuality Done👍🏻

  • @Another0neTime
    @Another0neTime ปีที่แล้ว

    Thanks, bud.

  • @AparnaKompella
    @AparnaKompella 6 หลายเดือนก่อน

    i am still seeing undefined after following steps as it is on powershell

  • @webtestingui7187
    @webtestingui7187 ปีที่แล้ว

    Hello,Please share your github url

    • @CommitQuality
      @CommitQuality  11 หลายเดือนก่อน

      github.com/CommitQuality

    • @webtestingui7187
      @webtestingui7187 11 หลายเดือนก่อน

      Thank you @@CommitQuality

  • @kovacstibi9595
    @kovacstibi9595 ปีที่แล้ว +1

    I need a little assistant.
    In terminal I type this: $env:ENV="prod"
    but when I run the basic test and log ENV variable 'console.log(process.env.ENV)' then I got "undefined" result..
    I am bit lost...
    dotenv.config({
    path: `./env/.env.prod`
    })
    -->this works
    dotenv.config({
    path: `./env/.env.${process.env.ENV}`
    })
    this failed...

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว

      What type of terminal are you using?

    • @kovacstibi9595
      @kovacstibi9595 ปีที่แล้ว

      powershell
      but today morning everything works.. bit confused..
      maybe the restart solved... (I am new with typscript/playwright/visual code)
      anyway thanks! your videos are awesome!@@CommitQuality

    • @CommitQuality
      @CommitQuality  ปีที่แล้ว

      The classic turn it off and on again :D Thank you :) @@kovacstibi9595

    • @ramprasadprathapani3578
      @ramprasadprathapani3578 ปีที่แล้ว

      This will help us for undefined in dotenv.config block path: './env/.env.' + process.env.ENV_Test