【问题标题】:PhantomJS over HTTPSHTTPS 上的 PhantomJS
【发布时间】: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


    【解决方案1】:

    我目前面临同样的问题。尝试了您告诉的所有替代方案,但似乎没有任何效果。

    唯一真正有效(对我的项目不可行,但可能对你的项目不可行)是实例化传递 service_args 的 webdriver,如下所示:

    Python:

    webdriver.PhantomJS(executable_path='/home/rodrigo/bin/phantomjs-2.1.1-linux-x86_64/bin/phantomjs',
                        desired_capabilities=dict(DesiredCapabilities.PHANTOMJS),
                        service_args=['--web-security=no', '--ssl-protocol=any', '--ignore-ssl-errors=yes'])
    

    希望它对你的帮助大于对我的帮助。

    【讨论】:

      猜你喜欢
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多