mercredi 1 avril 2020

Django testing - logging in with Selenium not working

I'm trying to test the login page of a django app using Selenium - but I keep getting the error message 'Your email and password do not match'.

from django.test import LiveServerTestCase
from selenium import webdriver

from accounts.models import User, Project

class TestInitiationFlow(LiveServerTestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()
        self.user = User.objects.create(email='user@test.co.uk', admin=True)
        self.user.set_password('Test1234')

        self.assertEqual(User.objects.count(), 1)
        self.assertTrue(User.objects.get(email='user@test.co.uk'))

        self.assertFalse(Project.objects.first())

    def tearDown(self):
        self.browser.quit()

    def test_initiating_new_project(self):

        # The user navigates to the homepage of the app
        # And sees the login screen
        self.browser.get(self.live_server_url)

        # The user enters an email and password
        username_input = self.browser.find_element_by_id('id_username')
        password_input = self.browser.find_element_by_id('id_password')
        submit_button = self.browser.find_element_by_id('submit_button')

        username_input.send_keys('user@test.co.uk')
        password_input.send_keys('Test1234')

        # The user presses enter and is taken to the startup screen

        submit_button.click()

        self.assertEqual(self.browser.current_url, self.live_server_url+'/startup')

Any help gratefully received!

Aucun commentaire:

Enregistrer un commentaire