nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Only the "default" test env runs when I call nightwatch.runner(argv, done, settings); in a JS file #775

Closed OLmitch closed 8 years ago

OLmitch commented 8 years ago

Hi Nightwatch, thanks for the platform it'll help us speed up our BrowserStack testing by 5x thanks to your parallel processing support.

Can you help me understand what I'm doing wrong here? Every time I run Nightwatch from within a JS file only a test for the "default" test environment option runs.

I'm calling Nightwatch from within a JavaScript file like so:

index.js

try {
  var argv = {
      test: 'nightwatch/example.js',
      config: '../nightwatch.json',
      env : 'windows_10_safari_5_1,windows_10_chrome_46'
  };

  nightwatch.cli(function(argv) {
    nightwatch.runner(argv, done, settings);
  })
} catch (error) {
  console.log('Exception:' + error.message);
}

But when I call nightwatch.runner(argv, done, settings); only the "default" test env runs, and "windows_10_safari_5_1" nor "windows_10_chrome_46" runs. This happens when I only use one of them as the env value as well.

nightwatch.json

{
  "src_folders": [
    "nightwatch\/"
  ],
  "selenium": {
    "start_process": false,
    "host": "hub.browserstack.com",
    "port": 80
  },
  "test_settings": {
    "default": {
      "launch_url": "http:\/\/hub.browserstack.com",
      "selenium_port": 80,
      "selenium_host": "hub.browserstack.com",
      "silent": true,
      "screenshots": {
        "enabled": false,
        "path": ""
      },
      "desiredCapabilities": {
        "browser": "internet explorer",
        "os": "Windows",
        "browser_version": "11.0",
        "os_version": "10",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "browserstack.user": <username>,
        "browserstack.key": <access key>
      }
    },
    "windows_10_chrome_46": {
      "launch_url": "http:\/\/hub.browserstack.com",
      "selenium_port": 80,
      "selenium_host": "hub.browserstack.com",
      "silent": true,
      "screenshots": {
        "enabled": false,
        "path": ""
      },
      "desiredCapabilities": {
        "browser": "Chrome",
        "os": "Windows",
        "browser_version": "46.0",
        "os_version": "10",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "browserstack.user": <username>,
        "browserstack.key": <access key>
      }
    },
    "windows_10_safari_5_1": {
      "launch_url": "http:\/\/hub.browserstack.com",
      "selenium_port": 80,
      "selenium_host": "hub.browserstack.com",
      "silent": true,
      "screenshots": {
        "enabled": false,
        "path": ""
      },
      "desiredCapabilities": {
        "browser": "Safari",
        "os": "Windows",
        "browser_version": "5.1",
        "os_version": "10",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "browserstack.user": <username>,
        "browserstack.key": <access key>
      }
    }
  }
}

Is there something I'm doing wrong? Thanks!

OLmitch commented 8 years ago

Ahh got it. I was using:

  nightwatch.cli(function(argv) {
    nightwatch.runner(argv, done, settings);
  })

And I noticed using .cli() didn't make sense when I could run runner directly, so my code now looks like this:

try {
  var argv = {
      test: 'nightwatch/example.js',
      config: 'nightwatch.json',
      env: 'windows_10_safari_5_1'
  };
  nightwatch.runner(argv, done, settings);
} catch (error) {
  console.log('Exception:' + error.message);
}

I don't know why what I was doing before was failing, but I'm glad it's working now. Thanks again