python unittests中的quit方法使用Selenium引发ConnectionResetError
我有一个使用Selenium for Chrome Webdriver进行集成测试的类,如下所示python unittests中的quit方法使用Selenium引发ConnectionResetError,python,selenium,unit-testing,selenium-webdriver,python-unittest,Python,Selenium,Unit Testing,Selenium Webdriver,Python Unittest,我有一个使用Selenium for Chrome Webdriver进行集成测试的类,如下所示 LoginTest.py 类LoginTest(StaticLiveServerTestCase): browser=CommonTest.set\u-up\u-webdriver() wait=WebDriverWait(浏览器,20) @类方法 def设置等级(cls): super(LoginTest,cls).setUpClass() cls.browser.maximize_window(
LoginTest.py
类LoginTest(StaticLiveServerTestCase):
browser=CommonTest.set\u-up\u-webdriver()
wait=WebDriverWait(浏览器,20)
@类方法
def设置等级(cls):
super(LoginTest,cls).setUpClass()
cls.browser.maximize_window()
cls.browser\u url=cls.live\u server\u url
cls.browser.get(cls.browser\u url)
@类方法
def拆卸类(cls):
super(LoginTest,cls).tearDownClass()
时间。睡眠(3)
cls.browser.quit()#此处出错
def设置(自):
super(LoginTest,self).setUp()
...
def拆卸(自):
super(LoginTest,self).tearDown()
CommonTest.py
类别测试:
@静力学方法
def设置Web驱动程序():
options=webdriver.chrome.options.options()
options.add_参数(“--disable dev shm usage”)
options.add_参数(“--no sandbox”)
返回webdriver.Chrome(可执行文件路径=Environment.Chrome驱动程序路径=WINDOWS路径,选项=options,
服务日志路径=constest.TEST日志路径)
当我删除行cls.browser.quit()时,我的测试工作正常。但它不会关闭Chrome浏览器。
如果我添加行cls.browser.quit()
它将得到错误:
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
我搜索了错误ConnectionResetError:[WinError 10054]一个现有连接被远程主机强制关闭了很多次
并添加了很多解决方案,但在按照当前实现使用时仍然出现该错误,脚本结束后将停止,subprocess.Popen
不会在\uuuuu del\uuuu
上发送信号,因此尝试在触发\uu del\uuuu
时关闭启动的进程
def __del__(self):
# `subprocess.Popen` doesn't send signal on `__del__`;
# so we attempt to close the launched process when `__del__`
# is triggered.
try:
self.stop()
except Exception:
pass