mirror of https://github.com/django/django.git
Refs #494 -- Fixed a flaky admin_inlines tests.
This commit is contained in:
parent
294d0d8815
commit
99d2469e75
|
@ -99,6 +99,28 @@ class AdminSeleniumWebDriverTestCase(StaticLiveServerTestCase):
|
||||||
timeout
|
timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def wait_until_visible(self, css_selector, timeout=10):
|
||||||
|
"""
|
||||||
|
Block until the element described by the CSS selector is visible.
|
||||||
|
"""
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.support import expected_conditions as ec
|
||||||
|
self.wait_until(
|
||||||
|
ec.visibility_of_element_located((By.CSS_SELECTOR, css_selector)),
|
||||||
|
timeout
|
||||||
|
)
|
||||||
|
|
||||||
|
def wait_until_invisible(self, css_selector, timeout=10):
|
||||||
|
"""
|
||||||
|
Block until the element described by the CSS selector is invisible.
|
||||||
|
"""
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.support import expected_conditions as ec
|
||||||
|
self.wait_until(
|
||||||
|
ec.invisibility_of_element_located((By.CSS_SELECTOR, css_selector)),
|
||||||
|
timeout
|
||||||
|
)
|
||||||
|
|
||||||
def wait_page_loaded(self):
|
def wait_page_loaded(self):
|
||||||
"""
|
"""
|
||||||
Block until page has started to load.
|
Block until page has started to load.
|
||||||
|
|
|
@ -879,19 +879,19 @@ class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
|
||||||
self.admin_login(username='super', password='secret')
|
self.admin_login(username='super', password='secret')
|
||||||
self.selenium.get(self.live_server_url + reverse('admin:admin_inlines_author_add'))
|
self.selenium.get(self.live_server_url + reverse('admin:admin_inlines_author_add'))
|
||||||
# One field is in a stacked inline, other in a tabular one.
|
# One field is in a stacked inline, other in a tabular one.
|
||||||
test_fields = ['id_nonautopkbook_set-0-title', 'id_nonautopkbook_set-2-0-title']
|
test_fields = ['#id_nonautopkbook_set-0-title', '#id_nonautopkbook_set-2-0-title']
|
||||||
show_links = self.selenium.find_elements_by_link_text('SHOW')
|
show_links = self.selenium.find_elements_by_link_text('SHOW')
|
||||||
self.assertEqual(len(show_links), 2)
|
self.assertEqual(len(show_links), 2)
|
||||||
for show_index, field_name in enumerate(test_fields, 0):
|
for show_index, field_name in enumerate(test_fields, 0):
|
||||||
self.assertFalse(self.selenium.find_element_by_id(field_name).is_displayed())
|
self.wait_until_invisible(field_name)
|
||||||
show_links[show_index].click()
|
show_links[show_index].click()
|
||||||
self.assertTrue(self.selenium.find_element_by_id(field_name).is_displayed())
|
self.wait_until_visible(field_name)
|
||||||
hide_links = self.selenium.find_elements_by_link_text('HIDE')
|
hide_links = self.selenium.find_elements_by_link_text('HIDE')
|
||||||
self.assertEqual(len(hide_links), 2)
|
self.assertEqual(len(hide_links), 2)
|
||||||
for hide_index, field_name in enumerate(test_fields, 0):
|
for hide_index, field_name in enumerate(test_fields, 0):
|
||||||
self.assertTrue(self.selenium.find_element_by_id(field_name).is_displayed())
|
self.wait_until_visible(field_name)
|
||||||
hide_links[hide_index].click()
|
hide_links[hide_index].click()
|
||||||
self.assertFalse(self.selenium.find_element_by_id(field_name).is_displayed())
|
self.wait_until_invisible(field_name)
|
||||||
|
|
||||||
|
|
||||||
class SeleniumChromeTests(SeleniumFirefoxTests):
|
class SeleniumChromeTests(SeleniumFirefoxTests):
|
||||||
|
|
Loading…
Reference in New Issue