【发布时间】:2015-08-18 22:40:18
【问题描述】:
在 Django 中,我尝试创建一个用户,然后尝试使用 selenium 登录该用户,但是当我运行测试失败时,它显示身份验证错误。这是我的代码:
class LoginFunctionalTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
# self.browser.get('http://localhost:8000')
def tearDown(self):
self.browser.quit()
def test_login_page(self):
self.browser.get('http://localhost:8000')
self.assertIn('Hiren->Login', self.browser.title)
def test_login_form(self):
self.browser.get('http://localhost:8000')
user = User.objects.create_user('testHiren', 'myemail@test.com', 'testPass')
user.save()
username = self.browser.find_element_by_id('username-id')
password = self.browser.find_element_by_id('password-id')
submit = self.browser.find_element_by_id('login-button')
username.send_keys('testHiren')
password.send_keys('testPass')
submit.click()
time.sleep(10) # if authentication successful its redirects to /dashboard
location = self.browser.current_url
self.assertEqual('http://localhost:8000/dashboard', location)
知道为什么会失败吗?
【问题讨论】:
-
发生了什么?有任何错误信息吗?
-
它显示来自浏览器登录方法的标准身份验证错误消息(用户名/密码不正确)。
标签: python django django-testing