Skip to content

Commit 44e99a7

Browse files
author
Kyle McGonagle
committed
Default to png file type for screenshots if type is not provided and path does not include extension.
1 parent e93c23a commit 44e99a7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

playwright/_impl/_element_handle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def convert_select_option_values(
457457

458458
def determine_screenshot_type(path: Union[str, Path]) -> Literal["jpeg", "png"]:
459459
mime_type, _ = mimetypes.guess_type(path)
460-
if mime_type == "image/png":
460+
if mime_type == "image/png" or mime_type is None:
461461
return "png"
462462
if mime_type == "image/jpeg":
463463
return "jpeg"

tests/async/test_screenshot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ async def test_should_infer_screenshot_type_from_path(
6868
await page.screenshot(path=output_jpg_file)
6969
assert_image_file_format(output_jpg_file, "JPEG")
7070

71+
output_png_file = tmp_path / "foo"
72+
await page.screenshot(path=output_png_file)
73+
assert_image_file_format(output_png_file, "PNG")
74+
7175

7276
async def test_should_screenshot_with_type_argument(page: Page, tmp_path: Path) -> None:
7377
output_jpeg_with_png_extension = tmp_path / "foo_jpeg.png"

0 commit comments

Comments
 (0)