在nightwatch.js中设置代理

我在Node.js应用程序中使用nightwatch.js编写集成testing。 对于特定的testing用例,我希望通过proxy连接夜间手表。 什么是正确的方法来做到这一点? 我从官方文档或Google集团找不到任何东西。

Selenium文档build议按照此处所述将其设置在webdriver实例上。 我不知道如何通过守夜做到这一点。

nightwatch.jsonconfiguration文件中,您应该能够在desiredCapabilities中设置代理参数:

 "chrome" : { "desiredCapabilities": { "browserName": "chrome", "javascriptEnabled": true, "acceptSslCerts": true, "chromeOptions" : { "args" : [ "disable-extensions", "start-maximized" ] }, "proxy": { "proxyType": "manual", "httpProxy": "your_proxy:8080" } } }, 

查看这个文档: https : //code.google.com/p/selenium/wiki/JsonWireProtocol#Proxy_JSON_Object

我在searchsocks5代理解决scheme时偶然发现了这个问题。 当我从使用socksProxy属性的JsonWireProtocol文档中使用实现时,我总是得到以下错误:

 message: 'unknown error: cannot parse capability: proxy from unknown error: proxyType is \'manual\' but no manual proxy capabilities were found 

使用通过proxy.pac文件configuration的socks5代理 – proxyType: 'pac'使用proxyAutoconfigUrl proxyType: 'pac'没有任何问题。 但是这不适合我的用例。

经过一些摆弄之后,我终于find了解决这个问题的两个办法:

  1. 使用CLI参数为chromedriver
 desiredCapabilities: { browserName: 'chrome', /* … */ chromeOptions: { args: [ '--proxy-server=socks5://proxy_url:proxy_port' ] } } 

*编辑:看起来像这样已被删除
2.使用sslProxy属性
由于袜子代理理论上只不过是一个ssl隧道,我认为我可以给这个财产另一个尝试。 使它终于正常工作的解决scheme如下所示:

 desiredCapabilities: { browserName: 'chrome', /* … */ proxy: { proxyType: 'manual', sslProxy: 'socks5://proxy_url:proxy_port' } } 

希望回答帮助任何人寻找关于socks5代理的帮助。 🙂
但更重要的是,在未来,电动汽车将正确实施JsonWireProtocol。

Nightwatch更改了nightwatch.conf.js文件中的代理对象在开始使用代理代理而不是http代理时的工作原理,不幸的是,它似乎没有logging在任何地方。 但它仍然存在,你只需要在代理对象中传递不同的参数。 它接受的“协议”列在proxy-agent github上。请参阅下面的示例。

 firefox: { desiredCapabilities: { browserName: 'firefox', version: 'latest', }, proxy: { host:'127.0.0.1', port:8001, protocol: 'http', }, },