docs(python): add docs for new_context fixture (#30522)

https://github.com/microsoft/playwright-internal/issues/202
This commit is contained in:
Max Schmitt 2024-04-24 22:40:38 +02:00 committed by GitHub
parent c9e4c49c2f
commit 1b7e097b68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,