Made a couple of selenium tests wait for page loaded

The admin_widgets tests were issuing click() to the browser but
didn't wait for the effects of those clicks. This caused the resulting
request to be processed concurrently with the test case. When using
in-memory SQLite this caused weird failures.

Also added wait_page_loaded() to admin selenium tests for code
reuse.

Fixed #19856
This commit is contained in:
Anssi Kääriäinen 2013-02-20 03:08:55 +02:00
parent 4e36e0a8b3
commit 50677b29af
4 changed files with 21 additions and 22 deletions

View File

@ -41,6 +41,20 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase):
timeout 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/'): def admin_login(self, username, password, login_url='/admin/'):
""" """
Helper function to log into the admin. Helper function to log into the admin.
@ -53,8 +67,7 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase):
login_text = _('Log in') login_text = _('Log in')
self.selenium.find_element_by_xpath( self.selenium.find_element_by_xpath(
'//input[@value="%s"]' % login_text).click() '//input[@value="%s"]' % login_text).click()
# Wait for the next page to be loaded. self.wait_page_loaded()
self.wait_loaded_tag('body')
def get_css_value(self, selector, attribute): def get_css_value(self, selector, attribute):
""" """

View File

@ -546,15 +546,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_name('profile_set-2-last_name').send_keys('2 last name 2')
self.selenium.find_element_by_xpath('//input[@value="Save"]').click() self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
self.wait_page_loaded()
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
# Check that the objects have been created in the database # Check that the objects have been created in the database
self.assertEqual(ProfileCollection.objects.all().count(), 1) self.assertEqual(ProfileCollection.objects.all().count(), 1)

View File

@ -3262,16 +3262,7 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase):
# Save and check that everything is properly stored in the database # Save and check that everything is properly stored in the database
self.selenium.find_element_by_xpath('//input[@value="Save"]').click() self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
self.wait_page_loaded()
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.assertEqual(MainPrepopulated.objects.all().count(), 1) self.assertEqual(MainPrepopulated.objects.all().count(), 1)
MainPrepopulated.objects.get( MainPrepopulated.objects.get(
name=' this is the mAin nÀMë and it\'s awεšome', name=' this is the mAin nÀMë and it\'s awεšome',

View File

@ -644,11 +644,13 @@ class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCas
self.selenium.get( self.selenium.get(
'%s%s' % (self.live_server_url, '/admin_widgets/school/%s/' % self.school.id)) '%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('vertical', 'students')
self.execute_basic_operations('horizontal', 'alumni') self.execute_basic_operations('horizontal', 'alumni')
# Save and check that everything is properly stored in the database --- # Save and check that everything is properly stored in the database ---
self.selenium.find_element_by_xpath('//input[@value="Save"]').click() 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.school = models.School.objects.get(id=self.school.id) # Reload from database
self.assertEqual(list(self.school.students.all()), self.assertEqual(list(self.school.students.all()),
[self.arthur, self.cliff, self.jason, self.john]) [self.arthur, self.cliff, self.jason, self.john])
@ -728,6 +730,7 @@ class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCas
# Save and check that everything is properly stored in the database --- # Save and check that everything is properly stored in the database ---
self.selenium.find_element_by_xpath('//input[@value="Save"]').click() 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.school = models.School.objects.get(id=self.school.id) # Reload from database
self.assertEqual(list(self.school.students.all()), self.assertEqual(list(self.school.students.all()),
[self.jason, self.peter]) [self.jason, self.peter])