summaryrefslogtreecommitdiff
path: root/django/test/selenium.py
diff options
context:
space:
mode:
authorNatalia <124304+nessita@users.noreply.github.com>2025-06-25 17:22:46 -0300
committernessita <124304+nessita@users.noreply.github.com>2025-06-27 15:57:02 -0300
commitff0ff98d427982b7225df59f454a86bdf66251d6 (patch)
tree6af4889cfdea447484db5fc4afc447fc2315cab0 /django/test/selenium.py
parentd63241ebc7067fdebbaf704989b34fcd8f26bbe9 (diff)
Refs #15727 -- Updated AdminSeleniumTestCase to use ContentSecurityPolicyMiddleware.
Replaced the custom CSP middleware previously used in the admin's AdminSeleniumTestCase with the official ContentSecurityPolicyMiddleware. This change ensures alignment with Django's built-in CSP support. Also updates the test logic to inspect browser console logs to assert that no CSP violations are triggered during Selenium admin tests.
Diffstat (limited to 'django/test/selenium.py')
-rw-r--r--django/test/selenium.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/django/test/selenium.py b/django/test/selenium.py
index 15ee3002ec..be8f4a815f 100644
--- a/django/test/selenium.py
+++ b/django/test/selenium.py
@@ -77,7 +77,11 @@ class SeleniumTestCaseBase(type(LiveServerTestCase)):
def get_capability(cls, browser):
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
- return getattr(DesiredCapabilities, browser.upper())
+ caps = getattr(DesiredCapabilities, browser.upper())
+ if browser == "chrome":
+ caps["goog:loggingPrefs"] = {"browser": "ALL"}
+
+ return caps
def create_options(self):
options = self.import_options(self.browser)()
@@ -237,6 +241,19 @@ class SeleniumTestCase(LiveServerTestCase, metaclass=SeleniumTestCaseBase):
path.parent.mkdir(exist_ok=True, parents=True)
self.selenium.save_screenshot(path)
+ def get_browser_logs(self, source=None, level="ALL"):
+ """Return Chrome console logs filtered by level and optionally source."""
+ try:
+ logs = self.selenium.get_log("browser")
+ except AttributeError:
+ logs = []
+ return [
+ log
+ for log in logs
+ if (level == "ALL" or log["level"] == level)
+ and (source is None or log["source"] == source)
+ ]
+
@classmethod
def _quit_selenium(cls):
# quit() the WebDriver before attempting to terminate and join the