Skip to content

Instantly share code, notes, and snippets.

@jphalip
Created November 5, 2011 06:01
Show Gist options
  • Save jphalip/1341169 to your computer and use it in GitHub Desktop.
Save jphalip/1341169 to your computer and use it in GitHub Desktop.
What could soon become the first Django admin Selenium test...
class SeleniumTests(SeleniumTestCase):
fixtures = ['admin-views-users.xml']
urls = "regressiontests.admin_views.urls"
def admin_login(self, username, password):
"""
Helper function to log into the admin.
"""
self.selenium.open('/test_admin/admin/')
self.selenium.type('username', username)
self.selenium.type('password', password)
self.selenium.click("//input[@value='Log in']")
self.selenium.wait_for_page_to_load(5000)
def get_css_value(self, selector, attribute):
"""
Helper function that returns the value for the CSS attribute of an
DOM element specified by the given selector.
"""
return self.selenium.get_eval(
'selenium.browserbot.getCurrentWindow().django'
'.jQuery("%s").css("%s")' % (selector, attribute))
def test_show_hide_date_time_picker_widgets(self):
"""
Ensure that pressing the ESC key closes the date and time picker
widgets.
Refs #17064.
"""
self.admin_login(username='super', password='secret')
# Open a page that has a date and time picker widgets
self.selenium.open('/test_admin/admin/admin_views/reservation/add/')
# First, with the date picker widget ---------------------------------
# Check that the date picker is hidden
self.assertEqual(
self.get_css_value('#calendarbox0', 'display'), 'none')
# Click the calendar icon
self.selenium.click('id=calendarlink0')
# Check that the date picker is visible
self.assertEqual(
self.get_css_value('#calendarbox0', 'display'), 'block')
# Press the ESC key
self.selenium.key_up('css=html', '27')
# Check that the date picker is hidden again
self.assertEqual(
self.get_css_value('#calendarbox0', 'display'), 'none')
# Then, with the time picker widget ----------------------------------
# Check that the time picker is hidden
self.assertEqual(
self.get_css_value('#clockbox0', 'display'), 'none')
# Click the time icon
self.selenium.click('id=clocklink0')
# Check that the time picker is visible
self.assertEqual(
self.get_css_value('#clockbox0', 'display'), 'block')
# Press the ESC key
self.selenium.key_up('css=html', '27')
# Check that the time picker is hidden again
self.assertEqual(
self.get_css_value('#clockbox0', 'display'), 'none')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment