1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #33211 -- Updated tests for Selenium 4.0.0.

Replaced deprecated `find_element[s]_by_*()` usages, in favour of
`find_element[s]()` with an explicit `By`.
This commit is contained in:
Carlton Gibson
2021-10-20 15:54:30 +02:00
parent 8fa974fcdd
commit 2ccc0b22db
10 changed files with 411 additions and 325 deletions

View File

@@ -1412,23 +1412,27 @@ class SeleniumTests(AdminSeleniumTestCase):
"""
The status line for selected rows gets updated correctly (#22038).
"""
from selenium.webdriver.common.by import By
self.admin_login(username='super', password='secret')
self.selenium.get(self.live_server_url + reverse('admin:auth_user_changelist'))
form_id = '#changelist-form'
# Test amount of rows in the Changelist
rows = self.selenium.find_elements_by_css_selector(
rows = self.selenium.find_elements(
By.CSS_SELECTOR,
'%s #result_list tbody tr' % form_id
)
self.assertEqual(len(rows), 1)
row = rows[0]
selection_indicator = self.selenium.find_element_by_css_selector(
selection_indicator = self.selenium.find_element(
By.CSS_SELECTOR,
'%s .action-counter' % form_id
)
all_selector = self.selenium.find_element_by_id('action-toggle')
row_selector = self.selenium.find_element_by_css_selector(
all_selector = self.selenium.find_element(By.ID, 'action-toggle')
row_selector = self.selenium.find_element(
By.CSS_SELECTOR,
'%s #result_list tbody tr:first-child .action-select' % form_id
)
@@ -1455,12 +1459,13 @@ class SeleniumTests(AdminSeleniumTestCase):
should select all rows in-between.
"""
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
Parent.objects.bulk_create([Parent(name='parent%d' % i) for i in range(5)])
self.admin_login(username='super', password='secret')
self.selenium.get(self.live_server_url + reverse('admin:admin_changelist_parent_changelist'))
checkboxes = self.selenium.find_elements_by_css_selector('tr input.action-select')
checkboxes = self.selenium.find_elements(By.CSS_SELECTOR, 'tr input.action-select')
self.assertEqual(len(checkboxes), 5)
for c in checkboxes:
self.assertIs(c.get_property('checked'), False)
@@ -1472,16 +1477,17 @@ class SeleniumTests(AdminSeleniumTestCase):
self.assertIs(checkboxes[-1].get_property('checked'), False)
def test_select_all_across_pages(self):
from selenium.webdriver.common.by import By
Parent.objects.bulk_create([Parent(name='parent%d' % i) for i in range(101)])
self.admin_login(username='super', password='secret')
self.selenium.get(self.live_server_url + reverse('admin:admin_changelist_parent_changelist'))
selection_indicator = self.selenium.find_element_by_css_selector('.action-counter')
select_all_indicator = self.selenium.find_element_by_css_selector('.actions .all')
question = self.selenium.find_element_by_css_selector('.actions > .question')
clear = self.selenium.find_element_by_css_selector('.actions > .clear')
select_all = self.selenium.find_element_by_id('action-toggle')
select_across = self.selenium.find_elements_by_name('select_across')
selection_indicator = self.selenium.find_element(By.CSS_SELECTOR, '.action-counter')
select_all_indicator = self.selenium.find_element(By.CSS_SELECTOR, '.actions .all')
question = self.selenium.find_element(By.CSS_SELECTOR, '.actions > .question')
clear = self.selenium.find_element(By.CSS_SELECTOR, '.actions > .clear')
select_all = self.selenium.find_element(By.ID, 'action-toggle')
select_across = self.selenium.find_elements(By.NAME, 'select_across')
self.assertIs(question.is_displayed(), False)
self.assertIs(clear.is_displayed(), False)
@@ -1522,16 +1528,17 @@ class SeleniumTests(AdminSeleniumTestCase):
self.assertIs(select_all_indicator.is_displayed(), False)
def test_actions_warn_on_pending_edits(self):
from selenium.webdriver.common.by import By
Parent.objects.create(name='foo')
self.admin_login(username='super', password='secret')
self.selenium.get(self.live_server_url + reverse('admin:admin_changelist_parent_changelist'))
name_input = self.selenium.find_element_by_id('id_form-0-name')
name_input = self.selenium.find_element(By.ID, 'id_form-0-name')
name_input.clear()
name_input.send_keys('bar')
self.selenium.find_element_by_id('action-toggle').click()
self.selenium.find_element_by_name('index').click() # Go
self.selenium.find_element(By.ID, 'action-toggle').click()
self.selenium.find_element(By.NAME, 'index').click() # Go
alert = self.selenium.switch_to.alert
try:
self.assertEqual(
@@ -1543,6 +1550,7 @@ class SeleniumTests(AdminSeleniumTestCase):
alert.dismiss()
def test_save_with_changes_warns_on_pending_action(self):
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
Parent.objects.create(name='parent')
@@ -1550,13 +1558,13 @@ class SeleniumTests(AdminSeleniumTestCase):
self.admin_login(username='super', password='secret')
self.selenium.get(self.live_server_url + reverse('admin:admin_changelist_parent_changelist'))
name_input = self.selenium.find_element_by_id('id_form-0-name')
name_input = self.selenium.find_element(By.ID, 'id_form-0-name')
name_input.clear()
name_input.send_keys('other name')
Select(
self.selenium.find_element_by_name('action')
self.selenium.find_element(By.NAME, 'action')
).select_by_value('delete_selected')
self.selenium.find_element_by_name('_save').click()
self.selenium.find_element(By.NAME, '_save').click()
alert = self.selenium.switch_to.alert
try:
self.assertEqual(
@@ -1569,6 +1577,7 @@ class SeleniumTests(AdminSeleniumTestCase):
alert.dismiss()
def test_save_without_changes_warns_on_pending_action(self):
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
Parent.objects.create(name='parent')
@@ -1577,9 +1586,9 @@ class SeleniumTests(AdminSeleniumTestCase):
self.selenium.get(self.live_server_url + reverse('admin:admin_changelist_parent_changelist'))
Select(
self.selenium.find_element_by_name('action')
self.selenium.find_element(By.NAME, 'action')
).select_by_value('delete_selected')
self.selenium.find_element_by_name('_save').click()
self.selenium.find_element(By.NAME, '_save').click()
alert = self.selenium.switch_to.alert
try:
self.assertEqual(