Mocha Adapter for Nightwatch.js

3.2.2 · abandoned · verified Sun Apr 19

The `mocha-nightwatch` package serves as an adapter, enabling the use of Mocha's familiar BDD/TDD syntax, such as `describe` and `it`, within the Nightwatch.js end-to-end testing framework. This allows developers to structure their Nightwatch tests using Mocha's expressive assertion style and test organization patterns. The package is currently at version 3.2.2. However, it is important to note that this adapter has not been updated in over five years, with its last publication in October 2019. It relies on significantly older versions of its core dependencies, specifically Mocha (~3.2.0) and Nightwatch.js (~0.9.12). Consequently, its release cadence is non-existent, and it is incompatible with modern versions of Node.js, Nightwatch.js (v1.x, v2.x, v3.x+), and Mocha (v4.x+). Key differentiators, at the time of its relevance, included bridging two popular testing paradigms for browser automation, but its abandonment makes it unsuitable for current development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure Nightwatch.js to use Mocha as its test runner and write a basic end-to-end test. Ensure 'chromedriver' and 'nightwatch@~0.9.12' are installed.

// nightwatch.conf.js
const chromedriver = require('chromedriver');

module.exports = {
  src_folders: ["test"],
  output_folder: "reports",
  globals_path: "globals.js",

  test_runner: {
    type: "mocha",
    options: {
      ui: "bdd",
      reporter: "spec",
      timeout: "60000"
    }
  },

  webdriver: {
    start_process: true,
    port: 9515,
    server_path: chromedriver.path, // Requires 'chromedriver' package
    cli_args: [
      "--verbose"
    ]
  },

  test_settings: {
    default: {
      launch_url: "http://localhost",
      desiredCapabilities: {
        browserName: "chrome",
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          args: ["--headless"]
        }
      }
    }
  }
};

// test/example.spec.js

describe('Google Homepage Test', function() {
  it('should have a title', function(browser) {
    browser
      .url('https://www.google.com')
      .waitForElementVisible('body', 1000)
      .assert.titleContains('Google')
      .end();
  });

  it('should find the search input', function(browser) {
    browser
      .url('https://www.google.com')
      .waitForElementVisible('input[name="q"]', 1000)
      .assert.elementPresent('input[name="q"]')
      .end();
  });
});

view raw JSON →