Skip to content

Commit

Permalink
fix(download): support download.failure() is None (#2409)
Browse files Browse the repository at this point in the history
fix(download): support download.failure() == Node
  • Loading branch information
mxschmitt committed Apr 16, 2024
1 parent 47f88e5 commit 57b41b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion playwright/_impl/_artifact.py
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_helper.py
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion tests/async/test_download.py
Expand Up @@ -65,6 +65,7 @@ async def test_should_report_downloads_with_accept_downloads_false(
== f"<Download url={download.url!r} suggested_filename={download.suggested_filename!r}>"
)
assert await download.path()
assert await download.failure() is None


async def test_should_report_downloads_with_accept_downloads_true(
Expand Down Expand Up @@ -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()


Expand Down

0 comments on commit 57b41b2

Please sign in to comment.