Set proxy in nightwatch.js
Asked Answered
E

3

5

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.

Edmiston answered 21/5, 2015 at 21:38 Comment(0)
P
6

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

Packing answered 22/5, 2015 at 10:15 Comment(1)
if u need to auth with proxy "httpProxy": "your_login:your_password@your_proxy:8080" Mitis
R
3

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:

  1. Using CLI args for chromedriver
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.

Rap answered 30/1, 2017 at 16:0 Comment(2)
when using option 2 Chrome just ignores the settingPodite
@Podite I just tried it again. Sadly I can confirm this. Could be that it has been removed. If I find a new way how to do it, I'll update my postRap
H
2

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',
      },
    },
Hoodwink answered 8/9, 2017 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.