samedi 17 octobre 2015

How to test login functionality using LiveServerTestCase and Selenium in Django

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] (http://ift.tt/1LzlrOc). 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. Thank you

Aucun commentaire:

Enregistrer un commentaire