tests: make the e2e screenshots deterministic, and stop writing them over docs/
Two things a green e2e run left behind, both found by checking git status after it: 1. The mock listens on a fresh port every run and that port lands in the SearXNG base field, so all seven PNGs differed byte-for-byte between two passing runs. Nothing failed, but every `make e2e` dirtied the tracked README images and any commit made afterwards silently shipped a random loopback address. The port and the measured `<n> ms` in the meta line are now blanked before the shot - the assertions still check both, the PNG pins the wording only. 2. `--shots <dir>` writes the PNGs somewhere other than docs/, so a verification run does not touch the committed set at all. Proven: two consecutive `python3 tests/e2e.py` runs now produce identical md5s for all seven files. 40 checks, 0 fail.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-14 07:32:11
Commit634a1999
Parents0b74ad5c
Changed files
tests/e2e.py+26−5■■■■■
8 files+26−5
Diff
docs/ui-1024x768-dark.png+0−0■
index 785ecdb..1181269 100644
binary image
Binary image file
docs/ui-1024x768-light.png+0−0■
index 300a6f7..9c1dee8 100644
binary image
Binary image file
docs/ui-1440x900-dark.png+0−0■
index 9de452b..7ffb2e6 100644
binary image
Binary image file
docs/ui-1440x900-light.png+0−0■
index f0b3b57..c81b00c 100644
binary image
Binary image file
docs/ui-390x844-dark.png+0−0■
index 6bb6024..b902d83 100644
binary image
Binary image file
docs/ui-390x844-light.png+0−0■
index f91536b..abe4be2 100644
binary image
Binary image file
docs/ui-search-dark.png+0−0■
index 4e8090b..e274a49 100644
binary image
Binary image file
tests/e2e.py+26−5■■■■■
index 4f24f8c..83564bc 100755
--- a/tests/e2e.py
+++ b/tests/e2e.py
@@ -17,8 +17,9 @@ provider at tests/mockapi.py, opens the page with Playwright at 1440 / 1024 /
1717 Skips cleanly (exit 0) when Playwright is missing, so the offline suite stays
1818 dependency-free.
1919
20- python3 tests/e2e.py # run if Playwright is available
21- python3 tests/e2e.py --strict # exit 2 when Playwright is missing
20+ python3 tests/e2e.py # run if Playwright is available
21+ python3 tests/e2e.py --strict # exit 2 when Playwright is missing
22+ python3 tests/e2e.py --shots /tmp # write the PNGs somewhere other than docs/
2223 """
2324
2425 import argparse
@@ -121,6 +122,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
121122 def main():
122123 ap = argparse.ArgumentParser()
123124 ap.add_argument("--strict", action="store_true")
125+ ap.add_argument("--shots", default=DOCS,
126+ help="where the PNGs go (default docs/, the committed README set)")
124127 args = ap.parse_args()
125128
126129 try:
@@ -133,7 +136,8 @@ def main():
133136 bad("plugin_websearch binary is missing (run make first)")
134137 return 1
135138
136- os.makedirs(DOCS, exist_ok=True)
139+ shots = args.shots
140+ os.makedirs(shots, exist_ok=True)
137141 mock, mock_base, log = start_mock()
138142 os.environ["WEBSEARCH_MOCK_BASE"] = mock_base
139143 os.environ["WEBSEARCH_SEARXNG_BASE"] = mock_base + "/searxng"
@@ -229,8 +233,17 @@ def main():
229233 "document.getElementById('runMeta').textContent.indexOf('tavily') >= 0",
230234 timeout=20000)
231235 ok("switching the backend changes the next request")
236+ # The meta line carries the real elapsed time, which is
237+ # 2-7 ms and therefore different on every run. The
238+ # assertion above already proved it says "<n> ms"; the
239+ # PNG pins the wording, not this run's stopwatch.
240+ page.evaluate(
241+ "var m=document.getElementById('runMeta');"
242+ "if(m)m.textContent=m.textContent.replace(/\\d+ ms/,'N ms');"
243+ "var e=document.getElementById('searxng');"
244+ "if(e)e.value='';")
232245 page.screenshot(
233- path=os.path.join(DOCS, "ui-search-dark.png"),
246+ path=os.path.join(shots, "ui-search-dark.png"),
234247 full_page=True)
235248
236249 # Exa has no key: the provider's own message must appear.
@@ -287,7 +300,15 @@ def main():
287300 page.reload(wait_until="networkidle")
288301 page.wait_for_selector(".prov", timeout=15000)
289302
290- page.screenshot(path=os.path.join(DOCS, "ui-%s.png" % tag),
303+ # The mock server listens on a fresh port on every run, and
304+ # that port lands in the SearXNG base field - so the PNG
305+ # differed byte-for-byte between two green runs and any
306+ # `git status` after `make e2e` showed seven modified
307+ # screenshots. Blank the harness address so the picture is
308+ # of the page's default state, not of this run's loopback.
309+ page.evaluate("var e=document.getElementById('searxng');"
310+ "if(e)e.value='';")
311+ page.screenshot(path=os.path.join(shots, "ui-%s.png" % tag),
291312 full_page=True)
292313 page.close()
293314 browser.close()
294315
docs/ui-1024x768-dark.png+0−0■
index 785ecdb..1181269 100644index 785ecdb..1181269 100644
binary image
Binary image file
docs/ui-1024x768-light.png+0−0■
index 300a6f7..9c1dee8 100644index 300a6f7..9c1dee8 100644
binary image
Binary image file
docs/ui-1440x900-dark.png+0−0■
index 9de452b..7ffb2e6 100644index 9de452b..7ffb2e6 100644
binary image
Binary image file
docs/ui-1440x900-light.png+0−0■
index f0b3b57..c81b00c 100644index f0b3b57..c81b00c 100644
binary image
Binary image file
docs/ui-390x844-dark.png+0−0■
index 6bb6024..b902d83 100644index 6bb6024..b902d83 100644
binary image
Binary image file
docs/ui-390x844-light.png+0−0■
index f91536b..abe4be2 100644index f91536b..abe4be2 100644
binary image
Binary image file
docs/ui-search-dark.png+0−0■
index 4e8090b..e274a49 100644index 4e8090b..e274a49 100644
binary image
Binary image file
tests/e2e.py+26−5■■■■■
index 4f24f8c..83564bc 100755index 4f24f8c..83564bc 100755
--- a/tests/e2e.py--- a/tests/e2e.py
+++ b/tests/e2e.py+++ b/tests/e2e.py
@@ -17,8 +17,9 @@ provider at tests/mockapi.py, opens the page with Playwright at 1440 / 1024 /@@ -17,8 +17,9 @@ provider at tests/mockapi.py, opens the page with Playwright at 1440 / 1024 /
17 Skips cleanly (exit 0) when Playwright is missing, so the offline suite stays17 Skips cleanly (exit 0) when Playwright is missing, so the offline suite stays
18 dependency-free.18 dependency-free.
19 19
20- python3 tests/e2e.py # run if Playwright is available20+ python3 tests/e2e.py # run if Playwright is available
21- python3 tests/e2e.py --strict # exit 2 when Playwright is missing21+ python3 tests/e2e.py --strict # exit 2 when Playwright is missing
22+ python3 tests/e2e.py --shots /tmp # write the PNGs somewhere other than docs/
22 """23 """
23 24
24 import argparse25 import argparse
@@ -121,6 +122,8 @@ class Handler(http.server.BaseHTTPRequestHandler):@@ -121,6 +122,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
121 def main():122 def main():
122 ap = argparse.ArgumentParser()123 ap = argparse.ArgumentParser()
123 ap.add_argument("--strict", action="store_true")124 ap.add_argument("--strict", action="store_true")
125+ ap.add_argument("--shots", default=DOCS,
126+ help="where the PNGs go (default docs/, the committed README set)")
124 args = ap.parse_args()127 args = ap.parse_args()
125 128
126 try:129 try:
@@ -133,7 +136,8 @@ def main():@@ -133,7 +136,8 @@ def main():
133 bad("plugin_websearch binary is missing (run make first)")136 bad("plugin_websearch binary is missing (run make first)")
134 return 1137 return 1
135 138
136- os.makedirs(DOCS, exist_ok=True)139+ shots = args.shots
140+ os.makedirs(shots, exist_ok=True)
137 mock, mock_base, log = start_mock()141 mock, mock_base, log = start_mock()
138 os.environ["WEBSEARCH_MOCK_BASE"] = mock_base142 os.environ["WEBSEARCH_MOCK_BASE"] = mock_base
139 os.environ["WEBSEARCH_SEARXNG_BASE"] = mock_base + "/searxng"143 os.environ["WEBSEARCH_SEARXNG_BASE"] = mock_base + "/searxng"
@@ -229,8 +233,17 @@ def main():@@ -229,8 +233,17 @@ def main():
229 "document.getElementById('runMeta').textContent.indexOf('tavily') >= 0",233 "document.getElementById('runMeta').textContent.indexOf('tavily') >= 0",
230 timeout=20000)234 timeout=20000)
231 ok("switching the backend changes the next request")235 ok("switching the backend changes the next request")
236+ # The meta line carries the real elapsed time, which is
237+ # 2-7 ms and therefore different on every run. The
238+ # assertion above already proved it says "<n> ms"; the
239+ # PNG pins the wording, not this run's stopwatch.
240+ page.evaluate(
241+ "var m=document.getElementById('runMeta');"
242+ "if(m)m.textContent=m.textContent.replace(/\\d+ ms/,'N ms');"
243+ "var e=document.getElementById('searxng');"
244+ "if(e)e.value='';")
232 page.screenshot(245 page.screenshot(
233- path=os.path.join(DOCS, "ui-search-dark.png"),246+ path=os.path.join(shots, "ui-search-dark.png"),
234 full_page=True)247 full_page=True)
235 248
236 # Exa has no key: the provider's own message must appear.249 # Exa has no key: the provider's own message must appear.
@@ -287,7 +300,15 @@ def main():@@ -287,7 +300,15 @@ def main():
287 page.reload(wait_until="networkidle")300 page.reload(wait_until="networkidle")
288 page.wait_for_selector(".prov", timeout=15000)301 page.wait_for_selector(".prov", timeout=15000)
289 302
290- page.screenshot(path=os.path.join(DOCS, "ui-%s.png" % tag),303+ # The mock server listens on a fresh port on every run, and
304+ # that port lands in the SearXNG base field - so the PNG
305+ # differed byte-for-byte between two green runs and any
306+ # `git status` after `make e2e` showed seven modified
307+ # screenshots. Blank the harness address so the picture is
308+ # of the page's default state, not of this run's loopback.
309+ page.evaluate("var e=document.getElementById('searxng');"
310+ "if(e)e.value='';")
311+ page.screenshot(path=os.path.join(shots, "ui-%s.png" % tag),
291 full_page=True)312 full_page=True)
292 page.close()313 page.close()
293 browser.close()314 browser.close()
294315