Search code examples
playwright

Playwright test runner: Limit test to only one browser with a config file that has many projects


I have a test config file (playwright.config.ts) with many projects.

Usually, I want to test several different browsers.

However, when I'm building a test, I want to only test with a single browser/project (because the test is going to fail while I'm working on it).

I tried this command:

npx playwright test test.ts --browser='chromium'

But I get an error:

Error: Cannot use --browser option when configuration file defines projects. Specify browserName in the projects instead.

How do I "specify browserName in the projects" to limit the tests to running on one browser?

My config file:

const config: PlaywrightTestConfig = {
  projects: [
    {
      name: 'Chrome Stable',
      use: {
        browserName: 'chromium',
        channel: 'chrome',
      },
    },
    {
      name: 'Safari MacBook Air',
      use: {
        browserName: 'webkit',
        viewport: {
          width: 2560,
          height: 1620,
        },
      },
    },
    {
      name: 'Firefox Desktop',
      use: {
        browserName: 'firefox',
        viewport: {
          width: 1920,
          height: 1080,
        },
      },
    },
    {
      name: 'iPhone 6/7/8',
      use: devices['iPhone 8'],
    },
    {
      name: 'iPhone 6/7/8 Plus',
      use: devices['iPhone 8 Plus'],
    },
    {
      name: 'iPhone 12',
      use: devices['iPhone 12'],
    },
    {
      name: 'iPhone 12 Pro',
      use: devices['iPhone 12 Pro'],
    },
    {
      name: 'iPhone 12 Pro Max',
      use: devices['iPhone 12 Pro Max'],
    },
    {
      name: 'iPhone 5/SE',
      use: devices['iPhone SE'],
    },
    {
      name: 'iPad',
      use: devices['iPad (gen 7)'],
    },
    {
      name: 'iPad landscape',
      use: devices['iPad (gen 7) landscape'],
    },
    {
      name: 'iPad Mini',
      use: devices['iPad Mini'],
    },
    {
      name: 'iPad Mini landscape',
      use: devices['iPad Mini landscape'],
    },
    {
      name: 'iPad Pro 11',
      use: devices['iPad Pro 11'],
    },
    {
      name: 'iPad Pro 11 landscape',
      use: devices['iPad Pro 11 landscape'],
    },

Solution

  • When using projects like in your case, you can use the CLI parameter --project or -p to filter by them. For example:

    npx playwright test test.ts --project='Chrome Stable'

    See here for more information.