Cross-Browser Testing with Playwright Python (Chromium, Firefox, WebKit)

Your users do not all use Chrome. Safari’s WebKit engine and Firefox’s Gecko engine render pages, handle events and implement web features differently, and bugs that only appear in one engine are common. Playwright ships all three engines, so one pytest suite can check them all. In this lesson you will run the same tests in Chromium, Firefox and WebKit, use real Chrome and Edge through channels, react to the current browser in fixtures and tests, give each browser its own launch options, and set up a cross-browser run that stays fast.

Advertisement

📖 What You’ll Learn: the three Playwright engines and which real browsers they represent, installing browsers, –browser and multiple browsers in one run, how test ids show the browser, Chrome and Edge with –browser-channel, the browser_name fixture, browser-specific expectations, browser_type_launch_args, skip_browser and only_browser, what usually differs between engines, and speeding up cross-browser runs.


🌐 Three Engines, Many Browsers

Every browser is built on a rendering engine. Playwright drives three of them directly:

Playwright browser Engine Represents
chromium Blink Chrome, Edge, Opera, Brave, Samsung Internet
firefox Gecko Firefox
webkit WebKit Safari on macOS and iOS

Playwright’s builds are patched versions of these engines, shipped with each Playwright release, so a test behaves the same on every machine. That is why Playwright can run WebKit on Windows and Linux, which is the easiest way to catch Safari bugs without a Mac.

Install the engines once (from Lesson 2):

⌨️ Terminal

playwright install                 # chromium, firefox and webkit
playwright install --with-deps     # also installs the system libraries on Linux/CI

▶️ Running in Another Browser

pytest-playwright runs Chromium by default. Choose another engine with --browser:

📄 pytest.ini

[pytest]
addopts = --base-url https://sqatools.in

📄 tests/test_shop.py

import re

from playwright.sync_api import Page, expect

SHOP = "/dummy-ecommerce-website/"


def test_search_and_add_to_cart(page: Page):
    page.goto(SHOP)
    page.get_by_test_id("search-input").fill("earbuds")
    page.get_by_test_id("search-button").click()
    expect(page).to_have_url(re.compile(r"#/search/earbuds$"))
    page.get_by_role("button", name="Add to cart").first.click()
    expect(page.get_by_test_id("cart-count")).to_have_text("1")


def test_login_error_message(page: Page):
    page.goto(SHOP + "#/login")
    page.get_by_test_id("login-button").click()
    expect(page.get_by_test_id("login-error")).to_have_text("Username and password are required.")

⌨️ Terminal

pytest --browser firefox -v

🖥️ Output

============================= test session starts =============================
platform win32 -- Python 3.15.1, pytest-9.2.0, pluggy-1.7.0 -- C:\Users\you\playwright-python\.venv\Scripts\python.exe
cachedir: .pytest_cache
baseurl: https://sqatools.in
rootdir: C:\Users\you\playwright-python
configfile: pytest.ini
plugins: allure-pytest-2.16.2, base-url-2.1.0, bdd-9.0.1, html-4.2.0, metadata-3.1.1, playwright-0.10.0, rerunfailures-16.7, xdist-3.8.0
collecting ... collected 2 items

tests/test_shop.py::test_search_and_add_to_cart[firefox] PASSED          [ 50%]
tests/test_shop.py::test_login_error_message[firefox] PASSED             [100%]

============================= 2 passed in 10.98s ==============================

Repeat the option to run every test in every listed browser:

⌨️ Terminal

pytest --browser chromium --browser firefox --browser webkit -v

🖥️ Output

============================= test session starts =============================
platform win32 -- Python 3.15.1, pytest-9.2.0, pluggy-1.7.0 -- C:\Users\you\playwright-python\.venv\Scripts\python.exe
cachedir: .pytest_cache
baseurl: https://sqatools.in
rootdir: C:\Users\you\playwright-python
configfile: pytest.ini
plugins: allure-pytest-2.16.2, base-url-2.1.0, bdd-9.0.1, html-4.2.0, metadata-3.1.1, playwright-0.10.0, rerunfailures-16.7, xdist-3.8.0
collecting ... collected 6 items

tests/test_shop.py::test_search_and_add_to_cart[chromium] PASSED         [ 16%]
tests/test_shop.py::test_login_error_message[chromium] PASSED            [ 33%]
tests/test_shop.py::test_search_and_add_to_cart[firefox] PASSED          [ 50%]
tests/test_shop.py::test_login_error_message[firefox] PASSED             [ 66%]
tests/test_shop.py::test_search_and_add_to_cart[webkit] PASSED           [ 83%]
tests/test_shop.py::test_login_error_message[webkit] PASSED              [100%]

============================= 6 passed in 22.19s ==============================

Two tests × three browsers = six results. The browser name is part of each test id ([chromium], [firefox], [webkit]), so you can select one with -k:

⌨️ Terminal

pytest --browser chromium --browser firefox --browser webkit -k webkit -q

🖥️ Output

..                                                                       [100%]
2 passed, 4 deselected in 7.22s

To make cross-browser runs the default for the whole project, put the options in addopts:

[pytest]
addopts = --base-url https://sqatools.in --browser chromium --browser firefox --browser webkit

Advertisement

🧭 Real Chrome and Edge: Channels

The chromium engine is the open-source base of Chrome and Edge, but not identical to them (codecs, some policies, auto-updates). To test with the branded browser installed on the machine, use a channel:

Channel Browser
chrome, chrome-beta, chrome-dev Google Chrome
msedge, msedge-beta, msedge-dev Microsoft Edge

⌨️ Terminal

pytest --browser-channel msedge -q

🖥️ Output

..                                                                       [100%]
2 passed in 10.95s

Edge is preinstalled on Windows; on other systems install the branded browser with playwright install chrome or playwright install msedge. A channel only applies to the Chromium engine.

📌 Note: Use the bundled chromium for everyday runs (it is pinned to your Playwright version, so results are reproducible) and a branded channel in a nightly job, or when a bug only shows in the real Chrome or Edge.


🔍 Knowing the Current Browser: browser_name

pytest-playwright provides a browser_name fixture ("chromium", "firefox" or "webkit"). Use it to log, to branch fixtures, or to explain an expected difference:

📄 tests/test_engine.py

from playwright.sync_api import Page


def test_engine_reports_itself(page: Page, browser_name):
    user_agent = page.evaluate("navigator.userAgent")
    print(f"\n{browser_name:9} -> {user_agent[:90]}")
    expected = {"chromium": "Chrome/", "firefox": "Firefox/", "webkit": "Safari/"}[browser_name]
    assert expected in user_agent

⌨️ Terminal

pytest tests/test_engine.py --browser chromium --browser firefox --browser webkit -q -s

🖥️ Output

chromium  -> Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessC
.
firefox   -> Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:159.0) Gecko/20100101 Firefox/159.0
.
webkit    -> Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) V
.
3 passed in 5.74s

Each engine identifies itself differently, which is exactly why servers sometimes send different pages to different browsers.


⚖️ When Results Really Differ

Most well-written tests pass unchanged in all three engines. When a behaviour legitimately differs, encode the difference in one place, not with if statements scattered through tests. A dictionary keyed by browser_name keeps it explicit:

📄 tests/test_input_types.py

from playwright.sync_api import Page

# How each engine treats invalid text typed into <input type="number">
NUMBER_INPUT_VALUE = {"chromium": "", "firefox": "", "webkit": ""}


def test_number_input_rejects_letters(page: Page, browser_name):
    page.set_content('<input type="number" id="qty">')
    page.locator("#qty").press_sequentially("12abc")
    value = page.locator("#qty").input_value()
    print(f"\n{browser_name}: value={value!r}")
    assert value in ("12", NUMBER_INPUT_VALUE[browser_name])

⌨️ Terminal

pytest tests/test_input_types.py --browser chromium --browser firefox --browser webkit -q -s

🖥️ Output

chromium: value='12'
.
firefox: value=''
.
webkit: value='12'
.
3 passed in 5.99s

This is a real difference. Chromium and WebKit ignore the letters as you type, so the field holds 12. Firefox lets you type them, and because 12abc is not a valid number, the input’s value is an empty string. A form that reads the value without validating it would submit nothing in Firefox. The expected values live in one dictionary, so the difference is documented and tested instead of hidden.

page.set_content() loads a tiny HTML page directly into the browser, which is a quick way to compare engine behaviour without a server.

Common areas where engines differ in real projects:

  • Form controls: date, time and colour pickers look and behave differently; never automate the native picker UI, use fill() with an ISO value (2026-12-31).
  • Fonts and rendering: screenshots differ by a few pixels, so visual baselines are stored per browser (Lesson 40 does this automatically).
  • Media codecs: open-source Chromium lacks some proprietary codecs; use the chrome channel for video tests.
  • Downloads, clipboard and permissions: grant permissions explicitly per context; some permissions do not exist in every engine.
  • Timing: an engine may fire events in a slightly different order. Web-first assertions (expect) absorb this; time.sleep() does not.

Advertisement

🧰 Per-Browser Launch Options

Override the session fixture browser_type_launch_args to change how each browser starts. It receives the default arguments and browser_name is available too:

📄 tests/conftest.py

import pytest


@pytest.fixture(scope="session")
def browser_type_launch_args(browser_type_launch_args, browser_name):
    args = {**browser_type_launch_args}
    if browser_name == "chromium":
        args["args"] = ["--disable-features=Translate"]           # Chromium command-line switch
    if browser_name == "firefox":
        args["firefox_user_prefs"] = {"intl.accept_languages": "en-IN"}
    return args

⌨️ Terminal

pytest --browser chromium --browser firefox -q

🖥️ Output

........                                                                 [100%]
8 passed in 17.53s

Keep these overrides small. Each one is a difference between your tests and real users.


🏷️ Skipping a Browser for One Test

From Lesson 43: mark a test to skip or limit browsers, always with a reason.

📄 tests/test_markers.py

import pytest
from playwright.sync_api import Page


@pytest.mark.skip_browser("webkit")
def test_not_on_webkit(page: Page):
    page.set_content("<p>ok</p>")


@pytest.mark.only_browser("chromium")
def test_chromium_devtools_protocol(page: Page):
    cdp = page.context.new_cdp_session(page)        # the Chrome DevTools Protocol exists only in Chromium
    result = cdp.send("Runtime.evaluate", {"expression": "1 + 1"})
    assert result["result"]["value"] == 2

⌨️ Terminal

pytest tests/test_markers.py --browser chromium --browser firefox --browser webkit -v -rs

🖥️ Output

============================= test session starts =============================
platform win32 -- Python 3.15.1, pytest-9.2.0, pluggy-1.7.0 -- C:\Users\you\playwright-python\.venv\Scripts\python.exe
cachedir: .pytest_cache
baseurl: https://sqatools.in
rootdir: C:\Users\you\playwright-python
configfile: pytest.ini
plugins: allure-pytest-2.16.2, base-url-2.1.0, bdd-9.0.1, html-4.2.0, metadata-3.1.1, playwright-0.10.0, rerunfailures-16.7, xdist-3.8.0
collecting ... collected 6 items

tests/test_markers.py::test_not_on_webkit[chromium] PASSED               [ 16%]
tests/test_markers.py::test_chromium_devtools_protocol[chromium] PASSED  [ 33%]
tests/test_markers.py::test_not_on_webkit[firefox] PASSED                [ 50%]
tests/test_markers.py::test_chromium_devtools_protocol[firefox] SKIPPED  [ 66%]
tests/test_markers.py::test_not_on_webkit[webkit] SKIPPED (skipped f...) [ 83%]
tests/test_markers.py::test_chromium_devtools_protocol[webkit] SKIPPED   [100%]

=========================== short test summary info ===========================
SKIPPED [1] ..\..\.venv\Lib\site-packages\pytest_playwright\pytest_playwright.py:338: skipped for this browser: firefox
SKIPPED [2] ..\..\.venv\Lib\site-packages\pytest_playwright\pytest_playwright.py:338: skipped for this browser: webkit
======================== 3 passed, 3 skipped in 5.35s =========================

new_cdp_session is a real example of a Chromium-only API, so only_browser("chromium") is the honest marker here.


🚀 Keeping Cross-Browser Runs Fast

Three browsers triple the run time. Common strategies:

  1. Run in parallel with pytest-xdist: pytest -n auto --browser chromium --browser firefox --browser webkit (Lesson 65).
  2. Smoke in all, full in one: run the full suite in Chromium on every push, and a smoke subset in all browsers.
  3. CI matrix: one job per browser, so they run on separate machines in parallel and report separately (Lesson 66).
  4. Nightly full matrix: all tests × all browsers (and channels) once a day.

⌨️ Terminal

pytest tests/test_shop.py -n 3 --browser chromium --browser firefox --browser webkit -q

🖥️ Output

bringing up nodes...
bringing up nodes...

......                                                                   [100%]
6 passed in 19.03s

⚠️ Watch out: This project sets the base URL with addopts = --base-url ..., not with the base_url = ... ini key, on purpose. With pytest-xdist, the pytest-base-url plugin skips its setup on worker processes, so a base_url ini value never reaches the workers and every relative page.goto("/...") fails with Invalid url. A --base-url option (in addopts, on the command line or via PYTEST_BASE_URL) is passed to every worker and works.


Advertisement

🏋️ Practice Exercises

Try each exercise on your own first, then open the answer to compare. The answers use the same practice sites and project layout as the lesson.

Exercise 1: Write a fixture is_safari_like that returns True when the current browser is WebKit, and use it in a test that prints a message only for WebKit.

Show answer
import pytest


@pytest.fixture
def is_safari_like(browser_name) -> bool:
    return browser_name == "webkit"


def test_message(page, is_safari_like):
    if is_safari_like:
        print("running the Safari engine")

Exercise 2: Your pytest.ini has addopts = --browser chromium --browser firefox --browser webkit. How do you run only Firefox for one quick check without editing the file?

Show answer

Options are additive, so adding --browser firefox would still run all three. Filter by the id instead:

pytest -k firefox

or override addopts for one run: pytest -o addopts="" --browser firefox (the -o flag replaces the ini value).

Exercise 3: Write the command that runs the whole suite in Google Chrome (installed on the machine) instead of the bundled Chromium, in headed mode.

Show answer
pytest --browser-channel chrome --headed

A channel only works with the Chromium engine, so --browser chromium is implied.

Exercise 4: A date-picker test passes in Chromium and fails in WebKit because it clicks the calendar popup. How should you rewrite it?

Show answer

Do not automate the native picker UI, which differs per engine. Fill the input with an ISO date and check the value:

page.locator("#datePicker").fill("2026-12-31")
expect(page.locator("#datePicker")).to_have_value("2026-12-31")

🧠 MCQ Quiz: Cross-Browser Testing in Python

10 questions on this lesson. Pick one answer for each, then press Check answers to see your score and an explanation for every question.

  1. Which Playwright browser represents Safari?
  2. How do you run every test in both Chromium and Firefox?
  3. How can you tell in the report which browser a result belongs to?
  4. What does --browser-channel msedge do?
  5. Which fixture tells a test which engine is running?
  6. Which fixture should you override to pass launch arguments per browser?
  7. Why is page.context.new_cdp_session() a good reason for only_browser("chromium")?
  8. Can Playwright run WebKit tests on Windows?
  9. What is the safest way to set a value in a native date input across browsers?
  10. Which strategy keeps cross-browser runs fast?

Want a longer, timed test? Take the Module 7 mock interview (20 MCQs in 20 minutes).


Advertisement

❓ Frequently Asked Questions

🤔 Is testing in Playwright’s WebKit the same as testing in Safari?

Very close, but not identical: it is the same engine with Playwright’s patches, without Safari’s browser shell and macOS integrations. It catches the vast majority of Safari engine bugs; for final sign-off on iOS, teams still use a real device or a device cloud.

🤔 Do I need to test in both Chrome and Edge?

Usually not: both use the Blink engine and behave almost identically. Run the bundled Chromium routinely and add an msedge channel run if many of your users use Edge or your app relies on enterprise policies.

🤔 Why does my test pass in Chromium but time out in Firefox?

Common causes: a locator that relies on browser-specific markup, a hard-coded wait that is too short for the slower first navigation, or a feature the engine does not support. Open the trace for the Firefox run (Lesson 62) and compare it with the Chromium trace.

🤔 Can I set the browser in pytest.ini instead of the command line?

Yes, through addopts = --browser firefox (or several --browser options). There is no separate ini key for it.

🤔 How do mobile browsers fit in?

Mobile Safari and Chrome on Android are covered by device emulation in WebKit and Chromium: viewport, touch, user agent and device scale factor. That is the next lesson.


🏁 Summary

  • Playwright drives three engines: Chromium (Chrome, Edge), Firefox and WebKit (Safari), on every OS.
  • --browser selects an engine and can be repeated; the browser name appears in each test id.
  • --browser-channel chrome or msedge runs the installed branded browser.
  • Use browser_name to log or encode real differences in one place, and browser_type_launch_args for per-browser launch options.
  • Mark engine-specific tests with skip_browser / only_browser, and keep runs fast with xdist, CI matrices and a smoke-vs-full split.

🎬 Watch the Playwright tutorial series on YouTube!

Subscribe to SqaToolsByDY • Practice on the SQA Tools Automation Practice Page