Skip to content

Commit 715b094

Browse files
committed
Fix things that selenium deprecated in version 4, and bump requirement
- Legacy-Id: 19432
1 parent 4d650bb commit 715b094

5 files changed

Lines changed: 159 additions & 154 deletions

File tree

ietf/doc/tests_js.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _fill_in_author_form(form_elt, name, email, affiliation, country):
3030
# To enter the person, type their name in the select2 search box, wait for the
3131
# search to offer the result, then press 'enter' to accept the result and close
3232
# the search input.
33-
person_span = form_elt.find_element_by_class_name('select2-chosen')
33+
person_span = form_elt.find_element(By.CLASS_NAME, 'select2-chosen')
3434
self.scroll_to_element(person_span)
3535
person_span.click()
3636
input = self.driver.switch_to.active_element
@@ -46,27 +46,27 @@ def _fill_in_author_form(form_elt, name, email, affiliation, country):
4646
# After the author is selected, the email select options will be populated.
4747
# Wait for that, then click on the option corresponding to the requested email.
4848
# This will only work if the email matches an address for the selected person.
49-
email_select = form_elt.find_element_by_css_selector('select[name$="email"]')
49+
email_select = form_elt.find_element(By.CSS_SELECTOR, 'select[name$="email"]')
5050
email_option = self.wait.until(
5151
presence_of_element_child_by_css_selector(email_select, 'option[value="{}"]'.format(email))
5252
)
5353
email_option.click() # select the email
5454

5555
# Fill in the affiliation and country. Finally, simple text inputs!
56-
affil_input = form_elt.find_element_by_css_selector('input[name$="affiliation"]')
56+
affil_input = form_elt.find_element(By.CSS_SELECTOR, 'input[name$="affiliation"]')
5757
affil_input.send_keys(affiliation)
58-
country_input = form_elt.find_element_by_css_selector('input[name$="country"]')
58+
country_input = form_elt.find_element(By.CSS_SELECTOR, 'input[name$="country"]')
5959
country_input.send_keys(country)
6060

6161
def _read_author_form(form_elt):
6262
"""Read values from an author form
6363
6464
Note: returns the Person instance named in the person field, not just their name.
6565
"""
66-
hidden_person_input = form_elt.find_element_by_css_selector('input[type="text"][name$="person"]')
67-
email_select = form_elt.find_element_by_css_selector('select[name$="email"]')
68-
affil_input = form_elt.find_element_by_css_selector('input[name$="affiliation"]')
69-
country_input = form_elt.find_element_by_css_selector('input[name$="country"]')
66+
hidden_person_input = form_elt.find_element(By.CSS_SELECTOR, 'input[type="text"][name$="person"]')
67+
email_select = form_elt.find_element(By.CSS_SELECTOR, 'select[name$="email"]')
68+
affil_input = form_elt.find_element(By.CSS_SELECTOR, 'input[name$="affiliation"]')
69+
country_input = form_elt.find_element(By.CSS_SELECTOR, 'input[name$="country"]')
7070
return (
7171
Person.objects.get(pk=hidden_person_input.get_attribute('value')),
7272
email_select.get_attribute('value'),
@@ -87,16 +87,16 @@ def _read_author_form(form_elt):
8787
self.driver.get(url)
8888

8989
# The draft has one author to start with. Find the list and check the count.
90-
authors_list = self.driver.find_element_by_id('authors-list')
91-
author_forms = authors_list.find_elements_by_class_name('author-panel')
90+
authors_list = self.driver.find_element(By.ID, 'authors-list')
91+
author_forms = authors_list.find_elements(By.CLASS_NAME, 'author-panel')
9292
self.assertEqual(len(author_forms), 1)
9393

9494
# get the "add author" button so we can add blank author forms
95-
add_author_button = self.driver.find_element_by_id('add-author-button')
95+
add_author_button = self.driver.find_element(By.ID, 'add-author-button')
9696
for index, auth in enumerate(authors):
9797
self.scroll_to_element(add_author_button) # Can only click if it's in view!
9898
add_author_button.click() # Create a new form. Automatically scrolls to it.
99-
author_forms = authors_list.find_elements_by_class_name('author-panel')
99+
author_forms = authors_list.find_elements(By.CLASS_NAME, 'author-panel')
100100
authors_added = index + 1
101101
self.assertEqual(len(author_forms), authors_added + 1) # Started with 1 author, hence +1
102102
_fill_in_author_form(author_forms[index + 1], auth.name, str(auth.email()), orgs[index], countries[index])
@@ -114,9 +114,9 @@ def _read_author_form(form_elt):
114114
)
115115

116116
# Must provide a "basis" (change reason)
117-
self.driver.find_element_by_id('id_basis').send_keys('change testing')
117+
self.driver.find_element(By.ID, 'id_basis').send_keys('change testing')
118118
# Now click the 'submit' button and check that the update was accepted.
119-
submit_button = self.driver.find_element_by_css_selector('button[type="submit"]')
119+
submit_button = self.driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]')
120120
self.scroll_to_element(submit_button)
121121
submit_button.click()
122122
# Wait for redirect to the document_main view

ietf/group/tests_js.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _search_draft_and_locate_result(self, draft_input, search_string, draft):
3434
(By.CSS_SELECTOR, result_selector),
3535
draft.name
3636
))
37-
results = self.driver.find_elements_by_css_selector(result_selector)
37+
results = self.driver.find_elements(By.CSS_SELECTOR, result_selector)
3838
matching_results = [r for r in results if draft.name in r.text]
3939
self.assertEqual(len(matching_results), 1)
4040
return matching_results[0]
@@ -61,7 +61,7 @@ def _assert_milestone_changed(self):
6161
except TimeoutException:
6262
found_expected_text = False
6363
self.assertTrue(found_expected_text, 'Milestone never marked as "changed"')
64-
return self.driver.find_element_by_css_selector(milestone_selector)
64+
return self.driver.find_element(By.CSS_SELECTOR, milestone_selector)
6565

6666
def test_add_milestone(self):
6767
draft = WgDraftFactory()
@@ -89,9 +89,9 @@ def test_add_milestone(self):
8989
(By.CSS_SELECTOR, 'form#milestones-form div.edit-milestone')
9090
))
9191

92-
desc_input = edit_div.find_element_by_css_selector('input[id$="_desc"]')
93-
due_input = edit_div.find_element_by_css_selector('input[id$="_due"]')
94-
draft_input = edit_div.find_element_by_css_selector(
92+
desc_input = edit_div.find_element(By.CSS_SELECTOR, 'input[id$="_desc"]')
93+
due_input = edit_div.find_element(By.CSS_SELECTOR, 'input[id$="_due"]')
94+
draft_input = edit_div.find_element(By.CSS_SELECTOR,
9595
'div.select2-container[id$="id_docs"] input.select2-input'
9696
)
9797

@@ -149,9 +149,9 @@ def test_edit_milestone(self):
149149
# Get the prefix used to identify inputs related to this milestone
150150
prefix = desc_field.get_attribute('id')[:-4] # -4 to strip off 'desc', leave '-'
151151

152-
due_field = self.driver.find_element_by_id(prefix + 'due')
153-
hidden_drafts_field = self.driver.find_element_by_id(prefix + 'docs')
154-
draft_input = self.driver.find_element_by_css_selector(
152+
due_field = self.driver.find_element(By.ID, prefix + 'due')
153+
hidden_drafts_field = self.driver.find_element(By.ID, prefix + 'docs')
154+
draft_input = self.driver.find_element(By.CSS_SELECTOR,
155155
'div.select2-container[id*="%s"] input.select2-input' % prefix
156156
)
157157
self.assertEqual(due_field.get_attribute('value'), milestone.due.strftime('%B %Y'))
@@ -185,4 +185,4 @@ def test_edit_milestone(self):
185185
gms = self.group.groupmilestone_set.first()
186186
self.assertEqual(gms.desc, expected_desc)
187187
self.assertEqual(gms.due.strftime('%m %Y'), expected_due_date)
188-
self.assertCountEqual(expected_docs, gms.docs.all())
188+
self.assertCountEqual(expected_docs, gms.docs.all())

0 commit comments

Comments
 (0)