|
4 | 4 | import sys |
5 | 5 | import argparse |
6 | 6 | import io |
| 7 | +import time |
7 | 8 | from pathlib import Path |
8 | 9 |
|
9 | 10 | from PIL import Image, ImageChops |
@@ -34,16 +35,23 @@ def screenshot(browser: webdriver.Remote, url: str) -> Image.Image: |
34 | 35 |
|
35 | 36 | target_find_by = By.TAG_NAME |
36 | 37 | target = "body" |
| 38 | + loaded_page_settling_time = 0 |
37 | 39 |
|
38 | | - web_driver_wait = WebDriverWait(browser, 5) |
| 40 | + # TODO for pdf2htmlex the second screenshot sometimes fades in from white... not sure why, but a sleep solves it |
| 41 | + if "poppler" in url: |
| 42 | + loaded_page_settling_time = 0.3 |
| 43 | + |
| 44 | + web_driver_wait = WebDriverWait(browser, 10) |
39 | 45 | web_driver_wait.until( |
40 | 46 | expected_conditions.presence_of_element_located((target_find_by, target)) |
41 | 47 | ) |
42 | 48 | web_driver_wait.until( |
43 | 49 | lambda driver: driver.execute_script("return document.readyState") == "complete" |
44 | 50 | ) |
45 | 51 |
|
46 | | - png = browser.get_screenshot_as_png() |
| 52 | + time.sleep(loaded_page_settling_time) |
| 53 | + |
| 54 | + png = browser.get_full_page_screenshot_as_png() |
47 | 55 | return Image.open(io.BytesIO(png)) |
48 | 56 |
|
49 | 57 |
|
@@ -89,8 +97,8 @@ def html_render_diff( |
89 | 97 | image_a = screenshot(browser, to_url(a)) |
90 | 98 | image_b = screenshot(browser_b, to_url(b)) |
91 | 99 |
|
92 | | - image_a = image_a.convert("RGBA") |
93 | | - image_b = image_b.convert("RGBA") |
| 100 | + image_a = image_a.convert("RGB") |
| 101 | + image_b = image_b.convert("RGB") |
94 | 102 | diff = ImageChops.difference(image_a, image_b) |
95 | 103 | return diff, (image_a, image_b) |
96 | 104 |
|
|
0 commit comments