Skip to content

Instantly share code, notes, and snippets.

@bennylope
Created April 24, 2012 20:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennylope/2483172 to your computer and use it in GitHub Desktop.
Save bennylope/2483172 to your computer and use it in GitHub Desktop.
from django.test import LiveServerTestCase
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.webdriver import WebDriver
class MySeleniumTests(LiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.selenium = WebDriver()
super(MySeleniumTests, cls).setUpClass()
@classmethod
def tearDownClass(cls):
super(MySeleniumTests, cls).tearDownClass()
cls.selenium.quit()
def test_form(self):
self.selenium.get('%s%s' % (self.live_server_url, '/'))
username = self.selenium.find_element_by_name('username')
username.send_keys('bennylope')
self.selenium.find_element_by_name('submit').click()
def test_form_validation(self):
"""Validate the form with JavaScript"""
self.selenium.get('%s%s' % (self.live_server_url, '/'))
first_name = self.selenium.find_element_by_name('first_name')
first_name.send_keys('ben')
last_name = self.selenium.find_element_by_name('last_name')
last_name.send_keys('lopatin')
self.selenium.find_elements(By.XPATH, "//input[@value='benlopatin']")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment