Playwright Browsers
playwright_browser gives your tests a Chromium browser that runs in a container, on the session's network. Nothing but the Playwright Python package is needed on the host.
At a Glance
- TestShed enabled with
--shed. - Docker can pull
mcr.microsoft.com/playwright, and the container can reach the npm registry (it starts the server withnpx playwright run-server).
Drive the Browser
def test_example_website(playwright_browser):
page = playwright_browser.new_page()
page.goto("https://example.com")
assert "Example Domain" in page.title()The fixture is session-scoped: every test shares one browser. Open a page or context per test to keep them apart.
Reach Your Containers
The browser runs on the session's network, so it reaches shed containers by address:
def test_app_page(shed, playwright_browser):
page = playwright_browser.new_page()
page.goto(f"http://{shed.ip()}:3000")Use the Clipboard
Pages and contexts the browser opens get the clipboard-read and clipboard-write permissions, so tests can copy and paste. Permissions you pass to new_page or new_context are added to them:
def test_paste(playwright_browser):
page = playwright_browser.new_page(permissions=["geolocation"])The page needs a secure origin (https, or localhost) for navigator.clipboard to exist. playwright_browser.wrapped is the plain Playwright Browser, without the extra permissions.
Which Image
The container runs mcr.microsoft.com/playwright at the same version as the playwright package you have installed, so the client and the browser always match. Upgrade the package and the image follows.
Next Steps
- Containers: start the services the browser tests.
- Fixtures and Markers: every fixture TestShed registers.