diff --git a/playwright/_impl/_element_handle.py b/playwright/_impl/_element_handle.py index 1561e19fc..986e2b20d 100644 --- a/playwright/_impl/_element_handle.py +++ b/playwright/_impl/_element_handle.py @@ -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" diff --git a/tests/async/test_screenshot.py b/tests/async/test_screenshot.py index 36149225f..6d6710188 100644 --- a/tests/async/test_screenshot.py +++ b/tests/async/test_screenshot.py @@ -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" @@ -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")