Issue setting up Nightwatch
Asked 07 September, 2021
Viewed 2.4K times
  • 57
Votes

I have a Django project I am attempting to get nightwatch JS setup on, but I can't seem to get around issues with selinum drivers.

I have a node_modules directory like this (showing important areas)

node_modules
  .bin
    chromedriver
    geckodriver

In my root folder I have a test written like so, named custom_test.js:

module.exports = {
  'NW test on Google' : function (client) {
    client
      .url('http://www.google.com')
      .waitForElementVisible('body', 1000)
      .assert.title('Google')
      .assert.visible('input[type=text]')
      .setValue('input[type=text]', 'Nightwatch JS')
      .waitForElementVisible('button[name=btnG]', 1000)
      .click('button[name=btnG]')
      .pause(1000)
      .assert.containsText('ol#rso li:first-child',
        'Nightwatch.js | Node.js powered End-to-End testing framework')
      .end()
  }
}

Scripts in package.json:

"nightwatch": "./node_modules/.bin/nightwatch"

And just in case this is needed, here shows the devDependenices from chromedriver and geckdriver

"chromedriver": "^88.0.0",

"geckodriver": "^1.22.1",

And now nightwatch.json

{
  "src_folders" : [""],

  "webdriver" : {
    "start_process": true,
    "server_path": "node_modules/.bin/geckodriver",
    "port": 9515
  },

  "test_settings" : {
    "default" : {
      "desiredCapabilities": {
        "browserName": "firefox"
      }
    }
  }
}

When I run: npm run nightwatch custom_test.js I simplt get:


An error occurred while retrieving a new session: "Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line"

If I change the nightwatch.json file to point to the chromedriver I get this error:

{
  "src_folders" : [""],

  "webdriver" : {
    "start_process": true,
    "server_path": "node_modules/.bin/chromedriver",
    "port": 9515
  },

  "test_settings" : {
    "default" : {
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    }
  }
}

An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"

This is not making sense to me as the configuration is only telling me to run the installations of the drivers through npm install:

https://nightwatchjs.org/gettingstarted/configuration/

What am I doing wrong?

UPDATE

Changin the config to nightwatch.conf.js:

module.exports = {
    // An array of folders (excluding subfolders) where your tests are located;
    // if this is not specified, the test source must be passed as the second argument to the test runner.
    src_folders: ["tests"],

    webdriver: {
        start_process: true,
        port: 4444,
        server_path: require('chromedriver').path,
        cli_args: [
        ]
    },
    test_settings: {
        default: {
            desiredCapabilities: {
                browserName: 'chrome',
            }
        }
    }
}

Provides this error:


An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"

Here is the whole output:

npm run nightwatch custom_test.js

> [email protected] nightwatch /opt/project
> nightwatch "custom_test.js"


[Custom Test] Test Suite
========================
⚠ Error connecting to localhost on port 4444.
_________________________________________________

TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (221ms)

 ✖ custom_test
   An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"
Error: An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"
    at endReadableNT (_stream_readable.js:1187:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

  Error: An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"
       at endReadableNT (_stream_readable.js:1187:12)
       at processTicksAndRejections (internal/process/task_queues.js:84:21)

   SKIPPED:
   - NW test on Google

npm ERR! code ELIFECYCLE
npm ERR! errno 5
npm ERR! [email protected] nightwatch: `nightwatch "custom_test.js"`
npm ERR! Exit status 5
npm ERR! 
npm ERR! Failed at the [email protected] nightwatch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-02-09T17_02_25_145Z-debug.log

UPDATE WITH NPX

Starting: nightwatch custom_test.js
internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module '/opt/project/nightwatch'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}


UPDATE 3: WHOLE PACKAGE.JSON

{
  "name": "exactestate",
  "version": "1.0.0",
  "description": "Modern, Secure, and Customizable Real Estate Management Software in the Cloud.",
  "scripts": {
    "build": "webpack --mode=production",
    "build:dev": "webpack --mode=development",
    "serve": "webpack-dev-server",
    "test": "jest --colors --coverage --verbose ",
    "nightwatch": "./node_modules/.bin/nightwatch"
  },
  "browserslist": [
    "last 2 version",
    "> 1%"
  ],
  "dependencies": {
    "@fortawesome/fontawesome-pro": "^5.13.0",
    "axios": "^0.21.1",
    "bootstrap": "^4.4.1",
    "chart.js": "^2.9.4",
    "chartjs-plugin-datalabels": "^0.7.0",
    "cleave": "^1.0.0-alpha.10",
    "crypto-js": "^4.0.0",
    "datatables.net": "^1.10.20",
    "gsap": "^3.2.6",
    "intro.js": "^2.9.3",
    "jquery": "^3.5.0",
    "jspdf": "^1.5.3",
    "jspdf-autotable": "^3.4.3",
    "lodash": "^4.17.15",
    "lodash-webpack-plugin": "^0.11.6",
    "mobile-device-detect": "^0.3.3",
    "moment": "^2.24.0",
    "mousetrap": "^1.6.5",
    "node": "^12.16.2",
    "popper.js": "^1.16.1",
    "qs": "^6.9.3",
    "secure-web-storage": "^1.0.2",
    "tiptap": "^1.27.0",
    "tiptap-extensions": "^1.29.0",
    "uglifyjs-webpack-plugin": "^2.2.0",
    "v-mask": "^2.1.0",
    "validator": "^12.2.0",
    "vue": "^2.6.11",
    "vue-async-computed": "^3.8.2",
    "vue-chartjs": "^3.5.1",
    "vue-inputmask": "^0.2.1",
    "vue2-perfect-scrollbar": "^1.5.0",
    "vuedraggable": "^2.23.2",
    "ws": "^7.3.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.11.6",
    "@babel/plugin-transform-runtime": "^7.11.5",
    "@babel/preset-env": "^7.11.5",
    "@tweenjs/tween.js": "^18.5.0",
    "@vue/test-utils": "^1.1.0",
    "autoprefixer": "^9.7.6",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^26.5.2",
    "babel-loader": "^8.1.0",
    "babel-preset-es2015": "^6.24.1",
    "chai": "^4.3.0",
    "chromedriver": "^88.0.0",
    "clean-webpack-plugin": "^3.0.0",
    "co": "^4.6.0",
    "co-mocha": "^1.2.2",
    "compression-webpack-plugin": "^3.1.0",
    "copy-webpack-plugin": "^5.1.1",
    "core-js": "^3.6.5",
    "css-loader": "^3.5.2",
    "electron": "^11.2.3",
    "fibers": "^4.0.2",
    "file-loader": "^4.3.0",
    "geckodriver": "^1.22.1",
    "glob": "^7.1.6",
    "gzip-loader": "0.0.1",
    "imagemin-mozjpeg": "^8.0.0",
    "imagemin-webpack-plugin": "^2.4.2",
    "jest": "^26.5.3",
    "jspdf": "^1.5.3",
    "mini-css-extract-plugin": "^0.8.2",
    "mocha": "^8.2.1",
    "mocha-generators": "^2.0.0",
    "nightmare": "^3.0.2",
    "nightwatch": "^1.5.1",
    "node-sass": "^4.14.1",
    "postcss-import": "^12.0.1",
    "postcss-loader": "^3.0.0",
    "regenerator-runtime": "^0.13.5",
    "sass": "^1.26.3",
    "sass-loader": "^8.0.2",
    "speed-measure-webpack-plugin": "^1.3.3",
    "style-loader": "^1.1.4",
    "url-loader": "^2.2.0",
    "vue-jest": "^3.0.7",
    "vue-loader": "^15.9.1",
    "vue-style-loader": "^4.1.2",
    "vue-template-compiler": "^2.6.11",
    "webpack": "^4.42.1",
    "webpack-bundle-analyzer": "^3.7.0",
    "webpack-bundle-tracker": "^0.4.3",
    "webpack-cli": "^3.3.11",
    "webpack-dev-server": "^3.11.0"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ViaTechSystems/ExactEstate.git"
  },
  "bugs": {
    "url": "https://github.com/ViaTechSystems/ExactEstate/issues"
  },
  "homepage": "https://github.com/ViaTechSystems/ExactEstate#readme"
}

1 Answer