Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Max Schmitt78bc6f4d745c
diff --git a/docs/src/test-assertions-csharp-java-python.md b/docs/src/test-assertions-csharp-java-python.md
index 186d066bcc..ab9b4e3044 100644
--- a/docs/src/test-assertions-csharp-java-python.md
+++ b/docs/src/test-assertions-csharp-java-python.md
@@ -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
+```