Skip to content

Commit 57b41b2

Browse files
authored
fix(download): support download.failure() is None (#2409)
fix(download): support download.failure() == Node
1 parent 47f88e5 commit 57b41b2

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

playwright/_impl/_artifact.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ async def save_as(self, path: Union[str, Path]) -> None:
4242
await stream.save_as(path)
4343

4444
async def failure(self) -> Optional[str]:
45-
return patch_error_message(await self._channel.send("failure"))
45+
reason = await self._channel.send("failure")
46+
if reason is None:
47+
return None
48+
return patch_error_message(reason)
4649

4750
async def delete(self) -> None:
4851
await self._channel.send("delete")

playwright/_impl/_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def patch_error_message(message: str) -> str:
229229
if match:
230230
message = to_snake_case(match.group(1)) + match.group(2)
231231
message = message.replace(
232-
"Pass { acceptDownloads: true }", "Pass { accept_downloads: True }"
232+
"Pass { acceptDownloads: true }", "Pass 'accept_downloads=True'"
233233
)
234234
return message
235235

tests/async/test_download.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ async def test_should_report_downloads_with_accept_downloads_false(
6565
== f"<Download url={download.url!r} suggested_filename={download.suggested_filename!r}>"
6666
)
6767
assert await download.path()
68+
assert await download.failure() is None
6869

6970

7071
async def test_should_report_downloads_with_accept_downloads_true(
@@ -180,9 +181,13 @@ async def test_should_error_when_saving_with_downloads_disabled(
180181
with pytest.raises(Error) as exc:
181182
await download.save_as(user_path)
182183
assert (
183-
"Pass { accept_downloads: True } when you are creating your browser context"
184+
"Pass 'accept_downloads=True' when you are creating your browser context"
184185
in exc.value.message
185186
)
187+
assert (
188+
"Pass 'accept_downloads=True' when you are creating your browser context."
189+
== await download.failure()
190+
)
186191
await page.close()
187192

188193

0 commit comments

Comments
 (0)