Refs #494 -- Fixed a flaky admin_inlines tests.

This commit is contained in:
Tim Graham 2016-01-11 12:25:56 -05:00
parent 294d0d8815
commit 99d2469e75
2 changed files with 27 additions and 5 deletions

View File

@ -99,6 +99,28 @@ class AdminSeleniumWebDriverTestCase(StaticLiveServerTestCase):
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):
"""
Block until page has started to load.

View File

@ -879,19 +879,19 @@ class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
self.admin_login(username='super', password='secret')
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.
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')
self.assertEqual(len(show_links), 2)
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()
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')
self.assertEqual(len(hide_links), 2)
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()
self.assertFalse(self.selenium.find_element_by_id(field_name).is_displayed())
self.wait_until_invisible(field_name)
class SeleniumChromeTests(SeleniumFirefoxTests):