Fixing call to Chrome to generate Archive screenshots.

This commit is contained in:
Roland 2026-06-10 11:55:35 -06:00
parent 7efee1fdb2
commit d85c7721b5
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 14 additions and 1 deletions

View file

@ -10,6 +10,7 @@ calibre
cargo
catdoc
chromium
chromium-driver
cpufrequtils
curl
dosfstools

View file

@ -2554,7 +2554,7 @@ def html_screenshot(html: bytes | str) -> bytes:
fh.write(html.encode() if isinstance(html, str) else html)
fh.flush()
with webdriver.Chrome(chrome_options=options) as driver:
with webdriver.Chrome(options=options) as driver:
driver.get(f'file://{fh.name}')
driver.set_window_size(1280, 720)
screenshot = driver.get_screenshot_as_png()

View file

@ -893,6 +893,18 @@ def test_html_screenshot(singlefile_contents_factory):
assert common.html_screenshot(singlefile_contents_factory())
def test_html_screenshot_webdriver_kwargs(singlefile_contents_factory):
"""Selenium 4.10 removed the `chrome_options` kwarg; `webdriver.Chrome` must be called with `options`."""
with mock.patch('wrolpi.common.webdriver.Chrome') as mock_chrome:
driver = mock_chrome.return_value.__enter__.return_value
driver.get_screenshot_as_png.return_value = b'PNG'
assert common.html_screenshot(singlefile_contents_factory()) == b'PNG'
assert mock_chrome.call_args.kwargs.keys() == {'options'}
assert isinstance(mock_chrome.call_args.kwargs['options'], common.webdriver.ChromeOptions)
@pytest.mark.parametrize('color,expected', [
('#ffffff', True),
('#FFFFFF', True),