Fixed #29892 -- Added explicit Selenium wait in admin autocomplete tests.
This commit is contained in:
parent
f47ba7e780
commit
c33eb6dcd0
|
@ -1,5 +1,5 @@
|
||||||
import json
|
import json
|
||||||
import time
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.admin.tests import AdminSeleniumTestCase
|
from django.contrib.admin.tests import AdminSeleniumTestCase
|
||||||
|
@ -162,6 +162,21 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
)
|
)
|
||||||
self.admin_login(username='super', password='secret', login_url=reverse('autocomplete_admin:index'))
|
self.admin_login(username='super', password='secret', login_url=reverse('autocomplete_admin:index'))
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def select2_ajax_wait(self, timeout=10):
|
||||||
|
from selenium.common.exceptions import NoSuchElementException
|
||||||
|
from selenium.webdriver.support import expected_conditions as ec
|
||||||
|
yield
|
||||||
|
with self.disable_implicit_wait():
|
||||||
|
try:
|
||||||
|
loading_element = self.selenium.find_element_by_css_selector(
|
||||||
|
'li.select2-results__option.loading-results'
|
||||||
|
)
|
||||||
|
except NoSuchElementException:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.wait_until(ec.staleness_of(loading_element), timeout=timeout)
|
||||||
|
|
||||||
def test_select(self):
|
def test_select(self):
|
||||||
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
|
||||||
|
@ -183,19 +198,19 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
self.assertEqual(len(results), PAGINATOR_SIZE + 1)
|
self.assertEqual(len(results), PAGINATOR_SIZE + 1)
|
||||||
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.
|
||||||
for _ in range(len(results)):
|
with self.select2_ajax_wait():
|
||||||
search.send_keys(Keys.ARROW_DOWN)
|
for _ in range(len(results)):
|
||||||
|
search.send_keys(Keys.ARROW_DOWN)
|
||||||
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
# All objects and "Loading more results".
|
# All objects are now loaded.
|
||||||
self.assertEqual(len(results), PAGINATOR_SIZE + 11)
|
self.assertEqual(len(results), PAGINATOR_SIZE + 11)
|
||||||
# Limit the results with the search field.
|
# Limit the results with the search field.
|
||||||
search.send_keys('Who')
|
with self.select2_ajax_wait():
|
||||||
# Ajax request is delayed.
|
search.send_keys('Who')
|
||||||
self.assertTrue(result_container.is_displayed())
|
# Ajax request is delayed.
|
||||||
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
self.assertTrue(result_container.is_displayed())
|
||||||
self.assertEqual(len(results), PAGINATOR_SIZE + 12)
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
# Wait for ajax delay.
|
self.assertEqual(len(results), PAGINATOR_SIZE + 12)
|
||||||
time.sleep(0.25)
|
|
||||||
self.assertTrue(result_container.is_displayed())
|
self.assertTrue(result_container.is_displayed())
|
||||||
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
|
@ -224,18 +239,18 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
self.assertEqual(len(results), PAGINATOR_SIZE + 1)
|
self.assertEqual(len(results), PAGINATOR_SIZE + 1)
|
||||||
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.
|
||||||
for _ in range(len(results)):
|
with self.select2_ajax_wait():
|
||||||
search.send_keys(Keys.ARROW_DOWN)
|
for _ in range(len(results)):
|
||||||
|
search.send_keys(Keys.ARROW_DOWN)
|
||||||
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
self.assertEqual(len(results), 31)
|
self.assertEqual(len(results), 31)
|
||||||
# Limit the results with the search field.
|
# Limit the results with the search field.
|
||||||
search.send_keys('Who')
|
with self.select2_ajax_wait():
|
||||||
# Ajax request is delayed.
|
search.send_keys('Who')
|
||||||
self.assertTrue(result_container.is_displayed())
|
# Ajax request is delayed.
|
||||||
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
self.assertTrue(result_container.is_displayed())
|
||||||
self.assertEqual(len(results), 32)
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
# Wait for ajax delay.
|
self.assertEqual(len(results), 32)
|
||||||
time.sleep(0.25)
|
|
||||||
self.assertTrue(result_container.is_displayed())
|
self.assertTrue(result_container.is_displayed())
|
||||||
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
|
|
Loading…
Reference in New Issue