summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-04-16 09:28:34 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-05-02 13:18:58 +0200
commit39828fa7786a805f7a542abb929f352d3c5b722c (patch)
treec9518ad22bb7f7cb004f5adad66fd3ada712aef5 /django/test
parent914bf6917157923783ad2ea4c8a60115738a203c (diff)
Added a high contrast mode to screenshot cases.
Thank you to Sarah Abderemane and Nick Pope for the reviews.
Diffstat (limited to 'django/test')
-rw-r--r--django/test/selenium.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/django/test/selenium.py b/django/test/selenium.py
index 07df34ae1f..eecfd87bf1 100644
--- a/django/test/selenium.py
+++ b/django/test/selenium.py
@@ -191,6 +191,26 @@ class SeleniumTestCase(LiveServerTestCase, metaclass=SeleniumTestCaseBase):
finally:
self.selenium.execute_script("localStorage.removeItem('theme');")
+ def set_emulated_media(self, features, media=""):
+ if self.browser != "chrome":
+ self.skipTest("Emulated media controls are only supported on Chrome.")
+ # Chrome Dev Tools Protocol Emulation.setEmulatedMedia
+ # https://chromedevtools.github.io/devtools-protocol/1-3/Emulation/#method-setEmulatedMedia
+ self.selenium.execute_cdp_cmd(
+ "Emulation.setEmulatedMedia", {"media": media, "features": features}
+ )
+
+ @contextmanager
+ def high_contrast(self):
+ self.set_emulated_media(features=[{"name": "forced-colors", "value": "active"}])
+ with self.desktop_size():
+ try:
+ yield
+ finally:
+ self.set_emulated_media(
+ features=[{"name": "forced-colors", "value": "none"}]
+ )
+
def take_screenshot(self, name):
if not self.screenshots:
return