diff --git a/playwright/_impl/_assertions.py b/playwright/_impl/_assertions.py index aea37d35c..a216df75a 100644 --- a/playwright/_impl/_assertions.py +++ b/playwright/_impl/_assertions.py @@ -67,6 +67,8 @@ async def _expect_impl( expect_options["timeout"] = self._timeout or 5_000 if expect_options["isNot"]: message = message.replace("expected to", "expected not to") + if title: + title = title.replace('"to_', '"not_to_') if "useInnerText" in expect_options and expect_options["useInnerText"] is None: del expect_options["useInnerText"] result = await self._call_expect(expression, expect_options, title) diff --git a/tests/async/test_assertions.py b/tests/async/test_assertions.py index 49e3c3e7f..04fbfeb16 100644 --- a/tests/async/test_assertions.py +++ b/tests/async/test_assertions.py @@ -1023,6 +1023,15 @@ async def test_should_be_able_to_set_custom_timeout(page: Page) -> None: assert 'Expect "to_be_visible" with timeout 111ms' in str(exc_info.value) +async def test_negative_assertion_should_show_not_prefix_in_call_log( + page: Page, +) -> None: + await page.set_content("") + with pytest.raises(AssertionError) as exc_info: + await expect(page.locator("button")).not_to_be_visible(timeout=111) + assert 'Expect "not_to_be_visible" with timeout 111ms' in str(exc_info.value) + + async def test_should_be_able_to_set_custom_global_timeout(page: Page) -> None: try: expect.set_options(timeout=111)