docs(python): add snippet for new_context fixture (#33392)
This commit is contained in:
Родитель
18453f3889
Коммит
3b4b8f9e49
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче