Nightwatch: Running nightwatch tests in a browser with CORS disables

Created on 2 Aug 2016  路  8Comments  路  Source: nightwatchjs/nightwatch

I am writing a selection of end to end tests using nightwatch. These tests call out to an external API, which has CORS settings that deny requests from localhost accessing the API.

For development on localhost I have installed a browser plugin that allows me to turn of the requirement of CORS. In chrome I can pass.

I have found an alternative method of handling the CORS settings and that is to start the browser with flags as follows. chromium-browser --disable-web-security --user-data-dir. Is there anyway to tell nightwatch to pass this arguments when it starts up chrome/chromium

Most helpful comment

@beatfactor , I followed your link and I set:
"desiredCapabilities" : { "chromeOptions" : { "args" : ["disable-web-security"] } }
And, it doesn't work. I've tried several variations, such as
"desiredCapabilities" : { "chromeOptions" : { "args" : ["--disable-web-security"] } }
and placing it inside Chrome, test_settings and selenium hashes. Does Nightwatch actualy allow
disable-web-security?

All 8 comments

It's not something I've done personally, but it looks like the path you need to take is:

I have this in my nightwatch.conf.js. to no effect.

"cli_args": {
      "webdriver.chrome.driver": require('chromedriver').path,
      "webdriver.chrome.args": "--disable-web-security --user-data-dir"
    }

You need to specify your chrome args in the chromeOptions property of your desiredCapabilities, as seen here: https://github.com/nightwatchjs/nightwatch/wiki/Chrome-Setup#command-line-switches.

@beatfactor , I followed your link and I set:
"desiredCapabilities" : { "chromeOptions" : { "args" : ["disable-web-security"] } }
And, it doesn't work. I've tried several variations, such as
"desiredCapabilities" : { "chromeOptions" : { "args" : ["--disable-web-security"] } }
and placing it inside Chrome, test_settings and selenium hashes. Does Nightwatch actualy allow
disable-web-security?

This worked for me in nightwatch.json:

"test_settings": { "chrome":{ "desiredCapabilities": { "chromeOptions" : { "args" : ["--disable-web-security"] } } } }

@michaelscheurer This would be useful to be documented somewhere in the Wiki.

@michaelscheurer i am trying to disable web security for Safari and Firefox but had no luck. Any ideas?

The config doesn't work for me through Android Chrome.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakebl picture dakebl  路  4Comments

lgaticaq picture lgaticaq  路  3Comments

jvlaar picture jvlaar  路  4Comments

manjero picture manjero  路  4Comments

MateuszJeziorski picture MateuszJeziorski  路  3Comments