• Skip to main content
  • Skip to primary sidebar

AutomationTestingHub

Selenium, Appium, Cucumber and more !!!

Run Playwright tests on different browsers

January 23, 2024 by anish Leave a Comment

In our first article on Playwright Tutorial for Beginners, we covered how you can install playwright and write your first test script. After this, we saw the steps using which you can run your playwright tests on Firefox browser.

We used this command to run the test script on Firefox browser – npx playwright test example.spec.js --project "firefox" --headed. In this article, we will dive in a bit deeper to understand how you can run your Playwright tests on different browsers as well. So let’s get started !!

run playwright tests on different browsers

Understanding projects section in playwright.config file

As mentioned before, we had used npx playwright test example.spec.js –project “firefox” –headed command to run our test script on Firefox browser. More specifically, it is this part – --project "firefox" which tells Playwright to execute the test script on Firefox browser. To understand how this works, we would need to refer to the playwright.config file

First of all, go to playwright-tutorial folder and then open playwright.config file

playwright.config file location

Scroll down a bit till you see projects section in playwright.config file. This is the section where you configure projects for major browsers.

projects - chromium, firefox and webkit options

In this section, you would notice that the first 3 options are chromium, firefox and webkit. You can also see that chromium is mapped with Desktop Chrome, firefox with Desktop Firefox and webkit with Desktop Safari. These are the same browsers that you installed during Playwright installation process

Now, coming back to the original point – when you mention --project "firefox" while running your test –

  • Playwright will check the projects sections in config file
  • it will figure out that Desktop Firefox is mapped with the name “firefox”
  • and hence, your test script will run on Desktop Firefox browser (which you had installed during Playwright installation process)

Go ahead and use this command to run your test script – npx playwright test example.spec.js --project "chromium" --headed. You will notice that, this time Playwright will open Chromium browser and run your test script.

Testing against branded browsers

Till now, we have executed our test script against the browsers that come with default playwright configuration (like Chromium). But you might have a requirement where you would need to test your code against actual public use browsers like Chrome. As an example, consider a scenario where your team is releasing some feature and you need to perform regression testing against a given version of Chrome that is publicly available.

To do this, check projects section in playwright.config file again. You would notice that there are two more sections which might be commented out – Test against mobile viewports and Test against branded browsers

Uncomment the section under Test against branded browsers. Make sure you have Chrome installed on your machine. Now you can mention “Google Chrome” with projects option (npx playwright test example.spec.js --project "Google Chrome" --headed), which will run your test script on the public version of Google Chrome installed on your machine

playwright - test against branded browsers

Other than running your tests against a single browser, you can run tests against multiple browser combinations as well. Let us see how this can be done

Running tests against all browsers

If you want to run the same test against all the browsers, you can simply remove –project option from the run command. This means that you are not specifying any browser while running the scripts, and hence Playwright will run the same tests against all the browsers

Command – npx playwright test example.spec.js --headed

After you run the test, view its HTML report. You will see that the report has listed down the runs against all the browsers which are mentioned in projects section in playwright.config file

playwright browsers - playwright test report against multiple browsers

Run tests against more than one browser

Instead of running tests on only one or on all the browsers, you can run the tests on more than one browsers as well. To do that, you have to mention –project multiple times and then mention the browser names. For example, we can use the following command if we want to run our tests on both chromium and public chrome version

Command – npx playwright test example.spec.js --project "chromium" --project "Google Chrome" --headed

This completes our article on running playwright test cases with different browser combinations. If you have any queries, please feel free to contact us using the comments section.

Filed Under: Playwright

Primary Sidebar

Automation Testing Hub

Tutorials Guide

Write test scripts in BDD format using our Cucumber Selenium Tutorial

Use our Appium Tutorial Series to setup Appium from scratch

Categories

  • Android
  • Appium
  • Cucumber
  • Java
  • Playwright
  • Selenium
  • Tosca

Recent Posts

  • Appium Inspector – Download and Install
  • How to download Chromedriver for Selenium
  • Run Playwright tests on different browsers
  • Playwright Automation Testing Tutorial
  • Selenium IDE Chrome Download

Recent Comments

  • Run Playwright tests on different browsers - AutomationTestingHub on Playwright Automation Testing Tutorial
  • Confluence: CPSSoft Test Framework on Appium Inspector – Download and Install
  • Playwright Automation Testing Tutorial - AutomationTestingHub on Download and Install – Node.js and NPM
  • Chrome浏览器在使用Java的Appium中无法启动。 | JAVA语言的经验与见解 on 2 Ways to find appPackage and appActivity name of your App
  • Appium Inspector Tutorial - AutomationTestingHub on Download and Install Appium 2 Server

Archives

  • January 2024
  • July 2023
  • March 2023
  • February 2023
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016

Latest Selenium 3 Guide

Are you using the latest version of Selenium WebDriver? It provides lot better support for the latest browser versions. Check it out here - Setup Latest Selenium WebDriver

Categories

  • Android
  • Appium
  • Cucumber
  • Java
  • Playwright
  • Selenium
  • Tosca

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in

Go to mobile version