From f5e5057ad90049f808a8e8ee932a0f77089e06f7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 12 Mar 2021 19:10:25 +0100 Subject: tests: Further improve and stabilize screenshots (cherry picked from commit 903e5e294301d8551c06e6f918b726a20a1d391c) --- tests/end2end/fixtures/quteprocess.py | 4 ++-- tests/end2end/test_invocations.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 9ef338768..47548cc63 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -919,8 +919,8 @@ class QuteProc(testprocess.Process): # Rendering might not be completed yet... time.sleep(0.5) - raise ValueError( - f"Pixel probing for {probe_color} failed (got {probed_color} on last try)") + # Using assert again for pytest introspection + assert probed_color == probe_color, "Color probing failed, values on last try:" def press_keys(self, keys): """Press the given keys using :fake-key.""" diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index 6875db452..82473e50d 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -666,12 +666,10 @@ def test_dark_mode(webengine_versions, quteproc_new, request, # Position chosen by fair dice roll. # https://xkcd.com/221/ - pos = QPoint(4, 4) - img = quteproc_new.get_screenshot(probe_pos=pos, probe_color=expected) - - color = testutils.Color(img.pixelColor(pos)) - # For pytest debug output - assert color == expected + quteproc_new.get_screenshot( + probe_pos=QPoint(4, 4), + probe_color=expected, + ) def test_dark_mode_mathml(quteproc_new, request, qtbot): @@ -689,14 +687,16 @@ def test_dark_mode_mathml(quteproc_new, request, qtbot): quteproc_new.wait_for_js('Image loaded') # First make sure loading finished by looking outside of the image - img = quteproc_new.get_screenshot( + quteproc_new.get_screenshot( probe_pos=QPoint(105, 0), probe_color=testutils.Color(0, 0, 204), ) - # Then get the actual formula color - color = testutils.Color(img.pixelColor(QPoint(4, 4))) - assert color == testutils.Color(255, 255, 255) + # Then get the actual formula color, probing again in case it's not displayed yet... + quteproc_new.get_screenshot( + probe_pos=QPoint(4, 4), + probe_color=testutils.Color(255, 255, 255), + ) def test_unavailable_backend(request, quteproc_new): -- cgit v1.2.3-54-g00ecf