docs(python): add support for custom expect message (#21151)

https://github.com/microsoft/playwright-python/issues/1310
This commit is contained in:
Max Schmitt 2023-02-23 13:25:00 +01:00 committed by GitHub
parent 8b8444dacc
commit 78bc6f4d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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