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

6

8

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'],
    },
Narrate answered 23/6, 2021 at 12:38 Comment(0)
K
9

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.

Kattiekatuscha answered 23/6, 2021 at 16:3 Comment(1)
$ npx playwright test -p chromium gives error: unknown option '-p' in "@playwright/test": "^1.43.1".Balaam
Z
4

In my case,

npx playwright test --project='chromium'

did the trick

Zinkenite answered 1/5, 2023 at 12:31 Comment(0)
M
0
 "scripts": {
    "test:chrome": "npx playwright test --headed --project=chromium",
    "test:firefox": "npx playwright test --headed --project=firefox",
    "test:safari": "npx playwright test --headed --project=webkit"
  },
Munniks answered 28/8, 2024 at 19:39 Comment(0)
E
-1

you can comment out this as well to run your test only on chromium.

{ name: 'Safari MacBook Air', use: { browserName: 'webkit', viewport: { width: 2560, height: 1620, }, }, }, { name: 'Firefox Desktop', use: { browserName: 'firefox', viewport: { width: 1920, height: 1080, }, }, },

Erleneerlewine answered 11/5, 2022 at 23:12 Comment(0)
A
-1

As per the latest spec, you have to use --project='desktop-chromium'

Announce answered 23/2, 2024 at 1:9 Comment(1)
Do you have a source for that? I already defined the projects in the question, and that's not one of the defined project names...Narrate
H
-1

As of Playwright 1.43.1

playwright-component-testing.config.ts:

// ...more config code
  /* Configure projects for major browsers */
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        contextOptions: {
          permissions: ['clipboard-read', 'clipboard-write'],
        },
      },
    },
    {
      name: 'firefox',
      use: {
        ...devices['Desktop Firefox'],
        launchOptions: {
          firefoxUserPrefs: {
            'dom.events.asyncClipboard.readText': true,
            'dom.events.testing.asyncClipboard': true,
          },
        },
      },
    },
    {
      name: 'webkit',
      use: { ...devices['Desktop Safari'] },
    },
  ],
// ...more config code

Terminal:

karl ~/development/test/packages/react [1194-needle-audit] $ npx --no playwright test -c playwright-component-testing.config.ts audit --workers 1 --project='desktop-chromium'
Error: Project(s) "desktop-chromium" not found. Available projects: "chromium", "firefox", "webkit"


To open last HTML report run:

  npx playwright show-report

I can indeed say the argument that works is: --project='chromium' for the given configuration file.

Hamill answered 14/5, 2024 at 23:8 Comment(2)
Your answer is the same as https://mcmap.net/q/1304691/-playwright-test-runner-limit-test-to-only-one-browser-with-a-config-file-that-has-many-projectsNarrate
@PatrickKenny With actual details of how I arrived at such a solution. Unlike other solutions.Hamill

© 2022 - 2025 — McMap. All rights reserved.