George Bryant
George Bryant

Reputation: 51

How do I get Nightwatch.js to run tests on Internet Explorer

I'm trying to run some basic nightwatch tests in Internet Explorer, Chrome, and Firefox. While I can get chrome and firefox to work, I cannot for the life of me make Internet Explorer work. I've tried searching through this site, and found this answer in particular, but it was no help. Naturally, I've also looked through the nightwatch documentation to no avail

Here is my nightwatch.conf.js file:

const BINPATH = './node_modules/nightwatch/bin/';

// we use a nightwatch.conf.js file so we can include comments and helper functions
module.exports = {
  "src_folders": ["test"],// Where you are storing your Nightwatch e2e tests
  "output_folder": "./reports", // reports (test outcome) output by nightwatch
  "selenium": { // downloaded by selenium-download module
    "start_process": true, // tells nightwatch to start/stop the selenium process
    "server_path": "./node_modules/nightwatch/bin/selenium.jar",
    "host": "127.0.0.1",
    "port": 4444, // standard selenium port
    "cli_args": { // chromedriver is downloaded by selenium-download (see readme)
      "webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver",
      "webdriver.ie.driver": "C:/Users/[uname]/Develop/IEDriverServer.exe",
      "webdriver.gecko.driver": "C:/Users/[uname]/Develop/geckodriver.exe",
      "webdriver.firefox.profile": ""
    }
  },
  "test_runner": "mocha",
  "test_settings": {
    "default": {
      "screenshots": {
        "enabled": false,
        "path": './screenshots' // save screenshots here
      },
      "globals": {
        "waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
      },
      "desiredCapabilities": { // use Chrome as the default browser for tests
        "browserName": "ie"
      }
    },
    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true // turn off to test progressive enhancement
      }
    },
    "ie": {
      "desiredCapabilities": {
        "browserName": "internet explorer",
        "version": "11",
        "selenium_port"  : 4444,
        "selenium_host"  : "localhost",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "allowBlockedContent": true,
        "ignoreProtectedModeSettings": true
      }
    },
    "firefox": {
      "desiredCapabilities": {
        "browserName": "firefox",
        "javascriptEnabled": true // turn off to test progressive enhancement
      }
    }
  }
};
/**
 * selenium-download does exactly what it's name suggests;
 * downloads (or updates) the version of Selenium (& chromedriver)
 * on your localhost where it will be used by Nightwatch.
 /the following code checks for the existence of `selenium.jar` before trying to run our tests.
 */

require('fs').stat(BINPATH + 'selenium.jar', function (err, stat) { // got it?
  if (err || !stat || stat.size < 1) {
    require('selenium-download').ensure(BINPATH, function(error) {
      if (error) throw new Error(error); // no point continuing so exit!
      console.log('✔ Selenium & Chromedriver downloaded to:', BINPATH);
    });
  }
});

This is the error that I keep recieving from my tests:

> nightwatch --config nightwatch.conf.js

Starting selenium server... started - PID:  7624


  Asset Library left hand nav
    1) "before all" hook

  0 passing (319ms)
  1 failing

  1) Asset Library left hand nav "before all" hook:
     Connection refused! Is selenium server started?






npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.1
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `nightwatch --config nightwatch.conf.js`
npm ERR! Exit status 10
npm ERR!
npm ERR! Failed at the [email protected] start script 'nightwatch --config nightwatch.conf.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ui-centre-tests package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     nightwatch --config nightwatch.conf.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ui-centre-tests
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ui-centre-tests
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\[uname]\Develop\HSBC\UICentre\npm-debug.log

Nightwatch is set to start the selenium server its self, and visiting localhost:4444 after starting the tests does show that it has been started. Changing the browsers to Chrome and Firefox also works fine, its just IE that is the problem. I've tried using 64 and 32bit version of the IEDriverServer, and had them added to my PATH, but still nothing. Any help would be much appreciated!

EDIT: I updated my package.json so that npm start runs nightwatch --config nightwatch.conf.js --env ie,chrome,firefox. With this in place, an instance of IE does now open, but it does not actually run the tests

Upvotes: 1

Views: 1874

Answers (1)

George Bryant
George Bryant

Reputation: 51

I finally got it to work, here are the steps that I performed to get it working

  1. MANUALLY set the lowest possible security settings for each environment by going to Tools > Internet Options > Security > Custom and set the radio buttons yourself.
  2. I then set my nighwatch.conf.js file to use the flag --env ie,chrome,firefox so that the tests would run in all three of the suites I made instead of just IE by default which is how it was configured before. When running like this, I made my first step of progress in a while: IE would now actually open, but would only show "This is the initial start page for the WebDriver server" but would not do anything else
  3. After the tests failed (As IE wasnt performing the steps in the test), I then ensured that the security settings were set to be the lowest possible on this instance of the browser which was opened by the IE driver
  4. The tests would still not run, so the last step i took was to manually move the IE window which opened by default on a secondary monitor onto my primary monitor so that it would open here by default when the tests ran, and BOOM! Tests working in IE :D

Good luck to anyone else struggling this, IE is a PAIN to get working

Upvotes: 2

Related Questions