JSPM

  • Created
  • Published
  • Downloads 1516
  • Score
    100M100P100Q114637F
  • License MIT

Nightwatch.js plugin for Cucumber.js

Package Exports

  • nightwatch-cucumber

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nightwatch-cucumber) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

nightwatch-cucumber nightwatch-cucumber

npm version Build Status Coverage Status semantic-release js-standard-style Commitizen friendly dependencies Status devDependencies Status Ask question

NPM

This module enables to use a BDD-style approach for cross-browser testing:

Installation

Step 1

First you need to have Nightwatch.js and Cucumber.js to be installed locally.

$ npm install --save-dev nightwatch cucumber

If you are new to Nightwatch.js you can read the developer guide.

Step 2

Install nightwatch-cucumber

$ npm install --save-dev nightwatch-cucumber

Step 3

In project root create a JavaScript configuration file for Nightwatch.js. Use nightwatch.conf.js instead of nightwatch.json. More details You don't need to specify src_folders.

// nightwatch.conf.js

module.exports = {
  ...
}

Step 4

Require nightwatch-cucumber at the top of the configuration file.

// nightwatch.conf.js

require('nightwatch-cucumber')({
  /* configuration */
})

module.exports = {
  ...
}

For more examples check out the examples folder

Demo Test

By default feature files are located in features folder. You can change this using configuration object.

# features/google.feature

Feature: Google Search

Scenario: Searching Google

  Given I open Google's search page
  Then the title is "Google"
  And the Google search form exists

Step definitions files are located in features/step_definitions folder by default.

All step definitions will run with this set to Nightwatch.js client or browser object

// features/step_definitions/google.js

module.exports = function() {

  this.Given(/^I open Google's search page$/, function() {
    this
      .url('http://google.com')
      .waitForElementVisible('body', 1000)
  })

  this.Then(/^the title is "([^"]*)"$/, function(title) {
    this.assert.title(title)
  })

  this.Then(/^the Google search form exists$/, function() {
    this.assert.visible('input[name="q"]')
  })

}

For more examples check out the examples folder

Running tests

If you have installed nightwatch with -g (global) option you can run the tests by executing

nightwatch

In other case you can run the tests by executing

node_modules/.bin/nightwatch

alt-tag

Features

HTML reports

HTML report generation is enabled by default. It's default location is reports/cucumber.html. You can disable or change this using configuration object.

alt-tag

Using the openReport option it is possible to make the report automatically open once test run finished.

Feature background

You can use feature background to avoid copying and pasting of steps. The background runs before each scenario after beforeScenario hooks.

Feature: Feature background example

Background:
  Given there are 10 cucumbers

Scenario: eating

  When I eat 3 cucumbers
  Then I should have 7 cucumbers

Scenario: adding

  When I add 1 cucumbers
  Then I should have 11 cucumbers

Scenario Outlines

You can use scenario outlines to avoid copying and pasting of scenarios.

Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples:
  | start | eat | left |
  |  12   |  5  |  7   |
  |  20   |  5  |  15  |

Page Objects

For making you tests more readable and maintainable you can use the Page Object pattern. Nightwatch reads the page objects from the folder (or folders) specified in the page_objects_path configuration property. More details. Add the following line to Nightwatch.js configuration file.

// nightwatch.conf.js

var nightwatchCucumber = require('nightwatch-cucumber')({
  /* configuration */
})

module.exports = {
  src_folders: [nightwatchCucumber],
  page_objects_path: 'page-objects',
  ...
}
//page-objects/yahoo.js

module.exports = {
  url: 'http://yahoo.com',
  elements: {
    body: 'body',
    searchBar: 'input[name="p"]'
  }
}

Now we can use page objects from step definitions

//step-definitions/yahoo.js

module.exports = function() {

  this.Given(/^I open Yahoo's search page$/, function() {
    var yahoo = this.page.yahoo()

    yahoo
      .navigate()
      .waitForElementVisible('@body', 1000)
  })

  this.Then(/^the Yahoo search form exists$/, function() {
    var yahoo = this.page.yahoo()

    yahoo.assert.visible('@searchBar')
  })

}

Feature Groups

You can selectively run features based on groups. To group features together just place them in the same sub-folder. The folder name is the name of the group. You can use Nightwatch CLI --group, --skipgroup flags. More details

Feature Tags

You can selectively run features based on tags. More details

# google.feature

@google @search
Feature: Google Search

Scenario: Searching Google

  Given I open Google's search page
  Then the title is "Google"
  And the Google search form exists
$ node nightwatch.js --tag google

You can also skip features based on tags

node nightwatch.js --skiptags google

Hooks

Hooks can be provided using Cucumber.js support files. Support files are specified using supportFiles configuration option. More details

// nightwatch.conf.js

require('nightwatch-cucumber')({
  supportFiles: ['hooks.js']
})

module.exports = {
  ...
}
// hooks.js

module.exports = function () {
  this.registerHandler('AfterFeatures', function (features, callback) {
    ...
    callback();
  });
}

Configuration

The default configuration object is.

{
  featureFiles: ['features'],
  stepDefinitions: ['features/step_definitions'],
  supportFiles: [],
  jsonReport: 'reports/cucumber.json',
  htmlReport: 'reports/cucumber.html',
  openReport: false,
  stepTimeout: 30000
}

Default configuration could be overwritten in the following way.

// nightwatch.conf.js

require('nightwatch-cucumber')({
  stepDefinitions: ['step_definitions']
})

module.exports = {
  ...
}

Timeouts

You can use stepTimeout option to set timeout for steps. By default, timeout is 30 seconds.

Contribute

Anyone and everyone is welcome to contribute.

Authors

Igor Muchychka (@mucsi96)

Thanks for assistance and contributions:

Igor Zalutski (@ZIJ), Daniele Campogiani (@dcampogiani), Simranjeet Singh (@RSsimranjeetsingh), Shashi Shekhar Singh (@singhshashi), Alex Murphy, Ben Grabham, Jean-Baptiste Blanchet (@jbblanchet), Vincent Spiewak (@vspiewak), Fabio Quinzi (@FabioQ), Alfredo Moretta (@Alfredo81), Jeffrey Effendy (@jeffrey-effendy) Lawrence (@ldabiralai) Domenico Gemoli (@aberonni) Klokov Anton (@klokovas)

Change log

See releases

License

This software is released under the terms of the MIT license.

Other projects