docs(python): add snippet for new_context fixture (#33392)
This commit is contained in:
parent
18453f3889
commit
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.
|
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
|
```py title="test_my_application.py"
|
||||||
pytest --slowmo 100
|
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
|
### Skip test by browser
|
||||||
|
|
||||||
```py title="test_my_application.py"
|
```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"
|
```py title="conftest.py"
|
||||||
import pytest
|
import pytest
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue