From 3bc6b18cb92462ff5ae54efd0fce5340e9149b0f Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Fri, 3 Jan 2014 11:25:24 +0100 Subject: [PATCH] Fixed selenium failure. This fixes (at least according to tests on the ci itself) admin_widgets.tests.RelatedFieldWidgetSeleniumFirefoxTests.test_foreign_key_using_to_field (http://ci.djangoproject.com/job/Django/database=mysql_gis,python=python2.7/3792/testReport/junit/admin_widgets.tests/RelatedFieldWidgetSeleniumFirefoxTests/test_foreign_key_using_to_field/) The cause for this issue seems to be that wait_page_loaded was executed before click fired and as such no profile got saved (again just an educated guess, but with this fix I can no longer reproduce it -- fingers crossed). --- django/contrib/admin/tests.py | 12 ++++++++++++ tests/admin_widgets/tests.py | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py index 72cb0606f3..40fd10089b 100644 --- a/django/contrib/admin/tests.py +++ b/django/contrib/admin/tests.py @@ -69,6 +69,18 @@ class AdminSeleniumWebDriverTestCase(StaticLiveServerCase): """ from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as ec + self.wait_until( + ec.text_to_be_present_in_element( + (By.CSS_SELECTOR, css_selector), text), + timeout + ) + + def wait_for_value(self, css_selector, text, timeout=10): + """ + Helper function that blocks until the value is found in the css selector. + """ + from selenium.webdriver.common.by import By + from selenium.webdriver.support import expected_conditions as ec self.wait_until( ec.text_to_be_present_in_element_value( (By.CSS_SELECTOR, css_selector), text), diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 794cd7924c..29dd5750ae 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -993,7 +993,7 @@ class AdminRawIdWidgetSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): # The field now contains the selected band's id self.selenium.switch_to_window(main_window) - self.wait_for_text('#id_main_band', '42') + self.wait_for_value('#id_main_band', '42') # Reopen the popup window and click on another band self.selenium.find_element_by_id('lookup_id_main_band').click() @@ -1005,7 +1005,7 @@ class AdminRawIdWidgetSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): # The field now contains the other selected band's id self.selenium.switch_to_window(main_window) - self.wait_for_text('#id_main_band', '98') + self.wait_for_value('#id_main_band', '98') def test_many_to_many(self): self.admin_login(username='super', password='secret', login_url='/') @@ -1028,7 +1028,7 @@ class AdminRawIdWidgetSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): # The field now contains the selected band's id self.selenium.switch_to_window(main_window) - self.wait_for_text('#id_supporting_bands', '42') + self.wait_for_value('#id_supporting_bands', '42') # Reopen the popup window and click on another band self.selenium.find_element_by_id('lookup_id_supporting_bands').click() @@ -1040,7 +1040,7 @@ class AdminRawIdWidgetSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): # The field now contains the two selected bands' ids self.selenium.switch_to_window(main_window) - self.wait_for_text('#id_supporting_bands', '42,98') + self.wait_for_value('#id_supporting_bands', '42,98') class AdminRawIdWidgetSeleniumChromeTests(AdminRawIdWidgetSeleniumFirefoxTests): @@ -1084,7 +1084,7 @@ class RelatedFieldWidgetSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): # Go ahead and submit the form to make sure it works self.selenium.find_element_by_css_selector(save_button_css_selector).click() - self.wait_page_loaded() + self.wait_for_text('li.success', 'The profile "newuser" was added successfully.') profiles = models.Profile.objects.all() self.assertEqual(len(profiles), 1) self.assertEqual(profiles[0].user.username, username_value)