Answer the question
In order to leave comments, you need to log in
How to create user in Selenium tests?
In both tests, print prints what should only be printed in the usucces test, even though the user has been created. What's the matter? And what is the best way to write an assert so that it checks for the presence of an element that falls under the selector?
from django.test import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
from django.contrib.auth.models import User
class MySeleniumTests(LiveServerTestCase):
def setUp(self):
self.selenium = WebDriver()
User.objects.create(username='admin', password='admin', email='')
def tearDown(self):
self.selenium.quit()
def test_login_success(self):
self.selenium.get(self.live_server_url)
username_input = self.selenium.find_element_by_id("id_username")
username_input.send_keys('admin')
password_input = self.selenium.find_element_by_id("id_password")
password_input.send_keys('admin')
self.selenium.find_element_by_css_selector('.btn-success').click()
print User.objects.all()
print self.selenium.find_element_by_css_selector(".alert").text
def test_login_unsuccess(self):
self.selenium.get(self.live_server_url)
username_input = self.selenium.find_element_by_id("id_username")
username_input.send_keys('adminw')
password_input = self.selenium.find_element_by_id("id_password")
password_input.send_keys('adminw')
self.selenium.find_element_by_css_selector('.btn-success').click()
print User.objects.all()
print self.selenium.find_element_by_css_selector(".alert").text
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question