Skip to content

Commit

Permalink
Enabled the existing admin Selenium tests to be run with Internet Exp…
Browse files Browse the repository at this point in the history
…lorer. Note that some tweaks had to be made, in particular as IE7 has limited capabilities regarding CSS selectors.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17666 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
julien committed Mar 5, 2012
1 parent 797b677 commit 4694263
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 25 deletions.
4 changes: 2 additions & 2 deletions django/contrib/admin/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_select_option(self, selector, value):
identified by the CSS selector `selector`. identified by the CSS selector `selector`.
""" """
from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchElementException
options = self.selenium.find_elements_by_css_selector('%s option' % selector) options = self.selenium.find_elements_by_css_selector('%s > option' % selector)
for option in options: for option in options:
if option.get_attribute('value') == value: if option.get_attribute('value') == value:
return option return option
Expand All @@ -90,7 +90,7 @@ def assertSelectOptions(self, selector, values):
Asserts that the <SELECT> widget identified by `selector` has the Asserts that the <SELECT> widget identified by `selector` has the
options with the given `values`. options with the given `values`.
""" """
options = self.selenium.find_elements_by_css_selector('%s option' % selector) options = self.selenium.find_elements_by_css_selector('%s > option' % selector)
actual_values = [] actual_values = []
for option in options: for option in options:
actual_values.append(option.get_attribute('value')) actual_values.append(option.get_attribute('value'))
Expand Down
47 changes: 29 additions & 18 deletions tests/regressiontests/admin_inlines/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -394,46 +394,47 @@ def test_add_inlines(self):
Ensure that the "Add another XXX" link correctly adds items to the Ensure that the "Add another XXX" link correctly adds items to the
inline form. inline form.
""" """
from selenium.common.exceptions import TimeoutException
self.admin_login(username='super', password='secret') self.admin_login(username='super', password='secret')
self.selenium.get('%s%s' % (self.live_server_url, self.selenium.get('%s%s' % (self.live_server_url,
'/admin/admin_inlines/profilecollection/add/')) '/admin/admin_inlines/profilecollection/add/'))


# Check that there's only one inline to start with and that it has the # Check that there's only one inline to start with and that it has the
# correct ID. # correct ID.
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'#profile_set-group table tr.dynamic-profile_set')), 1) '.dynamic-profile_set')), 1)
self.failUnlessEqual(self.selenium.find_element_by_css_selector( self.failUnlessEqual(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set:nth-of-type(1)').get_attribute('id'), '.dynamic-profile_set')[0].get_attribute('id'),
'profile_set-0') 'profile_set-0')
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-0 input[name=profile_set-0-first_name]')), 1) '.dynamic-profile_set#profile_set-0 input[name=profile_set-0-first_name]')), 1)
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-0 input[name=profile_set-0-last_name]')), 1) '.dynamic-profile_set#profile_set-0 input[name=profile_set-0-last_name]')), 1)


# Add an inline # Add an inline
self.selenium.find_element_by_link_text('Add another Profile').click() self.selenium.find_element_by_link_text('Add another Profile').click()


# Check that the inline has been added, that it has the right id, and # Check that the inline has been added, that it has the right id, and
# that it contains the right fields. # that it contains the right fields.
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'#profile_set-group table tr.dynamic-profile_set')), 2) '.dynamic-profile_set')), 2)
self.failUnlessEqual(self.selenium.find_element_by_css_selector( self.failUnlessEqual(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set:nth-of-type(2)').get_attribute('id'), 'profile_set-1') '.dynamic-profile_set')[1].get_attribute('id'), 'profile_set-1')
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-1 input[name=profile_set-1-first_name]')), 1) '.dynamic-profile_set#profile_set-1 input[name=profile_set-1-first_name]')), 1)
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-1 input[name=profile_set-1-last_name]')), 1) '.dynamic-profile_set#profile_set-1 input[name=profile_set-1-last_name]')), 1)


# Let's add another one to be sure # Let's add another one to be sure
self.selenium.find_element_by_link_text('Add another Profile').click() self.selenium.find_element_by_link_text('Add another Profile').click()
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'#profile_set-group table tr.dynamic-profile_set')), 3) '.dynamic-profile_set')), 3)
self.failUnlessEqual(self.selenium.find_element_by_css_selector( self.failUnlessEqual(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set:nth-of-type(3)').get_attribute('id'), 'profile_set-2') '.dynamic-profile_set')[2].get_attribute('id'), 'profile_set-2')
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-2 input[name=profile_set-2-first_name]')), 1) '.dynamic-profile_set#profile_set-2 input[name=profile_set-2-first_name]')), 1)
self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector( self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-2 input[name=profile_set-2-last_name]')), 1) '.dynamic-profile_set#profile_set-2 input[name=profile_set-2-last_name]')), 1)


# Enter some data and click 'Save' # Enter some data and click 'Save'
self.selenium.find_element_by_name('profile_set-0-first_name').send_keys('0 first name 1') self.selenium.find_element_by_name('profile_set-0-first_name').send_keys('0 first name 1')
Expand All @@ -442,10 +443,17 @@ def test_add_inlines(self):
self.selenium.find_element_by_name('profile_set-1-last_name').send_keys('1 last name 2') self.selenium.find_element_by_name('profile_set-1-last_name').send_keys('1 last name 2')
self.selenium.find_element_by_name('profile_set-2-first_name').send_keys('2 first name 1') self.selenium.find_element_by_name('profile_set-2-first_name').send_keys('2 first name 1')
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()


# Wait for the next page to be loaded. try:
self.wait_loaded_tag('body') # 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)
Expand Down Expand Up @@ -491,4 +499,7 @@ def test_delete_inlines(self):




class SeleniumChromeTests(SeleniumFirefoxTests): class SeleniumChromeTests(SeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'

class SeleniumIETests(SeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
18 changes: 16 additions & 2 deletions tests/regressiontests/admin_views/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2934,6 +2934,7 @@ def test_basic(self):
main form and with stacked and tabular inlines. main form and with stacked and tabular inlines.
Refs #13068, #9264, #9983, #9784. Refs #13068, #9264, #9983, #9784.
""" """
from selenium.common.exceptions import TimeoutException
self.admin_login(username='super', password='secret', login_url='/test_admin/admin/') self.admin_login(username='super', password='secret', login_url='/test_admin/admin/')
self.selenium.get('%s%s' % (self.live_server_url, self.selenium.get('%s%s' % (self.live_server_url,
'/test_admin/admin/admin_views/mainprepopulated/add/')) '/test_admin/admin/admin_views/mainprepopulated/add/'))
Expand All @@ -2958,7 +2959,7 @@ def test_basic(self):
self.assertEqual(slug2, 'option-one-here-stacked-inline') self.assertEqual(slug2, 'option-one-here-stacked-inline')


# Add an inline # Add an inline
self.selenium.find_element_by_css_selector('#relatedprepopulated_set-group .add-row a').click() self.selenium.find_elements_by_link_text('Add another Related Prepopulated')[0].click()
self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-pubdate').send_keys('1999-01-25') self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-pubdate').send_keys('1999-01-25')
self.get_select_option('#id_relatedprepopulated_set-1-status', 'option two').click() self.get_select_option('#id_relatedprepopulated_set-1-status', 'option two').click()
self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-name').send_keys(u' now you haVe anöther sŤāÇkeð inline with a very ... loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text... ') self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-name').send_keys(u' now you haVe anöther sŤāÇkeð inline with a very ... loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text... ')
Expand All @@ -2978,7 +2979,7 @@ def test_basic(self):
self.assertEqual(slug2, 'option-two-and-now-tabular-inline') self.assertEqual(slug2, 'option-two-and-now-tabular-inline')


# Add an inline # Add an inline
self.selenium.find_element_by_css_selector('#relatedprepopulated_set-2-group .add-row a').click() self.selenium.find_elements_by_link_text('Add another Related Prepopulated')[1].click()
self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-2-1-pubdate').send_keys('1981-08-22') self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-2-1-pubdate').send_keys('1981-08-22')
self.get_select_option('#id_relatedprepopulated_set-2-1-status', 'option one').click() self.get_select_option('#id_relatedprepopulated_set-2-1-status', 'option one').click()
self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-2-1-name').send_keys(u'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters') self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-2-1-name').send_keys(u'a tÃbűlaŘ inline with ignored ;"&*^\%$#@-/`~ characters')
Expand All @@ -2989,6 +2990,16 @@ def test_basic(self):


# 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()

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=u' this is the mAin nÀMë and it\'s awεšome', name=u' this is the mAin nÀMë and it\'s awεšome',
Expand Down Expand Up @@ -3031,6 +3042,9 @@ def test_basic(self):
class SeleniumPrePopulatedChromeTests(SeleniumPrePopulatedFirefoxTests): class SeleniumPrePopulatedChromeTests(SeleniumPrePopulatedFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'


class SeleniumPrePopulatedIETests(SeleniumPrePopulatedFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'



class ReadonlyTest(TestCase): class ReadonlyTest(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
Expand Down
12 changes: 9 additions & 3 deletions tests/regressiontests/admin_widgets/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ def test_show_hide_date_time_picker_widgets(self):
class DateTimePickerSeleniumChromeTests(DateTimePickerSeleniumFirefoxTests): class DateTimePickerSeleniumChromeTests(DateTimePickerSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'


class DateTimePickerSeleniumIETests(DateTimePickerSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'



class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
Expand Down Expand Up @@ -515,7 +518,7 @@ def execute_basic_operations(self, mode, field_name):
elif mode == 'vertical': elif mode == 'vertical':
# There 's no 'Choose all' button in vertical mode, so individually # There 's no 'Choose all' button in vertical mode, so individually
# select all options and click 'Choose'. # select all options and click 'Choose'.
for option in self.selenium.find_elements_by_css_selector(from_box + ' option'): for option in self.selenium.find_elements_by_css_selector(from_box + ' > option'):
option.click() option.click()
self.selenium.find_element_by_id(choose_link).click() self.selenium.find_element_by_id(choose_link).click()
self.assertSelectOptions(from_box, []) self.assertSelectOptions(from_box, [])
Expand All @@ -532,7 +535,7 @@ def execute_basic_operations(self, mode, field_name):
elif mode == 'vertical': elif mode == 'vertical':
# There 's no 'Remove all' button in vertical mode, so individually # There 's no 'Remove all' button in vertical mode, so individually
# select all options and click 'Remove'. # select all options and click 'Remove'.
for option in self.selenium.find_elements_by_css_selector(to_box + ' option'): for option in self.selenium.find_elements_by_css_selector(to_box + ' > option'):
option.click() option.click()
self.selenium.find_element_by_id(remove_link).click() self.selenium.find_element_by_id(remove_link).click()
self.assertSelectOptions(from_box, self.assertSelectOptions(from_box,
Expand Down Expand Up @@ -685,4 +688,7 @@ def test_filter(self):
[self.jason, self.peter]) [self.jason, self.peter])


class HorizontalVerticalFilterSeleniumChromeTests(HorizontalVerticalFilterSeleniumFirefoxTests): class HorizontalVerticalFilterSeleniumChromeTests(HorizontalVerticalFilterSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'

class HorizontalVerticalFilterSeleniumIETests(HorizontalVerticalFilterSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'

0 comments on commit 4694263

Please sign in to comment.