Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playwright/_impl/_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def convert_select_option_values(

def determine_screenshot_type(path: Union[str, Path]) -> Literal["jpeg", "png"]:
mime_type, _ = mimetypes.guess_type(path)
if mime_type == "image/png":
if mime_type == "image/png" or mime_type is None:
return "png"
if mime_type == "image/jpeg":
return "jpeg"
Expand Down
8 changes: 8 additions & 0 deletions tests/async/test_screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ async def test_should_infer_screenshot_type_from_path(
await page.screenshot(path=output_jpg_file)
assert_image_file_format(output_jpg_file, "JPEG")

output_png_file = tmp_path / "foo"
await page.screenshot(path=output_png_file)
assert_image_file_format(output_png_file, "PNG")


async def test_should_screenshot_with_type_argument(page: Page, tmp_path: Path) -> None:
output_jpeg_with_png_extension = tmp_path / "foo_jpeg.png"
Expand All @@ -77,3 +81,7 @@ async def test_should_screenshot_with_type_argument(page: Page, tmp_path: Path)
output_png_with_jpeg_extension = tmp_path / "bar_png.jpeg"
await page.screenshot(path=output_png_with_jpeg_extension, type="png")
assert_image_file_format(output_png_with_jpeg_extension, "PNG")

output_png_with_jpeg_extension = tmp_path / "bar_jpeg"
await page.screenshot(path=output_png_with_jpeg_extension, type="jpeg")
assert_image_file_format(output_png_with_jpeg_extension, "JPEG")