Python 硒测试在第一次测试后失败
我正在尝试运行我为Debian服务器上的Django项目编写的selenium测试,使用xvfb 我正在尝试运行3个测试,在第一个测试之后,它们失败并出现以下错误: NoSuchElementException:消息:u'无法定位元素:Python 硒测试在第一次测试后失败,python,django,selenium,Python,Django,Selenium,我正在尝试运行我为Debian服务器上的Django项目编写的selenium测试,使用xvfb 我正在尝试运行3个测试,在第一个测试之后,它们失败并出现以下错误: NoSuchElementException:消息:u'无法定位元素:{“方法”:“xpath”,“选择器”:”//a[@href=\\\“\\\”\\\“]”}' 我已经运行了export DISPLAY=:99,并且正在使用Django LiveServerTestCase和Django selenium。 SELENIUM\u
{“方法”:“xpath”,“选择器”:”//a[@href=\\\“\\\”\\\“]”}'
我已经运行了export DISPLAY=:99
,并且正在使用Django LiveServerTestCase和Django selenium。
SELENIUM\u DISPLAY=':99'
在my settings.py中设置
这是我的测试跑步者:
class BaseLiveTest(LiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.selenium = WebDriver()
super(BaseLiveTest, cls).setUpClass()
@classmethod
def tearDownClass(cls):
super(BaseLiveTest, cls).tearDownClass()
cls.selenium.quit()
def login(self, user):
#helper function, to log in users
#go to login page
self.selenium.get("%s%s" % (self.live_server_url, reverse('userena_signin')))
#wait for page to display
WebDriverWait(self.selenium, 10).until(
lambda x: self.selenium.find_element_by_id('id_identification'),
)
#fill in form and submit
identifictation_input = self.selenium.find_element_by_id('id_identification')
identifictation_input.send_keys(user.email)
password_input = self.selenium.find_element_by_id("id_password")
password_input.send_keys('password')
self.selenium.find_element_by_xpath('//form/descendant::button[@type="submit"]').click()
#wait for dashboard to load
WebDriverWait(self.selenium, 10).until(
lambda x: self.selenium.find_element_by_id('container'),
)
当我单独运行每个测试时,它们都通过了,但是如果我尝试一个接一个地运行它们,最后两个测试就会失败。有什么想法吗?你需要使用
setUp()
和tearDown()
,而不是setUpClass()
和tearDown()
。类版本在整个fixture中全局运行,因此所有3个测试都使用相同的WebDriver
实例,因此浏览器不会处于第二次和第三次测试所期望的状态。有什么想法说明为什么这会在本地而不是在服务器上工作吗?在本地,我使用Firefox webdriver运行OSX。服务器是Debian、xvfb和iceweasel。测试可以逐个运行,但不能按顺序运行。每次运行1显式地,类级安装程序将在每个测试中运行一次。