在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)
知道它失败的原因吗?
答案 0 :(得分:-1)
所以我只是想通了这个FN测试是使用默认数据库而不是测试数据库,所以我改变了流程