我已经创建了一个配置文件,根据在运行时选择的浏览器选择我的desired_capabilities。
@pytest.fixture(scope='session')
def driver(request):
browser_name = request.config.getoption('--browser')
hub_address = request.config.getoption('--hub-address')
local = request.config.getoption('--local')
if local:
_driver = getattr(webdriver, browser_name.title())()
else:
# This is a hack to get around Chrome's sandbox not working inside of a docker container
if browser_name == 'chrome':
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
desired_capabilities = options.to_capabilities()
if browser_name == 'ie':
desired_capabilities = getattr(DesiredCapabilities, "INTERNETEXPLORER")
else: # firefox
desired_capabilities = getattr(DesiredCapabilities, browser_name.upper())
context = {
'command_executor': 'http://{hub_address}/wd/hub'.format(hub_address=hub_address),
'desired_capabilities': desired_capabilities,
}
_driver = webdriver.Remote(**context)
def fin():
# pass
_driver.close()
_driver.quit()
request.addfinalizer(fin)
return _driver
因此典型的运行命令如下所示:
py.test -vv -s --orion=<ip> --hub-address=localhost:4444 --browser=chrome test_myTest.py
我有Chrome&amp; Firefox工作正常,但我的问题是我打开网页时弹出的安全证书。如何禁用IE的安全页面?
我尝试添加以下内容:
options = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy()
options['acceptSslCerts'] = True
desired_capabilities = getattr(options, "INTERNETEXPLORER")
在最后一行失败了......
E AttributeError:&#39; dict&#39;对象没有属性&#39; INTERNETEXPLORER&#39;。
我也试过......
desired_capabilities = getattr(DesiredCapabilities, "INTERNETEXPLORER")
desired_capabilities['acceptSslCerts'] = True
测试运行了,但我不得不手动点击安全证书警告以使其消失。