PhantomJS 无法访问自签名 HTTPS 页面 Codeception
Posted
技术标签:
【中文标题】PhantomJS 无法访问自签名 HTTPS 页面 Codeception【英文标题】:PhantomJS cannot visit Self-signed HTTPS pages Codeception 【发布时间】:2016-06-22 04:35:19 【问题描述】:我目前正在使用以下工具进行验收测试:
密码接收 Selenium 网络驱动程序 PhantomJS (作为无头浏览器幽灵)我的问题是访问自签名 (https) 页面时我的测试失败
我尝试过的:
phantomjs --webdriver=5555 --ignore-ssl-errors=true --ssl-protocol=any
在我的acceptance.suit.yml 中添加phantomjs.cli.args: ["--ignore-ssl-errors=true"]
功能
到目前为止,这些选项并没有给我带来任何运气。
这是我的acceptance.suit.yml
文件
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: https://myproject.com
browser: firefox
capabilities:
unexpectedAlertBehaviour: 'accept'
env:
phantom:
modules:
enabled:
- WebDriver
config:
WebDriver:
url: https://myproject.com
http_proxy: 192.1.1.1
http_proxy_port: 3000
browser: phantomjs
capabilities:
phantomjs.cli.args: ["--ignore-ssl-errors=true"]
更新
这个错误出现[ModuleException] WebDriver: Current url is blank, no page was opened
我不知道为什么会发生这个错误,因为我已经指出了一个页面。这是我的测试样本
public function tryToTestThis(AcceptanceTester $I)
$I->wantTo('Test this function');
$I->amOnPage('/mypage/');
$I->see('This text');
Codeception 中的答案会更好。谢谢
【问题讨论】:
您能否详细说明发生了什么?任何错误,测试如何失败?谢谢。 @alecxe 嗨,我更新了我的帖子。它说[ModuleException] WebDriver: Current url is blank, no page was opened
我能够复制您的错误并使用 --ignore-ssl-errors=true 运行 phantomjs 使我的测试通过。唯一的区别是我没有使用 http_proxy 和 http_proxy_port,你检查过你的代理吗?
@MajicBob 是的,我已经确定我的代理是正确的。我不确定的是,如果它设置http_proxy
代码接收的正确方法没有显示任何设置http_proxy
和http_proxy_port
的示例
@Þaw 是的,那里的文档不是很好,我之前没有将它与代理一起使用。我能想到的唯一其他事情是确保您看到请求进入您的代理并尝试将 2 个设置移动到模块:部分而不是 env。
【参考方案1】:
如果出现此问题,我们已找出原因。这是因为我同时运行Selenium
和phantomJS
。 (我从一些教程中得到了这个想法。)
我在做
java -jar selenium.jar
然后我这样做是因为它会导致在端口 4444 运行 phantomjs 时出错(显然 selenium 正在使用它)我改用端口 5555。
phantomjs --webdriver=5555 --ignore-ssl-errors=true --ssl-protocol=any
注意:如果不涉及 https / ssl 自签名页面,一切正常。
我们认为 codeception
优先考虑端口 4444 并忽略我的 phantomjs 中指示的任何选项,即 --ignore-ssl-errors=true --ssl-protocol=any
这就是为什么无法访问 https/自签名页面的原因。
所以基本上,修复只是在没有硒的情况下单独运行 phantomjs。
phantomjs --webdriver=4444 --ignore-ssl-errors=true --ssl-protocol=any
谢谢
【讨论】:
以上是关于PhantomJS 无法访问自签名 HTTPS 页面 Codeception的主要内容,如果未能解决你的问题,请参考以下文章
在 aws 弹性负载均衡器上无法让 https 使用自签名证书