我正在为一个项目编写测试用例,并想测试我的登录功能。我正在使用LiveServerTestCase课程,selenium并在 Django 网站 [链接] ( https://docs.djangoproject.com/en/1.8/topics/testing/tools/ ) 中关注此文档。如果你看到下面的代码:
from django.test import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
class MySeleniumTests(LiveServerTestCase):
fixtures = ['user-data.json']
@classmethod
def setUpClass(cls):
super(MySeleniumTests, cls).setUpClass()
cls.selenium = WebDriver()
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super(MySeleniumTests, cls).tearDownClass()
def test_login(self):
self.selenium.get('%s%s' % (self.live_server_url, '/login/'))
username_input = self.selenium.find_element_by_name("username")
username_input.send_keys('rakesh')
password_input = self.selenium.find_element_by_name("password")
password_input.send_keys('ranjan')
self.selenium.find_element_by_xpath('//input[@value="Log in"]').click()
我的用户名是rakesh,密码是ranjan,我想知道为什么下面的代码在这里失败了?我正确地发送了我的参数,但它仍然不接受。
由于在每个测试用例上都会创建一个新数据库,是否也可以在上述代码中创建新用户和密码?我对编写测试用例特别陌生,将不胜感激。
Error: loaddata.py:225: UserWarning: No fixture named 'user-data' found.
warnings.warn("No fixture named '%s' found." % fixture_name)
我也无法理解你的意思fixtures = ['user-data.json']