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

This commit is contained in:
Max Schmitt 2024-11-01 17:50:34 +01:00 коммит произвёл GitHub
Родитель 18453f3889
Коммит 3b4b8f9e49
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 12 добавлений и 7 удалений

Просмотреть файл

@ -111,16 +111,21 @@ 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
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
```
Slows down Playwright operations by 100 milliseconds.
### Skip test by browser
```py title="test_my_application.py"
@ -198,7 +203,7 @@ def browser_context_args(browser_context_args):
}
```
### Device emulation
### Device emulation / BrowserContext option overrides
```py title="conftest.py"
import pytest