Run your Nightwatch.js tests with Grunt

Grunt meets Nightwatch.js

Automatize your tests:

module.exports = function(grunt) {
    nightwatch: {
      options: { /* see below */ }

Write some tests:


module.exports = {
  'Demo test Google'function(browser) {
      .waitForElementVisible('body', 1000)
      .setValue('input[type=text]', 'nodejs')
      .waitForElementVisible('button[name=btnG]', 1000)
      .assert.containsText('#ires', 'joyent/node')


$ grunt nightwatch      # target: default
$ grunt nightwatch:A    # target: A
$ grunt nightwatch:A:B  # targets: A, B

Currently, grunt-nightwatch supports the same options as nwrun can handle.

Note that the nighwatch.json file settings is fully supported, but your task options will override them if needed.

module.exports = function(grunt) {
    nightwatch: {
      options: {
        // task options 
        standalone: true,
        // download settings 
        jar_version: '2.44.0',
        jar_path: '/opt/selenium/server.jar',
        jar_url: '',
        // nightwatch settings 
        globals: { foo: 'bar' },
        globals_path: 'custom_tests/globals',
        custom_commands_path: 'custom_tests/helpers',
        custom_assertions_path: 'custom_tests/asserts',
        src_folders: ['custom_tests/nightwatch'],
        output_folder: 'report',
        test_settings: {},
        selenium: {}
      custom: {
        // custom target + overrides 
        config_path: '/path/to/file.json',
        src_folders: ['other_tests/nightwatch']

Since 0.5.0, grunt-nightwatch will pass grunt.cli.options as the argv option to nwrun.

This means you can use grunt nightwatch:A:B --group foo --tag bar directly on the CLI.

When running in parallel Nightwatch will copy the process.argv and it may produce bugs if you expect a single boolean argument like grunt nightwatch:A:B --standalone.

It will spawn grunt nightwatch --standalone --env A and the argv will be erroneously parsed as --standalone=--env.

All options are the same as the main settings.

nightwatch: {
  demo: { /* see above */ }

Now you can execute grunt nightwatch:demo to run your tests.

Note that your tests must be grouped together as follows: tests/<group>/test.js