Skip to content

Instantly share code, notes, and snippets.

@jphalip
Created November 5, 2011 10:58
Show Gist options
  • Save jphalip/1341392 to your computer and use it in GitHub Desktop.
Save jphalip/1341392 to your computer and use it in GitHub Desktop.
More Selenium tests for the Django admin
class AdminInlinesSeleniumTests(SeleniumTestCase):
fixtures = ['admin-views-users.xml']
urls = "regressiontests.admin_inlines.urls"
def admin_login(self, username, password):
"""
Helper function to log into the admin.
"""
self.selenium.open('/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(3000)
def test_add_inlines(self):
"""
Ensure that the "Add another XXX" link correctly adds items to the
inline form.
"""
self.admin_login(username='super', password='secret')
self.selenium.open('/admin/admin_inlines/titlecollection/add/')
# Check that there's only one inline to start with and that it has the
# correct ID.
self.failUnlessEqual(self.selenium.get_css_count(
'css=#title_set-group table tr.dynamic-title_set'), 1)
self.failUnless(self.selenium.get_attribute(
'css=.dynamic-title_set:nth-of-type(1)@id'), 'title_set-0')
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-0 input[name=title_set-0-title1]'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-0 input[name=title_set-0-title2]'))
# Add an inline
self.selenium.click("link=Add another Title")
# Check that the inline has been added, that it has the right id, and
# that it contains the right fields.
self.failUnlessEqual(self.selenium.get_css_count(
'css=#title_set-group table tr.dynamic-title_set'), 2)
self.failUnless(self.selenium.get_attribute(
'css=.dynamic-title_set:nth-of-type(2)@id'), 'title_set-1')
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-1 input[name=title_set-1-title1]'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-1 input[name=title_set-1-title2]'))
# Let's add another one to be sure
self.selenium.click("link=Add another Title")
self.failUnlessEqual(self.selenium.get_css_count(
'css=#title_set-group table tr.dynamic-title_set'), 3)
self.failUnless(self.selenium.get_attribute(
'css=.dynamic-title_set:nth-of-type(3)@id'), 'title_set-2')
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-2 input[name=title_set-2-title1]'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-2 input[name=title_set-2-title2]'))
def test_delete_inlines(self):
self.admin_login(username='super', password='secret')
self.selenium.open('/admin/admin_inlines/titlecollection/add/')
# Add a few inlines
self.selenium.click("link=Add another Title")
self.selenium.click("link=Add another Title")
self.selenium.click("link=Add another Title")
self.selenium.click("link=Add another Title")
self.failUnlessEqual(self.selenium.get_css_count(
'css=#title_set-group table tr.dynamic-title_set'), 5)
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-0'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-1'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-2'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-3'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-4'))
# Click on a few delete buttons
self.selenium.click(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-1 td.delete a')
self.selenium.click(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-2 td.delete a')
# Verify that they're gone and that the IDs have been re-sequenced
self.failUnlessEqual(self.selenium.get_css_count(
'css=#title_set-group table tr.dynamic-title_set'), 3)
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-0'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-1'))
self.failUnless(self.selenium.is_element_present(
'css=form#titlecollection_form tr.dynamic-title_set#title_set-2'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment