skip to Main Content

May I know what is the equivalent of the cypress.env() in playwright.

We have below line of code in yml file in Cypress

CYPRESS_test_suite: 'Smoke tests'

Then in 1 of our spec file we have this line of code

const test_suite = Cypress.env('test_suite')

I would like to do it also in playwright but I am not able to find any references.

2

Answers


  1. According to docs, you can use process .env variables:

    const test_suite = process.env.VARIABE_NAME // e.g. 'test_suite'
    

    or

    const test_suite = process.env.CYPRESS_VARIABLE_NAME
    

    if you want to use the variable from cypress env

    Login or Signup to reply.
  2. If you are trying to tag your tests, for example as a ‘smoke_test’, Playwright has other ways to support this beyond process.env.{variable} with the tag attribute.

    test('user can login', { tag: ['@smoke', '@e2e' ] }, async ({ page }) => {
      // write test });
    });
    

    which can then be ran with

    npx playwright test --grep @smoke

    and will be appropriately tagged for filtering in subsequent test reports.

    This is available in Playwright versions >= 1.4.2.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search