Skip to content

Commit 5798f4b

Browse files
pbratkowskijacobtylerwalls
authored andcommitted
Fixed selenium tests in Firefox.
Unlike Chromium-based browsers, Firefox does not automatically scroll elements into view when using the Actions API with move_to_element. This calls the scrollIntoView function explicitly, which fixes some selenium tests when not running in headless mode.
1 parent d725f68 commit 5798f4b

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

tests/admin_views/tests.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6101,6 +6101,9 @@ def test_prepopulated_fields(self):
61016101
status = self.selenium.find_element(
61026102
By.ID, "id_relatedprepopulated_set-2-0-status"
61036103
)
6104+
# Fix for Firefox which does not scroll to clicked elements automatically with
6105+
# the Options API
6106+
self.selenium.execute_script("arguments[0].scrollIntoView();", status)
61046107
ActionChains(self.selenium).move_to_element(status).click(status).perform()
61056108
self.selenium.find_element(
61066109
By.ID, "id_relatedprepopulated_set-2-0-pubdate"
@@ -6135,6 +6138,7 @@ def test_prepopulated_fields(self):
61356138
status = self.selenium.find_element(
61366139
By.ID, "id_relatedprepopulated_set-2-1-status"
61376140
)
6141+
self.selenium.execute_script("arguments[0].scrollIntoView();", status)
61386142
ActionChains(self.selenium).move_to_element(status).click(status).perform()
61396143
self.select_option("#id_relatedprepopulated_set-2-1-status", "option one")
61406144
self.selenium.find_element(
@@ -6163,6 +6167,7 @@ def test_prepopulated_fields(self):
61636167
row_id = "id_relatedprepopulated_set-4-0-"
61646168
self.selenium.find_element(By.ID, f"{row_id}pubdate").send_keys("2011-12-12")
61656169
status = self.selenium.find_element(By.ID, f"{row_id}status")
6170+
self.selenium.execute_script("arguments[0].scrollIntoView();", status)
61666171
ActionChains(self.selenium).move_to_element(status).click(status).perform()
61676172
self.select_option(f"#{row_id}status", "option one")
61686173
self.selenium.find_element(By.ID, f"{row_id}name").send_keys(
@@ -6177,13 +6182,16 @@ def test_prepopulated_fields(self):
61776182
self.assertEqual(slug1, "stacked-inline-2011-12-12")
61786183
self.assertEqual(slug2, "option-one")
61796184
# Add inline.
6180-
self.selenium.find_elements(
6185+
add_link = self.selenium.find_elements(
61816186
By.LINK_TEXT,
61826187
"Add another Related prepopulated",
6183-
)[3].click()
6188+
)[3]
6189+
self.selenium.execute_script("arguments[0].scrollIntoView();", add_link)
6190+
add_link.click()
61846191
row_id = "id_relatedprepopulated_set-4-1-"
61856192
self.selenium.find_element(By.ID, f"{row_id}pubdate").send_keys("1999-01-20")
61866193
status = self.selenium.find_element(By.ID, f"{row_id}status")
6194+
self.selenium.execute_script("arguments[0].scrollIntoView();", status)
61876195
ActionChains(self.selenium).move_to_element(status).click(status).perform()
61886196
self.select_option(f"#{row_id}status", "option two")
61896197
self.selenium.find_element(By.ID, f"{row_id}name").send_keys(

0 commit comments

Comments
 (0)