I'm writing Integration Tests using nightwatch.js
in a Node.js
application. For a particular test case, I want nightwatch to connect via a proxy
. What would be the right way to do this? I can't find anything from its official documentation, or from its Google Group.
The Selenium
documentation suggests setting it on the webdriver instance as described here. I'm not sure how to do this via nightwatch.
In the nightwatch.json configuration file, you should be able to set a proxy parameter in the desiredCapabilities:
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions" : {
"args" : [
"disable-extensions",
"start-maximized"
]
},
"proxy": {
"proxyType": "manual",
"httpProxy": "your_proxy:8080"
}
}
},
Check this doc: https://code.google.com/p/selenium/wiki/JsonWireProtocol#Proxy_JSON_Object
I stumbled over this Question on my search for socks5 proxy solution.
When I used the implementation from the JsonWireProtocol documentation using the socksProxy
property, I always got the following error:
message: 'unknown error: cannot parse capability: proxy from unknown error:
proxyType is \'manual\' but no manual proxy capabilities were found
Using a socks5 proxy configured via a proxy.pac file - proxyType: 'pac'
using proxyAutoconfigUrl
was working without any problem. But this wasn't suitable for my use case.
After some fiddling around, I finally found two solutions to that problem:
desiredCapabilities: {
browserName: 'chrome',
/* … */
chromeOptions: {
args: [
'--proxy-server=socks5://proxy_url:proxy_port'
]
}
}
*edit: looks like this has been removed 2. Using sslProxy property
Since socks proxy is in theory nothing more than a ssl tunnel I thought I could give that property another try. The solution that made it finally working looked like this:
desiredCapabilities: {
browserName: 'chrome',
/* … */
proxy: {
proxyType: 'manual',
sslProxy: 'socks5://proxy_url:proxy_port'
}
}
Hope that answer help anyone looking for help regarding socks5 proxy. :)
But more important would be that chromedriver will implement the JsonWireProtocol properly in the future.
Nightwatch changed how the proxy object in the nightwatch.conf.js
file works when they started using proxy-agent instead of http-proxy, unfortunately it seems to not be documented anywhere. But it does still exist you just need to pass in different parameters in the proxy object. The 'protocols' it accepts are listed on the proxy-agent github See below for an example.
firefox: {
desiredCapabilities: {
browserName: 'firefox',
version: 'latest',
},
proxy: {
host:'127.0.0.1',
port:8001,
protocol: 'http',
},
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With