class SeleniumTestCase(LiveServerTestCase): def _pre_setup(self): super(SeleniumTestCase, self)._pre_setup() self.driver = PhantomJS() def _post_teardown(self): self.driver.quit() super(SeleniumTestCase, self)._post_teardown() def login(self, username='******', password='******', url='login'): """ Login to the server and be authenticated """ self.open(reverse(url)) self.driver.find_element_by_id("id_username").clear() self.driver.find_element_by_id("id_username").send_keys(username) self.driver.find_element_by_id("id_password").clear() self.driver.find_element_by_id("id_password").send_keys(password) self.driver.find_element_by_id("submit-id-login").click() def open(self, url): self.driver.get("%s%s" %(self.live_server_url, url)) def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException, e: return False return True