{"id":1669,"library":"pytest-playwright","title":"pytest-playwright","description":"pytest-playwright is a Pytest plugin that provides robust fixtures for Playwright, enabling efficient end-to-end web testing in Python. It automatically manages browser instances, contexts, and pages, integrating seamlessly with the pytest testing framework. As of version 0.7.2, it supports Playwright Python 1.39.0 and higher, with new versions typically released in sync with Playwright's own update cadence.","status":"active","version":"0.7.2","language":"en","source_language":"en","source_url":"https://github.com/microsoft/playwright-pytest","tags":["pytest","playwright","testing","web-automation","e2e","browser-testing"],"install":[{"cmd":"pip install pytest-playwright","lang":"bash","label":"Install pytest-playwright"},{"cmd":"playwright install","lang":"bash","label":"Install browser binaries (required)"}],"dependencies":[{"reason":"Core web automation library; pytest-playwright is a plugin for it.","package":"playwright","optional":false},{"reason":"Testing framework; pytest-playwright is a plugin for it.","package":"pytest","optional":false}],"imports":[{"note":"pytest-playwright provides fixtures (like 'page') automatically; they are not imported directly from the package.","wrong":"from pytest_playwright import page","symbol":"page","correct":"def test_example(page):"},{"note":"Used for type hinting the 'page' fixture, not to instantiate it.","symbol":"Page (for type hinting)","correct":"from playwright.sync_api import Page"}],"quickstart":{"code":"import pytest\n\ndef test_example_is_working(page):\n    page.goto(\"https://www.google.com\")\n    assert \"Google\" in page.title()\n    page.screenshot(path=\"screenshot.png\")\n\n# To run this test file:\n# 1. Save as e.g., `test_my_app.py`\n# 2. Ensure browsers are installed: `playwright install`\n# 3. Run: `pytest test_my_app.py`","lang":"python","description":"This quickstart demonstrates a basic web test using the `page` fixture provided by pytest-playwright. It navigates to Google, asserts the title, and takes a screenshot."},"warnings":[{"fix":"After installing `pytest-playwright`, run `playwright install` in your terminal to download browser binaries.","message":"Playwright requires browser binaries to be installed separately. Tests will fail with 'Playwright was not installed. Please run `playwright install`' if browsers are missing.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To improve performance, use pytest command-line options like `--browser-context-scope=session` or `--browser-scope=session` to share browser resources across tests. For custom fixtures, use `pytest.fixture(scope=\"session\")`.","message":"By default, `page`, `browser`, and `context` fixtures are created and torn down for *each* test function. While ensuring isolation, this can be slow for large test suites.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Run tests with `--headless=false` (e.g., `pytest --headless=false`) to launch browsers with a visible UI during execution. For more fine-grained control, use the `browser_args` fixture.","message":"Playwright runs browsers in headless mode by default (no visible UI). This can make debugging visual issues difficult.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For asynchronous tests, define your test function as `async def test_my_async(apage):` and use `await apage.goto(...)`.","message":"pytest-playwright provides synchronous Playwright API fixtures (e.g., `page`, `browser`) by default. If your tests require `async`/`await` patterns, you must explicitly use the asynchronous fixtures (e.g., `apage`, `abrowser`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check `pytest-playwright`'s `install_requires` for the compatible `playwright` version range (e.g., `playwright>=1.39.0`) and ensure both packages are upgraded together.","message":"pytest-playwright has strict version compatibility requirements with the `playwright` library. Installing incompatible versions can lead to runtime errors or unexpected behavior due to API mismatches.","severity":"breaking","affected_versions":"All versions, especially across major/minor `playwright` releases."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}