Skip to content

Commit bd79343

Browse files
Merge branch 'main' into profiling-panel
2 parents 7d03a66 + f95e032 commit bd79343

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

docs/changes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Pending
1919
an ``aria-live`` status for history refreshes, and WCAG 2.1 AA contrast in
2020
both themes.
2121
* Added a talk to the resources documentation.
22+
* Updated the example screenshot.
23+
* Updated the screenshot capture logic to find the toolbar elements in the
24+
shadow DOM.
2225
* Replaced ``PROFILER_THRESHOLD_RATIO`` with
2326
``PROFILER_CAPTURE_NON_PROJECT_THRESHOLD`` to allow more accurate profiling
2427
results.

example/django-debug-toolbar.png

237 KB
Loading

example/screenshot.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import subprocess
66
from time import sleep
77

8+
from selenium.common import NoSuchElementException
89
from selenium.webdriver.common.by import By
910
from selenium.webdriver.common.keys import Keys
1011
from selenium.webdriver.support import expected_conditions as EC
@@ -17,7 +18,7 @@ def parse_args():
1718
parser.add_argument("--headless", action="store_true")
1819
parser.add_argument("--outfile", "-o", required=True)
1920
parser.add_argument("--width", type=int, default=900)
20-
parser.add_argument("--height", type=int, default=700)
21+
parser.add_argument("--height", type=int, default=1200)
2122
return parser.parse_args()
2223

2324

@@ -61,6 +62,21 @@ def submit_form(selenium, data):
6162
WebDriverWait(selenium, timeout=5).until(EC.url_changes(url))
6263

6364

65+
def find_including_toolbar(selenium, by, value):
66+
"""Find the toolbar elements within the shadow root DOM"""
67+
selectors = {
68+
By.ID: "#{}",
69+
By.CLASS_NAME: ".{}",
70+
By.TAG_NAME: "{}",
71+
By.CSS_SELECTOR: "{}",
72+
}
73+
try:
74+
return selenium.find_element(by, value)
75+
except NoSuchElementException:
76+
shadow_root = selenium.find_element(By.ID, "djDebugRoot").shadow_root
77+
return shadow_root.find_element(By.CSS_SELECTOR, selectors[by].format(value))
78+
79+
6480
def main():
6581
args = parse_args()
6682
with example_server() as p:
@@ -73,12 +89,12 @@ def main():
7389

7490
selenium.get("http://localhost:8000/admin/auth/user/")
7591
# Check if SQL Panel is already visible:
76-
sql_panel = selenium.find_element(By.ID, "djdt-SQLPanel")
92+
sql_panel = find_including_toolbar(selenium, By.ID, "djdt-SQLPanel")
7793
if not sql_panel:
7894
# Open the admin sidebar.
79-
el = selenium.find_element(By.ID, "djDebugToolbarHandle")
95+
el = find_including_toolbar(selenium, By.ID, "djDebugToolbarHandle")
8096
el.click()
81-
sql_panel = selenium.find_element(By.ID, "djdt-SQLPanel")
97+
sql_panel = find_including_toolbar(selenium, By.ID, "djdt-SQLPanel")
8298
# Open the SQL panel.
8399
sql_panel.click()
84100

0 commit comments

Comments
 (0)