【发布时间】:2018-07-20 02:24:11
【问题描述】:
我有一个非常复杂的py.test python-selenium 测试设置,我在py.test 固定装置内创建了一个Firefox webdriver。以下是我在做什么的一些想法:
'driver.py':
class Driver(object):
"""
Driver class with basic wrappers around the selenium webdriver
and other convenience methods.
"""
def __init__(self, config, options):
"""Sets the driver and the config.
"""
self.remote = options.getoption("--remote")
self.headless = not options.getoption("--with-head")
if self.headless:
self.display = Display(visible=0, size=(13660, 7680))
self.display.start()
# Start the selenium webdriver
self.webdriver = fixefox_module.get_driver()
'conftest.py':
@pytest.fixture
def basedriver(config, options):
driver = driver.Driver(config, options)
yield driver
print("Debug 1")
driver.webdriver.quit()
print("Debug 2")
在运行测试时,我只能看到 Debug 1 打印出来。整个过程在这一点上停止,似乎没有继续进行。整个硒测试卡在webdriver.quit)。
但是,测试成功完成...
这种行为可能是什么原因?
附录:
执行挂起的原因似乎是由于未保存数据而询问用户是否要离开页面的弹出窗口。这意味着quit 方法的文档不正确。它指出:
Quits the driver and close every associated window.
【问题讨论】:
-
最常见的 selenium 异常是由 selenium 驱动程序不匹配引起的。您的 geckodriver 版本是否与您正在测试的 Firefox 版本匹配?
-
测试工作正常。只是webdriver的
quit方法似乎卡住了…… -
您可以先尝试使用
driver.webdriver.close()方法吗?那个工作正常吗? -
这会产生错误
SessionNotCreatedException: Message: Tried to run command without establishing a connection... -
奇怪,我在这个问题 (github.com/mozilla/geckodriver/issues/1071) 中看到了一条评论,证实了我的想法:如果只打开一个浏览器窗口并且您使用 driver.close(),它应该退出 webdriver 会话。 你还有其他调试日志吗?