mirror of
https://github.com/django/django.git
synced 2025-03-26 17:20:49 +00:00
Fixed SeleniumTestCase.set_emulated_media() when using selenium_hub.
The .execute_cdp_cmd() method doesn't exist on selenium.webdriver.Remote.
This commit is contained in:
parent
53b981eff2
commit
ceaf1e2848
@ -193,15 +193,24 @@ class SeleniumTestCase(LiveServerTestCase, metaclass=SeleniumTestCaseBase):
|
|||||||
finally:
|
finally:
|
||||||
self.selenium.execute_script("localStorage.removeItem('theme');")
|
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"}:
|
if self.browser not in {"chrome", "edge"}:
|
||||||
self.skipTest(
|
self.skipTest(
|
||||||
"Emulation.setEmulatedMedia is only supported on Chromium and "
|
"Emulation.setEmulatedMedia is only supported on Chromium and "
|
||||||
"Chrome-based browsers. See https://chromedevtools.github.io/devtools-"
|
"Chrome-based browsers. See https://chromedevtools.github.io/devtools-"
|
||||||
"protocol/1-3/Emulation/#method-setEmulatedMedia for more details."
|
"protocol/1-3/Emulation/#method-setEmulatedMedia for more details."
|
||||||
)
|
)
|
||||||
self.selenium.execute_cdp_cmd(
|
params = {}
|
||||||
"Emulation.setEmulatedMedia", {"media": media, "features": features}
|
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
|
@contextmanager
|
||||||
|
Loading…
x
Reference in New Issue
Block a user