diff --git a/playwright/_impl/_artifact.py b/playwright/_impl/_artifact.py index 63833fe04..d619c35e2 100644 --- a/playwright/_impl/_artifact.py +++ b/playwright/_impl/_artifact.py @@ -42,7 +42,10 @@ async def save_as(self, path: Union[str, Path]) -> None: await stream.save_as(path) async def failure(self) -> Optional[str]: - return patch_error_message(await self._channel.send("failure")) + reason = await self._channel.send("failure") + if reason is None: + return None + return patch_error_message(reason) async def delete(self) -> None: await self._channel.send("delete") diff --git a/playwright/_impl/_helper.py b/playwright/_impl/_helper.py index 0e6b91cd2..a79d9fe6a 100644 --- a/playwright/_impl/_helper.py +++ b/playwright/_impl/_helper.py @@ -229,7 +229,7 @@ def patch_error_message(message: str) -> str: if match: message = to_snake_case(match.group(1)) + match.group(2) message = message.replace( - "Pass { acceptDownloads: true }", "Pass { accept_downloads: True }" + "Pass { acceptDownloads: true }", "Pass 'accept_downloads=True'" ) return message diff --git a/tests/async/test_download.py b/tests/async/test_download.py index 96d06820e..082fcac26 100644 --- a/tests/async/test_download.py +++ b/tests/async/test_download.py @@ -65,6 +65,7 @@ async def test_should_report_downloads_with_accept_downloads_false( == f"" ) assert await download.path() + assert await download.failure() is None async def test_should_report_downloads_with_accept_downloads_true( @@ -180,9 +181,13 @@ async def test_should_error_when_saving_with_downloads_disabled( with pytest.raises(Error) as exc: await download.save_as(user_path) assert ( - "Pass { accept_downloads: True } when you are creating your browser context" + "Pass 'accept_downloads=True' when you are creating your browser context" in exc.value.message ) + assert ( + "Pass 'accept_downloads=True' when you are creating your browser context." + == await download.failure() + ) await page.close()