From 294d0d88158fa83eb095d663d054038ce9dfc3d4 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 11 Jan 2016 11:28:03 -0500 Subject: [PATCH] Fixed #26048 -- Made admin selenium tests use implicitly_wait() --- django/contrib/admin/tests.py | 10 ++-------- docs/topics/testing/tools.txt | 1 + tests/admin_views/tests.py | 6 ++---- tests/admin_widgets/tests.py | 5 +---- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py index b1846c83d2..bcdc747571 100644 --- a/django/contrib/admin/tests.py +++ b/django/contrib/admin/tests.py @@ -37,6 +37,7 @@ class AdminSeleniumWebDriverTestCase(StaticLiveServerTestCase): except Exception as e: raise SkipTest('Selenium webdriver "%s" not installed or not ' 'operational: %s' % (cls.webdriver_class, str(e))) + cls.selenium.implicitly_wait(10) # This has to be last to ensure that resources are cleaned up properly! super(AdminSeleniumWebDriverTestCase, cls).setUpClass() @@ -63,13 +64,6 @@ class AdminSeleniumWebDriverTestCase(StaticLiveServerTestCase): """ self.wait_until(lambda d: len(d.window_handles) == num_windows, timeout) - def wait_loaded_tag(self, tag_name, timeout=10): - """ - Helper function that blocks until the element with the given tag name - is found on the page. - """ - self.wait_for(tag_name, timeout) - def wait_for(self, css_selector, timeout=10): """ Helper function that blocks until a CSS selector is found on the page. @@ -112,7 +106,7 @@ class AdminSeleniumWebDriverTestCase(StaticLiveServerTestCase): from selenium.common.exceptions import TimeoutException try: # Wait for the next page to be loaded - self.wait_loaded_tag('body') + self.wait_for('body') except TimeoutException: # IE7 occasionally returns an error "Internet Explorer cannot # display the webpage" and doesn't load the next page. We just diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index d66f8df5ba..e6e8fe52e9 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -900,6 +900,7 @@ The code for this test may look as follows:: def setUpClass(cls): super(MySeleniumTests, cls).setUpClass() cls.selenium = WebDriver() + cls.selenium.implicitly_wait(10) @classmethod def tearDownClass(cls): diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 6e278c8ae0..cb72c20975 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -4430,8 +4430,7 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase): self.admin_login(username='super', password='secret', login_url=reverse('admin:index')) self.selenium.get(full_url) self.selenium.find_element_by_class_name('deletelink').click() - # Wait until we're on the delete page. - self.wait_for('.cancel-link') + # Click 'cancel' on the delete page. self.selenium.find_element_by_class_name('cancel-link').click() # Wait until we're back on the change page. self.wait_for_text('#content h1', 'Change pizza') @@ -4452,8 +4451,7 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase): self.admin_login(username='super', password='secret', login_url=reverse('admin:index')) self.selenium.get(full_url) self.selenium.find_element_by_class_name('deletelink').click() - # Wait until we're on the delete page. - self.wait_for('.cancel-link') + # Click 'cancel' on the delete page. self.selenium.find_element_by_class_name('cancel-link').click() # Wait until we're back on the change page. self.wait_for_text('#content h1', 'Change pizza') diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index c8297f4bc9..ca395015f4 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -1154,7 +1154,6 @@ class HorizontalVerticalFilterSeleniumFirefoxTests(SeleniumDataMixin, AdminSelen # Navigate away and go back to the change form page. self.selenium.find_element_by_link_text('Home').click() self.selenium.back() - self.wait_for('#id_students_from') expected_unselected_values = [ str(self.arthur.id), str(self.bob.id), str(self.cliff.id), str(self.jason.id), str(self.jenny.id), str(self.john.id), @@ -1306,7 +1305,6 @@ class RelatedFieldWidgetSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWeb self.selenium.find_element_by_id('add_id_user').click() self.wait_for_popup() self.selenium.switch_to.window('id_user') - self.wait_for('#id_password') password_field = self.selenium.find_element_by_id('id_password') password_field.send_keys('password') @@ -1318,14 +1316,13 @@ class RelatedFieldWidgetSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWeb self.selenium.find_element_by_css_selector(save_button_css_selector).click() self.selenium.switch_to.window(main_window) # The field now contains the new user - self.wait_for('#id_user option[value="newuser"]') + self.assertSelectOptions('#id_user', ['', 'super', 'newuser']) # Click the Change User button to change it self.selenium.find_element_by_id('change_id_user').click() self.wait_for_popup() self.selenium.switch_to.window('id_user') - self.wait_for('#id_username') username_field = self.selenium.find_element_by_id('id_username') username_value = 'changednewuser' username_field.clear()