diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py index 9d94127b34..a66e89f06d 100644 --- a/django/contrib/admin/tests.py +++ b/django/contrib/admin/tests.py @@ -49,6 +49,20 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase): timeout ) + def wait_page_loaded(self): + """ + Block until page has started to load. + """ + from selenium.common.exceptions import TimeoutException + try: + # Wait for the next page to be loaded + self.wait_loaded_tag('body') + except TimeoutException: + # IE7 occasionnally returns an error "Internet Explorer cannot + # display the webpage" and doesn't load the next page. We just + # ignore it. + pass + def admin_login(self, username, password, login_url='/admin/'): """ Helper function to log into the admin. @@ -61,8 +75,7 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase): login_text = _('Log in') self.selenium.find_element_by_xpath( '//input[@value="%s"]' % login_text).click() - # Wait for the next page to be loaded. - self.wait_loaded_tag('body') + self.wait_page_loaded() def get_css_value(self, selector, attribute): """ diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py index 8b620cc57d..27c6431458 100644 --- a/tests/regressiontests/admin_inlines/tests.py +++ b/tests/regressiontests/admin_inlines/tests.py @@ -445,15 +445,7 @@ class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): self.selenium.find_element_by_name('profile_set-2-last_name').send_keys('2 last name 2') self.selenium.find_element_by_xpath('//input[@value="Save"]').click() - - try: - # Wait for the next page to be loaded. - self.wait_loaded_tag('body') - except TimeoutException: - # IE7 occasionnally returns an error "Internet Explorer cannot - # display the webpage" and doesn't load the next page. We just - # ignore it. - pass + self.wait_page_loaded() # Check that the objects have been created in the database self.assertEqual(ProfileCollection.objects.all().count(), 1) @@ -502,4 +494,4 @@ class SeleniumChromeTests(SeleniumFirefoxTests): webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' class SeleniumIETests(SeleniumFirefoxTests): - webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver' \ No newline at end of file + webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver' diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 5531cb4e96..b695453e17 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -3034,16 +3034,7 @@ class SeleniumPrePopulatedFirefoxTests(AdminSeleniumWebDriverTestCase): # Save and check that everything is properly stored in the database self.selenium.find_element_by_xpath('//input[@value="Save"]').click() - - try: - # Wait for the next page to be loaded. - self.wait_loaded_tag('body') - except TimeoutException: - # IE7 occasionnally returns an error "Internet Explorer cannot - # display the webpage" and doesn't load the next page. We just - # ignore it. - pass - + self.wait_page_loaded() self.assertEqual(MainPrepopulated.objects.all().count(), 1) MainPrepopulated.objects.get( name=u' this is the mAin nÀMë and it\'s awεšome', diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py index 87e0309ddc..974f4d1007 100644 --- a/tests/regressiontests/admin_widgets/tests.py +++ b/tests/regressiontests/admin_widgets/tests.py @@ -597,12 +597,14 @@ class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCas self.selenium.get( '%s%s' % (self.live_server_url, '/admin_widgets/school/%s/' % self.school.id)) + self.wait_page_loaded() self.execute_basic_operations('vertical', 'students') self.execute_basic_operations('horizontal', 'alumni') # Save and check that everything is properly stored in the database --- self.selenium.find_element_by_xpath('//input[@value="Save"]').click() - self.school = models.School.objects.get(id=self.school.id) # Reload from database + self.wait_page_loaded() + self.school = models.School.objects.get(id=self.school.id) # Reload from database self.assertEqual(list(self.school.students.all()), [self.arthur, self.cliff, self.jason, self.john]) self.assertEqual(list(self.school.alumni.all()), @@ -681,6 +683,7 @@ class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCas # Save and check that everything is properly stored in the database --- self.selenium.find_element_by_xpath('//input[@value="Save"]').click() + self.wait_page_loaded() self.school = models.School.objects.get(id=self.school.id) # Reload from database self.assertEqual(list(self.school.students.all()), [self.jason, self.peter]) @@ -691,4 +694,4 @@ class HorizontalVerticalFilterSeleniumChromeTests(HorizontalVerticalFilterSeleni webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' class HorizontalVerticalFilterSeleniumIETests(HorizontalVerticalFilterSeleniumFirefoxTests): - webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver' \ No newline at end of file + webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'