|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
4 | | -import shutil |
5 | 4 | import sys |
6 | 5 | import argparse |
7 | 6 | import io |
8 | | -import time |
9 | 7 | from pathlib import Path |
10 | 8 |
|
11 | 9 | from PIL import Image, ImageChops |
@@ -74,18 +72,25 @@ def get_browser( |
74 | 72 |
|
75 | 73 |
|
76 | 74 | def html_render_diff( |
77 | | - a: str | Path, b: str | Path, browser: webdriver.Remote |
| 75 | + a: str | Path, |
| 76 | + b: str | Path, |
| 77 | + browser: webdriver.Remote, |
| 78 | + browser_b: webdriver.Remote = None, |
78 | 79 | ) -> tuple[Image.Image, tuple[Image.Image, Image.Image]]: |
79 | 80 | if not isinstance(a, (str, Path)) or not isinstance(b, (str, Path)): |
80 | 81 | raise TypeError("Both a and b must be str or Path instances") |
81 | 82 | if not isinstance(browser, webdriver.Remote): |
82 | 83 | raise TypeError(f"Expected webdriver.Remote, got {type(browser)}") |
| 84 | + if browser_b is None: |
| 85 | + browser_b = browser |
| 86 | + elif not isinstance(browser_b, webdriver.Remote): |
| 87 | + raise TypeError(f"Expected webdriver.Remote, got {type(browser_b)}") |
83 | 88 |
|
84 | 89 | image_a = screenshot(browser, to_url(a)) |
85 | | - image_b = screenshot(browser, to_url(b)) |
| 90 | + image_b = screenshot(browser_b, to_url(b)) |
86 | 91 |
|
87 | | - image_a = image_a.convert("RGB") |
88 | | - image_b = image_b.convert("RGB") |
| 92 | + image_a = image_a.convert("RGBA") |
| 93 | + image_b = image_b.convert("RGBA") |
89 | 94 | diff = ImageChops.difference(image_a, image_b) |
90 | 95 | return diff, (image_a, image_b) |
91 | 96 |
|
|
0 commit comments