Rayrun

How do I set up Playwright to run tests on both Chromium and Firefox browsers?

Answer

Running Tests on Chromium and Firefox with Playwright

To run tests on both Chromium and Firefox, you'll need to set up two projects in your Playwright config file.

First, import defineConfig and devices from @playwright/test.

import { defineConfig, devices } from '@playwright/test';

Next, define your projects array with two objects: one for Chromium and one for Firefox.

export default defineConfig({
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
      },
    },
    {
      name: 'firefox',
      use: {
        ...devices['Desktop Firefox'],
      },
    },
  ],
});

Each project should have a unique name ('chromium' or 'firefox') and specify which device to use.

To run all projects, use the npx playwright test command. Playwright will run all projects defined in your config file by default.

If you want to run only a specific project, use the --project command line option followed by its name. For example, to run only the Chromium project, you would use npx playwright test --project chromium.

For more tips on efficient Playwright test scripts, check out this blog post.

References

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Questions

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 [email protected].