summaryrefslogtreecommitdiff
path: root/django/test/selenium.py
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2024-05-13 16:52:01 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-05-13 17:31:35 +0200
commitceaf1e2848583ba832cc74715da38c802b6b0671 (patch)
tree2e53c63afe0fdbaedc347da906e7a543929506b1 /django/test/selenium.py
parent53b981eff2d168d92de31182b186827aecd88b8b (diff)
Fixed SeleniumTestCase.set_emulated_media() when using selenium_hub.
The .execute_cdp_cmd() method doesn't exist on selenium.webdriver.Remote.
Diffstat (limited to 'django/test/selenium.py')
-rw-r--r--django/test/selenium.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/django/test/selenium.py b/django/test/selenium.py
index db6c78a96b..4ef5015556 100644
--- a/django/test/selenium.py
+++ b/django/test/selenium.py
@@ -193,15 +193,24 @@ class SeleniumTestCase(LiveServerTestCase, metaclass=SeleniumTestCaseBase):
finally:
self.selenium.execute_script("localStorage.removeItem('theme');")
- def set_emulated_media(self, features, media=""):
+ def set_emulated_media(self, *, media=None, features=None):
if self.browser not in {"chrome", "edge"}:
self.skipTest(
"Emulation.setEmulatedMedia is only supported on Chromium and "
"Chrome-based browsers. See https://chromedevtools.github.io/devtools-"
"protocol/1-3/Emulation/#method-setEmulatedMedia for more details."
)
- self.selenium.execute_cdp_cmd(
- "Emulation.setEmulatedMedia", {"media": media, "features": features}
+ params = {}
+ if media is not None:
+ params["media"] = media
+ if features is not None:
+ params["features"] = features
+
+ # Not using .execute_cdp_cmd() as it isn't supported by the remote web driver
+ # when using --selenium-hub.
+ self.selenium.execute(
+ driver_command="executeCdpCommand",
+ params={"cmd": "Emulation.setEmulatedMedia", "params": params},
)
@contextmanager