mirror of
https://github.com/django/django.git
synced 2025-05-07 15:36:29 +00:00
Made SeleniumTests.test_select_multiple less flaky by improving Selenium waits.
This commit is contained in:
parent
86ae1a3b6c
commit
71a813a72c
@ -493,6 +493,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_select_multiple(self):
|
def test_select_multiple(self):
|
||||||
|
from selenium.common import NoSuchElementException
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
from selenium.webdriver.support.ui import Select
|
from selenium.webdriver.support.ui import Select
|
||||||
@ -519,7 +520,7 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||||||
result_container = self.selenium.find_element(
|
result_container = self.selenium.find_element(
|
||||||
By.CSS_SELECTOR, ".select2-results"
|
By.CSS_SELECTOR, ".select2-results"
|
||||||
)
|
)
|
||||||
self.assertTrue(result_container.is_displayed())
|
self.assertIs(result_container.is_displayed(), True)
|
||||||
self.assertCountSeleniumElements(
|
self.assertCountSeleniumElements(
|
||||||
".select2-results__option",
|
".select2-results__option",
|
||||||
PAGINATOR_SIZE + 1,
|
PAGINATOR_SIZE + 1,
|
||||||
@ -527,8 +528,8 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||||||
)
|
)
|
||||||
search = self.selenium.find_element(By.CSS_SELECTOR, ".select2-search__field")
|
search = self.selenium.find_element(By.CSS_SELECTOR, ".select2-search__field")
|
||||||
# Load next page of results by scrolling to the bottom of the list.
|
# Load next page of results by scrolling to the bottom of the list.
|
||||||
with self.select2_ajax_wait():
|
for _ in range(PAGINATOR_SIZE + 1):
|
||||||
for _ in range(PAGINATOR_SIZE + 1):
|
with self.select2_ajax_wait():
|
||||||
search.send_keys(Keys.ARROW_DOWN)
|
search.send_keys(Keys.ARROW_DOWN)
|
||||||
self.assertCountSeleniumElements(
|
self.assertCountSeleniumElements(
|
||||||
".select2-results__option", 31, root_element=result_container
|
".select2-results__option", 31, root_element=result_container
|
||||||
@ -537,11 +538,11 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||||||
with self.select2_ajax_wait():
|
with self.select2_ajax_wait():
|
||||||
search.send_keys("Who")
|
search.send_keys("Who")
|
||||||
# Ajax request is delayed.
|
# Ajax request is delayed.
|
||||||
self.assertTrue(result_container.is_displayed())
|
self.assertIs(result_container.is_displayed(), True)
|
||||||
self.assertCountSeleniumElements(
|
self.assertCountSeleniumElements(
|
||||||
".select2-results__option", 32, root_element=result_container
|
".select2-results__option", 32, root_element=result_container
|
||||||
)
|
)
|
||||||
self.assertTrue(result_container.is_displayed())
|
self.assertIs(result_container.is_displayed(), True)
|
||||||
|
|
||||||
self.assertCountSeleniumElements(
|
self.assertCountSeleniumElements(
|
||||||
".select2-results__option", 1, root_element=result_container
|
".select2-results__option", 1, root_element=result_container
|
||||||
@ -549,8 +550,18 @@ class SeleniumTests(AdminSeleniumTestCase):
|
|||||||
with self.select2_ajax_wait():
|
with self.select2_ajax_wait():
|
||||||
# Select the result.
|
# Select the result.
|
||||||
search.send_keys(Keys.RETURN)
|
search.send_keys(Keys.RETURN)
|
||||||
# Reopen the dropdown and add the first result to the selection.
|
with self.disable_implicit_wait():
|
||||||
|
with self.assertRaises(NoSuchElementException):
|
||||||
|
self.selenium.find_element(By.CSS_SELECTOR, ".select2-results")
|
||||||
|
with self.select2_ajax_wait():
|
||||||
|
# Reopen the dropdown.
|
||||||
elem.click()
|
elem.click()
|
||||||
|
result_container = self.selenium.find_element(
|
||||||
|
By.CSS_SELECTOR, ".select2-results"
|
||||||
|
)
|
||||||
|
self.assertIs(result_container.is_displayed(), True)
|
||||||
|
with self.select2_ajax_wait():
|
||||||
|
# Add the first result to the selection.
|
||||||
search.send_keys(Keys.ARROW_DOWN)
|
search.send_keys(Keys.ARROW_DOWN)
|
||||||
search.send_keys(Keys.RETURN)
|
search.send_keys(Keys.RETURN)
|
||||||
select = Select(self.selenium.find_element(By.ID, "id_related_questions"))
|
select = Select(self.selenium.find_element(By.ID, "id_related_questions"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user