Playwright Runner: Limit test to only one Browser

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.

Video Tutorial: Playwright Execute Test on Single Browser

Tags
Standard (Image)