mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
docs(python): add support for custom expect message (#21151)
https://github.com/microsoft/playwright-python/issues/1310
This commit is contained in:
parent
8b8444dacc
commit
78bc6f4d74
@ -28,3 +28,27 @@ title: "Assertions"
|
||||
| [`method: PageAssertions.toHaveTitle`] | Page has a title |
|
||||
| [`method: PageAssertions.toHaveURL`] | Page has a URL |
|
||||
| [`method: APIResponseAssertions.toBeOK`] | Response has an OK status |
|
||||
|
||||
## Custom Expect Message
|
||||
* langs: python
|
||||
|
||||
You can specify a custom error message as a second argument to the `expect` function, for example:
|
||||
|
||||
```python
|
||||
expect(page.get_by_text("Name"), "should be logged in").to_be_visible()
|
||||
```
|
||||
|
||||
The error would look like this:
|
||||
|
||||
```bash
|
||||
def test_foobar(page: Page) -> None:
|
||||
> expect(page.get_by_text("Name"), "should be logged in").to_be_visible()
|
||||
E AssertionError: should be logged in
|
||||
E Actual value: None
|
||||
E Call log:
|
||||
E LocatorAssertions.to_be_visible with timeout 5000ms
|
||||
E waiting for get_by_text("Name")
|
||||
E waiting for get_by_text("Name")
|
||||
|
||||
tests/test_foobar.py:22: AssertionError
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user