Search code examples
node.jsselenium-webdriverhttp-proxynightwatch.js

Set proxy in nightwatch.js


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.


Solution

  • 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