mirror of https://github.com/django/django.git
Made some Selenium tests less flaky by adding explicit wait.
This commit is contained in:
parent
42b4f81e6e
commit
649262a406
|
@ -431,17 +431,20 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||
self.live_server_url + reverse("autocomplete_admin:admin_views_answer_add")
|
||||
)
|
||||
elem = self.selenium.find_element(By.CSS_SELECTOR, ".select2-selection")
|
||||
elem.click() # Open the autocomplete dropdown.
|
||||
with self.select2_ajax_wait():
|
||||
elem.click() # Open the autocomplete dropdown.
|
||||
results = self.selenium.find_element(By.CSS_SELECTOR, ".select2-results")
|
||||
self.assertTrue(results.is_displayed())
|
||||
option = self.selenium.find_element(By.CSS_SELECTOR, ".select2-results__option")
|
||||
self.assertEqual(option.text, "No results found")
|
||||
elem.click() # Close the autocomplete dropdown.
|
||||
with self.select2_ajax_wait():
|
||||
elem.click() # Close the autocomplete dropdown.
|
||||
q1 = Question.objects.create(question="Who am I?")
|
||||
Question.objects.bulk_create(
|
||||
Question(question=str(i)) for i in range(PAGINATOR_SIZE + 10)
|
||||
)
|
||||
elem.click() # Reopen the dropdown now that some objects exist.
|
||||
with self.select2_ajax_wait():
|
||||
elem.click() # Reopen the dropdown now that some objects exist.
|
||||
result_container = self.selenium.find_element(
|
||||
By.CSS_SELECTOR, ".select2-results"
|
||||
)
|
||||
|
@ -478,7 +481,8 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||
".select2-results__option", 1, root_element=result_container
|
||||
)
|
||||
# Select the result.
|
||||
search.send_keys(Keys.RETURN)
|
||||
with self.select2_ajax_wait():
|
||||
search.send_keys(Keys.RETURN)
|
||||
select = Select(self.selenium.find_element(By.ID, "id_question"))
|
||||
self.assertEqual(
|
||||
select.first_selected_option.get_attribute("value"), str(q1.pk)
|
||||
|
@ -500,12 +504,14 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||
self.assertTrue(results.is_displayed())
|
||||
option = self.selenium.find_element(By.CSS_SELECTOR, ".select2-results__option")
|
||||
self.assertEqual(option.text, "No results found")
|
||||
elem.click() # Close the autocomplete dropdown.
|
||||
with self.select2_ajax_wait():
|
||||
elem.click() # Close the autocomplete dropdown.
|
||||
Question.objects.create(question="Who am I?")
|
||||
Question.objects.bulk_create(
|
||||
Question(question=str(i)) for i in range(PAGINATOR_SIZE + 10)
|
||||
)
|
||||
elem.click() # Reopen the dropdown now that some objects exist.
|
||||
with self.select2_ajax_wait():
|
||||
elem.click() # Reopen the dropdown now that some objects exist.
|
||||
result_container = self.selenium.find_element(
|
||||
By.CSS_SELECTOR, ".select2-results"
|
||||
)
|
||||
|
@ -536,12 +542,13 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||
self.assertCountSeleniumElements(
|
||||
".select2-results__option", 1, root_element=result_container
|
||||
)
|
||||
# Select the result.
|
||||
search.send_keys(Keys.RETURN)
|
||||
# Reopen the dropdown and add the first result to the selection.
|
||||
elem.click()
|
||||
search.send_keys(Keys.ARROW_DOWN)
|
||||
search.send_keys(Keys.RETURN)
|
||||
with self.select2_ajax_wait():
|
||||
# Select the result.
|
||||
search.send_keys(Keys.RETURN)
|
||||
# Reopen the dropdown and add the first result to the selection.
|
||||
elem.click()
|
||||
search.send_keys(Keys.ARROW_DOWN)
|
||||
search.send_keys(Keys.RETURN)
|
||||
select = Select(self.selenium.find_element(By.ID, "id_related_questions"))
|
||||
self.assertEqual(len(select.all_selected_options), 2)
|
||||
|
||||
|
|
|
@ -6111,6 +6111,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||
name_input.clear()
|
||||
name_input.send_keys("<i>edited section</i>")
|
||||
self.selenium.find_element(By.XPATH, '//input[@value="Save"]').click()
|
||||
self.wait_until(lambda d: len(d.window_handles) == 1, 1)
|
||||
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
||||
# Hide sidebar.
|
||||
toggle_button = self.selenium.find_element(
|
||||
|
@ -6133,6 +6134,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||
self.wait_for_text("#content h1", "Add section")
|
||||
self.selenium.find_element(By.ID, "id_name").send_keys("new section")
|
||||
self.selenium.find_element(By.XPATH, '//input[@value="Save"]').click()
|
||||
self.wait_until(lambda d: len(d.window_handles) == 1, 1)
|
||||
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
||||
select = Select(self.selenium.find_element(By.ID, "id_form-0-section"))
|
||||
self.assertEqual(select.first_selected_option.text, "new section")
|
||||
|
|
Loading…
Reference in New Issue