8000 Fixed #36192 -- Updated Selenium tests to match. · django/django@77ae496 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77ae496

Browse files
committed
Fixed #36192 -- Updated Selenium tests to match.
Updated the Selenium tests to work with the new semantic button elements that replaced anchor tags in the admin interface. Modified selectors in test files to target button elements instead of link text, ensuring compatibility with the improved accessibility changes.
1 parent 3936abc commit 77ae496

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

tests/admin_inlines/tests.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ def test_add_stackeds(self):
19001900

19011901
self.assertCountSeleniumElements(rows_selector, 3)
19021902
add_button = self.selenium.find_element(
1903-
By.LINK_TEXT, "Add another Inner4 stacked"
1903+
By.XPATH, "//button[contains(text(), 'Add another Inner4 stacked')]"
19041904
)
19051905
add_button.click()
19061906
self.assertCountSeleniumElements(rows_selector, 4)
@@ -1920,14 +1920,14 @@ def test_delete_stackeds(self):
19201920
self.assertCountSeleniumElements(rows_selector, 3)
19211921

19221922
add_button = self.selenium.find_element(
1923-
By.LINK_TEXT, "Add another Inner4 stacked"
1923+
By.XPATH, "//button[contains(text(), 'Add another Inner4 stacked')]"
19241924
)
19251925
add_button.click()
19261926
add_button.click()
19271927

19281928
self.assertCountSeleniumElements(rows_selector, 5)
19291929
for delete_link in self.selenium.find_elements(
1930-
By.CSS_SELECTOR, "%s .inline-deletelink" % inline_id
1930+
By.CSS_SELECTOR, "%s button.inline-deletelink" % inline_id
19311931
):
19321932
delete_link.click()
19331933
with self.disable_implicit_wait():
@@ -1948,8 +1948,7 @@ def test_delete_invalid_stacked_inlines(self):
19481948
self.assertCountSeleniumElements(rows_selector, 3)
19491949

19501950
add_button = self.selenium.find_element(
1951-
By.LINK_TEXT,
1952-
"Add another Inner4 stacked",
1951+
By.XPATH, "//button[contains(text(), 'Add another Inner4 stacked')]"
19531952
)
19541953
add_button.click()
19551954
add_button.click()
@@ -1983,7 +1982,7 @@ def test_delete_invalid_stacked_inlines(self):
19831982
)
19841983
self.assertEqual("Please correct the duplicate values below.", errorlist.text)
19851984
delete_link = self.selenium.find_element(
1986-
By.CSS_SELECTOR, "#inner4stacked_set-4 .inline-deletelink"
1985+
By.CSS_SELECTOR, "#inner4stacked_set-4 button.inline-deletelink"
19871986
)
19881987
delete_link.click()
19891988
self.assertCountSeleniumElements(rows_selector, 4)
@@ -2014,7 +2013,7 @@ def test_delete_invalid_tabular_inlines(self):
20142013
self.assertCountSeleniumElements(rows_selector, 3)
20152014

20162015
add_button = self.selenium.find_element(
2017-
By.LINK_TEXT, "Add another Inner4 tabular"
2016+
By.XPATH, "//button[contains(text(), 'Add another Inner4 tabular')]"
20182017
)
20192018
add_button.click()
20202019
add_button.click()
@@ -2051,7 +2050,7 @@ def test_delete_invalid_tabular_inlines(self):
20512050
)
20522051
self.assertEqual("Please correct the duplicate values below.", errorlist.text)
20532052
delete_link = self.selenium.find_element(
2054-
By.CSS_SELECTOR, "#inner4tabular_set-4 .inline-deletelink"
2053+
By.CSS_SELECTOR, "#inner4tabular_set-4 button.inline-deletelink"
20552054
)
20562055
delete_link.click()
20572056

@@ -2095,7 +2094,9 @@ def test_add_inlines(self):
20952094
)
20962095

20972096
# Add an inline
2098-
self.selenium.find_element(By.LINK_TEXT, "Add another Profile").click()
2097+
self.selenium.find_element(
2098+
By.XPATH, "//button[contains(text(), 'Add another Profile')]"
2099+
).click()
20992100

21002101
# The inline has been added, it has the right id, and it contains the
21012102
# correct fields.
@@ -2113,7 +2114,9 @@ def test_add_inlines(self):
21132114
".dynamic-profile_set#profile_set-1 input[name=profile_set-1-last_name]", 1
21142115
)
21152116
# Let's add another one to be sure
2116-
self.selenium.find_element(By.LINK_TEXT, "Add another Profile").click()
2117+
self.selenium.find_element(
2118+
By.XPATH, "//button[contains(text(), 'Add another Profile')]"
2119+
).click()
21172120
self.assertCountSeleniumElements(".dynamic-profile_set", 3)
21182121
self.assertEqual(
21192122
self.selenium.find_elements(By.CSS_SELECTOR, ".dynamic-profile_set")[
@@ -2189,10 +2192,18 @@ def test_delete_inlines(self):
21892192
)
21902193

21912194
# Add a few inlines
2192-
self.selenium.find_element(By.LINK_TEXT, "Add another Profile").click()
2193-
self.selenium.find_element(By.LINK_TEXT, "Add another Profile").click()
2194-
self.selenium.find_element(By.LINK_TEXT, "Add another Profile").click()
2195-
self.selenium.find_element(By.LINK_TEXT, "Add another Profile").click()
2195+
self.selenium.find_element(
2196+
By.XPATH, "//button[contains(text(), 'Add another Profile')]"
2197+
).click()
2198+
self.selenium.find_element(
2199+
By.XPATH, "//button[contains(text(), 'Add another Profile')]"
2200+
).click()
2201+
self.selenium.find_element(
2202+
By.XPATH, "//button[contains(text(), 'Add another Profile')]"
2203+
).click()
2204+
self.selenium.find_element(
2205+
By.XPATH, "//button[contains(text(), 'Add another Profile')]"
2206+
).click()
21962207
self.assertCountSeleniumElements(
21972208
"#profile_set-group table tr.dynamic-profile_set", 5
21982209
)
@@ -2215,12 +2226,12 @@ def test_delete_inlines(self):
22152226
self.selenium.find_element(
22162227
By.CSS_SELECTOR,
22172228
"form#profilecollection_form tr.dynamic-profile_set#profile_set-1 "
2218-
"td.delete a",
2229+
"td.delete button",
22192230
).click()
22202231
self.selenium.find_element(
22212232
By.CSS_SELECTOR,
22222233
"form#profilecollection_form tr.dynamic-profile_set#profile_set-2 "
2223-
"td.delete a",
2234+
"td.delete button",
22242235
).click()
22252236
# The rows are gone and the IDs have been re-sequenced
22262237
self.assertCountSeleniumElements(
@@ -2273,7 +2284,9 @@ def test_added_stacked_inline_with_collapsed_fields(self):
22732284
self.live_server_url + reverse("admin:admin_inlines_teacher_add")
22742285
)
22752286
add_text = gettext("Add another %(verbose_name)s") % {"verbose_name": "Child"}
2276-
self.selenium.find_element(By.LINK_TEXT, add_text).click()
2287+
self.selenium.find_element(
2288+
By.XPATH, f"//button[contains(text(), '{add_text}')]"
2289+
).click()
22772290
test_fields = ["#id_child_set-0-name", "#id_child_set-1-name"]
22782291
summaries = self.selenium.find_elements(By.TAG_NAME, "summary")
22792292
self.assertEqual(len(summaries), 3)
@@ -2440,7 +2453,9 @@ def test_inlines_verbose_name(self):
24402453
self.assertIn("Available attendant", available.text)
24412454
self.assertIn("Chosen attendant", chosen.text)
24422455
# Added inline should also have the correct verbose_name.
2443-
self.selenium.find_element(By.LINK_TEXT, "Add another Class").click()
2456+
self.selenium.find_element(
2457+
By.XPATH, "//button[contains(text(), 'Add another Class')]"
2458+
).click()
24442459
available = self.selenium.find_element(
24452460
By.CSS_SELECTOR, css_available_selector % 1
24462461
)
@@ -2450,7 +2465,9 @@ def test_inlines_verbose_name(self):
24502465
self.assertIn("Available attendant", available.text)
24512466
self.assertIn("Chosen attendant", chosen.text)
24522467
# Third inline should also have the correct verbose_name.
2453-
self.selenium.find_element(By.LINK_TEXT, "Add another Class").click()
2468+
self.selenium.find_element(
2469+
By.XPATH, "//button[contains(text(), 'Add another Class')]"
2470+
).click()
24542471
available = self.selenium.find_element(
24552472
By.CSS_SELECTOR, css_available_selector % 2
24562473
)
@@ -2522,7 +2539,7 @@ def test_tabular_inline_delete_layout(self):
25222539
"fieldset.module tbody tr.dynamic-sighting_set:not(.original) td.delete",
25232540
)
25242541
self.assertIn(
2525-
'<a role="button" class="inline-deletelink" href="#">',
2542+
'<button type="button" class="inline-deletelink">',
25262543
delete.get_attribute("innerHTML"),
25272544
)
25282545
self.take_screenshot("loaded")

tests/admin_views/test_autocomplete_view.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,9 @@ def assertNoResults(row):
593593
self.assertEqual(len(rows), 3)
594594
assertNoResults(rows[0])
595595
# Autocomplete works in rows added using the "Add another" button.
596-
self.selenium.find_element(By.LINK_TEXT, "Add another Authorship").click()
596+
self.selenium.find_element(
597+
By.XPATH, "//button[contains(text(), 'Add another Authorship')]"
598+
).click()
597599
rows = self.selenium.find_elements(By.CSS_SELECTOR, ".dynamic-authorship_set")
598600
self.assertEqual(len(rows), 4)
599601
assertNoResults(rows[-1])

tests/admin_views/tests.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5880,9 +5880,9 @@ def test_prepopulated_fields(self):
58805880
self.assertEqual(num_initial_select2_inputs, 4)
58815881

58825882
# Add an inline
5883-
self.selenium.find_elements(By.LINK_TEXT, "Add another Related prepopulated")[
5884-
0
5885-
].click()
5883+
self.selenium.find_elements(
5884+
By.XPATH, "//button[contains(text(), 'Add another Related prepopulated')]"
5885+
)[0].click()
58865886
self.assertEqual(
58875887
len(self.selenium.find_elements(By.CLASS_NAME, "select2-selection")),
58885888
num_initial_select2_inputs + 2,
@@ -5940,7 +5940,7 @@ def test_prepopulated_fields(self):
59405940
# Add an inline
59415941
# Button may be outside the browser frame.
59425942
element = self.selenium.find_elements(
5943-
By.LINK_TEXT, "Add another Related prepopulated"
5943+
By.XPATH, "//button[contains(text(), 'Add another Related prepopulated')]"
59445944
)[1]
59455945
self.selenium.execute_script("window.scrollTo(0, %s);" % element.location["y"])
59465946
element.click()
@@ -5970,9 +5970,9 @@ def test_prepopulated_fields(self):
59705970
# Add an inline without an initial inline.
59715971
# The button is outside of the browser frame.
59725972
self.selenium.execute_script("window.scrollTo(0, document.body.scrollHeight);")
5973-
self.selenium.find_elements(By.LINK_TEXT, "Add another Related prepopulated")[
5974-
2
5975-
].click()
5973+
self.selenium.find_elements(
5974+
By.XPATH, "//button[contains(text(), 'Add another Related prepopulated')]"
5975+
)[2].click()
59765976
self.assertEqual(
59775977
len(self.selenium.find_elements(By.CLASS_NAME, "select2-selection")),
59785978
num_initial_select2_inputs + 6,
@@ -5997,8 +5997,7 @@ def test_prepopulated_fields(self):
59975997
self.assertEqual(slug2, "option-one")
59985998
# Add inline.
59995999
self.selenium.find_elements(
6000-
By.LINK_TEXT,
6001-
"Add another Related prepopulated",
6000+
By.XPATH, "//button[contains(text(), 'Add another Related prepopulated')]"
60026001
)[3].click()
60036002
row_id = "id_relatedprepopulated_set-4-1-"
60046003
self.selenium.find_element(By.ID, f"{row_id}pubdate").send_keys("1999-01-20")

tests/admin_widgets/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ def test_date_time_picker_shortcuts(self):
12141214

12151215
now = datetime.now()
12161216
for shortcut in shortcuts:
1217-
shortcut.find_element(By.TAG_NAME, "a").click()
1217+
shortcut.find_element(By.TAG_NAME, "button").click()
12181218

12191219
# There is a time zone mismatch warning.
12201220
# Warning: This would effectively fail if the TIME_ZONE defined in the

0 commit comments

Comments
 (0)
0