Pytest Playwright Plugin (moved over to microsoft/pytest-playwright)
A Pytest wrapper for Playwright to automate web browsers (Chromium, Firefox, WebKit).
- Have a separate new page and context for each test with Pytest fixtures
- Run your end-to-end tests on multiple browsers by a CLI argument
- Run them headful with the
--headful
argument to debug them easily - Using base-url to only use the relative URL in your
Page.goto
calls
pip install pytest-playwright
Basic example for more see the examples sections as a reference.
def test_is_chromium(page):
page.goto("https://www.google.com")
page.type("input[name=q]", "Playwright GitHub")
page.click("input[type=submit]")
page.waitForSelector("text=microsoft/Playwright")
A string that contains the current browser name.
A Playwright browser instance for the whole test run.
A separate Playwright context instance for each new test.
A separate Playwright page instance for each new test.
A fixture that you can define to overwrite the launch arguments. It should return a Dict.
A fixture that you can define to overwrite the context arguments. It should return a Dict.
A fixture which is a boolean if a specific execution is made by the specified browser.
By default, the tests run on the Chromium browser. You can pass multiple times the --browser
flag to run it on different browsers or a single time to run it only on a specific browser.
Possible values: chromium
, firefox
, webkit
By default, the tests run in headless mode. You can pass the --headful
CLI flag to run the browser in headful mode.
import pytest
@pytest.mark.skip_browser("firefox")
def test_is_chromium(page):
page.goto("https://www.google.com")
# ...
import pytest
@pytest.mark.only_browser("chromium")
def test_is_chromium(page):
page.goto("https://www.google.com")
# ...
Start Pytest with the base-url
argument. Example: pytest --base-url http://localhost:8080
def test_is_chromium(page):
page.goto("/admin")
# -> Will result in http://localhost:8080/admin
from playwright.sync_api import Page
def test_my_test(page: Page):
page.goto("/admin")
# ...