I am writing test cases for a project, and want to test my login functionality. I am using LiveServerTestCase class, selenium and following this documentation in Django website [link] (https://docs.djangoproject.com/en/1.8/topics/testing/tools/). If you see the code below :
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()
My username is rakesh and password is ranjan, and I am wondering why the following code fails here? I am sending my parameters correctly, but still it is not accepting.
Since on every test case a new database is created, is there a way to create new user and password in the above code as well? I am particularly new to writing test cases and will appreciate any help.
Error: loaddata.py:225: UserWarning: No fixture named 'user-data' found.
warnings.warn("No fixture named '%s' found." % fixture_name)
I am also not able to understand what do you mean by fixtures = ['user-data.json']