From 78bc6f4d745ca50402183ace417af650c8d41aa2 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 23 Feb 2023 13:25:00 +0100 Subject: [PATCH] docs(python): add support for custom expect message (#21151) https://github.com/microsoft/playwright-python/issues/1310 --- .../src/test-assertions-csharp-java-python.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 +```