mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
docs(python): add docs for new_context fixture (#30522)
https://github.com/microsoft/playwright-internal/issues/202
This commit is contained in:
parent
c9e4c49c2f
commit
1b7e097b68
@ -55,6 +55,7 @@ def test_my_app_is_working(fixture_name):
|
||||
|
||||
- `context`: New [browser context](./browser-contexts) for a test.
|
||||
- `page`: New [browser page](./pages) for a test.
|
||||
- `new_context`: Allows creating different [browser contexts](./browser-contexts) for a test. Useful for multi-user scenarios. Accepts the same parameters as [`method: Browser.newContext`].
|
||||
|
||||
**Session scope**: These fixtures are created when requested in a test function and destroyed when all tests end.
|
||||
|
||||
@ -211,30 +212,6 @@ def browser_context_args(browser_context_args, playwright):
|
||||
|
||||
Or via the CLI `--device="iPhone 11 Pro"`
|
||||
|
||||
### Persistent context
|
||||
|
||||
```py title="conftest.py"
|
||||
import pytest
|
||||
from playwright.sync_api import BrowserType
|
||||
from typing import Dict
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def context(
|
||||
browser_type: BrowserType,
|
||||
browser_type_launch_args: Dict,
|
||||
browser_context_args: Dict
|
||||
):
|
||||
context = browser_type.launch_persistent_context("./foobar", **{
|
||||
**browser_type_launch_args,
|
||||
**browser_context_args,
|
||||
"locale": "de-DE",
|
||||
})
|
||||
yield context
|
||||
context.close()
|
||||
```
|
||||
|
||||
When using that all pages inside your test are created from the persistent context.
|
||||
|
||||
### Using with `unittest.TestCase`
|
||||
|
||||
See the following example for using it with `unittest.TestCase`. This has a limitation,
|
||||
|
Loading…
x
Reference in New Issue
Block a user