Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs(python): add snippet for new_context fixture (#33392)

Max Schmitt3b4b8f9e49db
diff --git a/docs/src/test-runners-python.md b/docs/src/test-runners-python.md
index d07fa2e53f..0dd4bbeca3 100644
--- a/docs/src/test-runners-python.md
+++ b/docs/src/test-runners-python.md
@@ -111,15 +111,20 @@ def test_visit_admin_dashboard(page: Page):
If you're using VSCode with Pylance, these types can be inferred by enabling the `python.testing.pytestEnabled` setting so you don't need the type annotation.
-### Configure slow mo
+### Using multiple contexts
-Run tests with slow mo with the `--slowmo` argument.
+In order to simulate multiple users, you can create multiple [`BrowserContext`](./browser-contexts) instances.
-```bash
-pytest --slowmo 100
-```
+```py title="test_my_application.py"
+from playwright.sync_api import Page, BrowserContext
+from pytest_playwright.pytest_playwright import CreateContextCallback
-Slows down Playwright operations by 100 milliseconds.
+def test_foo(page: Page, new_context: CreateContextCallback) -> None:
+ page.goto("https://example.com")
+ context = new_context()
+ page2 = context.new_page()
+ # page and page2 are in different contexts
+```
### Skip test by browser
@@ -198,7 +203,7 @@ def browser_context_args(browser_context_args):
}
```
-### Device emulation
+### Device emulation / BrowserContext option overrides
```py title="conftest.py"
import pytest