Playwright Runner: Limit test to only one Browser

Once you install Playwright and execute your test, you will find your single test will run on three browsers with two workers running two browsers simultaneously.

Cross Browser Testing by default is a nice feature, but while creating or debugging scripts, we want to save time by executing on one browser at a time and then testing on other browsers.

So you can stop running the scripts on multiple browsers in two ways: by making changes in the config file and by giving command line parameters for a specific browser.

Method 1: Comment Other Browser in Config File

 /* Configure projects for major browsers */
  projects: [
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],

    // {
    //   name: 'firefox',
    //   use: {
    //     ...devices['Desktop Firefox'],
    //   },
    // },

    // {
    //   name: 'webkit',
    //   use: {
    //     ...devices['Desktop Safari'],
    //   },
    // },

Now, your test will execute on chrome only. This is not an efficient approach, so I would recommend Method 2. 

Method 2: Give Command Line Option

npx playwright test myfirsttest.spec.js  --headed  --project=chromium
  • Here, the project can be replaced with also.
  • For Firefox, use value firefox, and for Safari, use webkit.
Sun, 09/05/2021 - 13:15

Authored by

Tarun Goswami, works as a Technical Lead at the well-known IT services company. With Over 11+ years of experience in Quality Assurance, he writes engaging and informative blogs in his spare time.

Video Tutorial: Playwright Execute Test on Single Browser