【发布时间】:2017-08-09 11:26:39
【问题描述】:
我需要使用 PhantomJS 为使用 https 的站点运行 Protractor 测试。这是一个开发环境,证书是自签名的,不被 PhantomJS 识别。我正在使用 --ignore-ssl-errors 标志启动 PhantomJS,这应该使它接受无效的证书,但这不起作用。在 CLI 中:
phantomjs --webdriver=localhost:4444 --web-security=false --ignore-ssl-errors=true --ssl-protocol=any
尽管有这些设置,webdriver 的 acceptSslCerts 属性仍设置为 false。从日志中:
Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"mac-unknown-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
在相关的 GhostDriver 回购问题 (https://github.com/detro/ghostdriver/pull/388) 中列出了以下代码:
const capabilities = webdriver.Capabilities.phantomjs();
capabilities.set(webdriver.Capability.ACCEPT_SSL_CERTS, true);
capabilities.set(webdriver.Capability.SECURE_SSL, false);
capabilities.set('phantomjs.cli.args', ['--web-security=no', '--ssl-protocol=any', '--ignore-ssl-errors=yes']);
const driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome(), capabilities).build();
我尝试在 protractor.conf.js 中进行设置:
capabilities: {
browserName: 'phantomjs',
'webdriver.Capability.ACCEPT_SSL_CERTS': true,
'webdriver.Capability.SECURE_SSL': false
}
但这没有任何效果。
有人知道如何在 https 模式下运行 PhatomJS 吗?
【问题讨论】:
标签: selenium ssl https phantomjs protractor