Rayrun
← Back to Discord Forum

Project configuration with multiple browsers

jennifer0419posted in #help-playwright
Open in Discord
jennifer0419
jennifer0419

I feel like I'm missing something obvious. I would like to be able to run tests defined in a project with multiple browsers. I cannot do this on the command line:

+ npx playwright test --project=e2e --browser all
Error: Cannot use --browser option when configuration file defines projects. Specify browserName in the projects instead.

But unfortunately, I can only specify one browserName in a project. There are two ways I can think of to address this:

  1. Duplicate projects, one per browser.
  2. Add the browserName attribute with the value set to an environment variable.

Unfortunately, with either approach I need to invoke Playwright once for each each browser, which complicates things when running in CI because I need to either run serially or spin up multiple runners to run in parallel.

What am I missing? Is there a configuration or CLI command for "run tests in this project using multiple browsers"?

This thread is trying to answer question "Is there a configuration or CLI command for running tests in a project using multiple browsers with Playwright?"

6 replies

You use projects to define browsers for testing.

A project is logical group of tests running with the same configuration. We use projects so we can run tests on different browsers and devices.

Look at https://playwright.dev/docs/test-projects

@darill Unfortunately, that is exactly what I'm referring to. I already have multiple projects. I don't want to have to duplicate them for every browser.

{
      name: 'setup',
      testMatch: '**/*.setup.ts',
    },

    {
      name: 'e2e',
      dependencies: ['setup'],
      testMatch: '**/*.spec.ts',
    },

    {
      name: 'e2e-v2',
      dependencies: ['setup'],
      testMatch: '**/*.v2spec.ts',
      use: {
        baseURL: `${process.env.ENV_URL}/v2/${process.env.CUSTOMER}-v2/`,
      },
    },

    {
      name: 'production monitoring synthetic tests',
      dependencies: ['setup'],
      testMatch: '**/*.synthetic.spec.ts',
    },
}

Where is your use: {...devices } to specify the browser?

@jennifer0419: I don't think this is a good practice. Imho projects are meant mainly to configure browsers. In this setup you would have to have projects like "e2e-chrome", "e2e-firefox" etc.

I don't think this is a good practice. Imho projects are meant mainly to configure browsers. In this setup you would have to have projects like "e2e-chrome", "e2e-firefox" etc.

jennifer0419
jennifer0419

I'll go with duplicating, then.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.