我是python新手。我正在尝试将StaticLiveServerTestCase
与Python一起使用来登录到Django管理门户。我正在使用下面的代码。运行以下代码将启动管理门户,但我无法使用凭据登录。如果我遗漏了什么,请告诉我。谢谢!在
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
class MySeleniumTests(StaticLiveServerTestCase):
port = 0
host = <<my host>>
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.selenium = WebDriver()
cls.selenium.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().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('myuser')
password_input = self.selenium.find_element_by_name("password")
password_input.send_keys('secret')
self.selenium.find_element_by_xpath('//input[@value="Log in"]').click()
在安装程序中使用create_superuser方法解决了这个问题。下面的代码解决了这个问题。在
您尚未在测试数据库中创建用户。在the example in the docs中,它使用固定装置
'user-data.json'
。在{cd2>中的另一个用户}。在
相关问题 更多 >
编程相关推荐