我正在非公开网页上运行非常复杂的硒测试。在大多数情况下,这些测试运行良好,但是有时它们在webdriver.quit()
方法中失败!
以下是错误的示例:
bsp_usecase_tests/tools/selNG.py:299: in quit
self.webdriver.quit()
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py:187: in quit
RemoteWebDriver.quit(self)
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py:606: in quit
self.execute(Command.QUIT)
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py:311: in execute
self.error_handler.check_response(response)[0m
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f091b065550>
response = {'status': 500, 'value': '{"value":{"error":"session not created","message":"Tried to run command without establishing...s::imp::thread::{{impl}}::new::thread_start\n at /checkout/src/libstd/sys/unix/thread.rs:84"}}'}
使用过的软件包:
顶级工作流程
mydriver = webdriver.Firefox(firefox_profile=profile, log_path=logfile)
...
do a single test here. Navigate to URL, login, click etc.
...
mydriver.stop_client()
mydriver.quit()
该错误大约在所有情况下的1-2%中出现...
在这里应该采取的正确措施是什么?
答案 0 :(得分:0)
根据 Selenium-Python API文档 ,stop_client()
在执行quit()
命令后被调用。可以重写此方法来定义自定义关闭行为。
源代码:
def stop_client(self):
"""
Called after executing a quit command. This method may be overridden to define custom shutdown behavior.
"""
pass
此错误消息...
bsp_usecase_tests/tools/selNG.py:299: in quit
self.webdriver.quit()
self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f091b065550>
response = {'status': 500, 'value': '{"value":{"error":"session not created","message":"Tried to run command without establishing...s::imp::thread::{{impl}}::new::thread_start\n
......意味着在调用quit()
方法时,由于没有活动的会话,所以返回了'status': 500
。
在您的代码块中:
stop_client()
,该代码在您的项目代码中被覆盖以定义自定义关闭行为。quit()
。如下反转代码行将解决您的问题:
mydriver = webdriver.Firefox(firefox_profile=profile, log_path=logfile)
...
do a single test here. Navigate to URL, login, click etc.
...
mydriver.quit()
mydriver.stop_client()