0.6.1 • Published 8 years ago

nadda v0.6.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

nadda Build Status Coverage Status

A zero config plugin for BDD acceptance testing in the browser using a combination of yadda, nightwatch, selenium, chromedriver, phantomjs and iedriver (if applicable).

Install

$ npm install nadda

Command Line

nadda includes a command-line test runner to easily run a suite e.g.

nadda -f 'tests/**/*.feature' -s 'tests/**/*.steps.js'

Things to note:

  • If using globbing in paths you may need to surround in quotes to stop the OS from resolving these prior to passing to nadda.
  • Globbed file paths don't support the use of ~.

The test runner supports a number of run-time options. To view all, run the following:

$ nadda --help
NameShortnameDefaultDescription
featuresf['**/*.feature', '!node_modules/**/*']globs to select feature files.
stepss['**/*.steps.js', '!node_modules/**/*']globs to select steps files.
configcfile path to local nightwatch.json if you want to override/add to nightwatch config.
localisationlselects the Yadda localisation library to pass to step files.
envePHANTOMJSselects the browser environment to use.
tagsttags to determine which scenarios to run.--tags ~@wip will run scenarios that do not have the @wip tag.--tags @wip will run scenarios that have the @wip tag.--tags ~@wip,@feature will run scenarios that do not have the @wip tag AND have the @feature tag. --tags ~@wip --tags @feature will run scenarios that do not have the @wip tag OR have the @feature tag.

API

nadda can be required into a project exposing a function which takes the same options as the command line tool and returns a promise. A list of possible yadda localisations and environments can be found under nadda.LOCALISATIONS and nadda.BROWSERS respectively.

var nadda = require('nadda');
nadda({
  features: 'tests/**/*.js',
  steps: 'tests/**/*.steps.js',
  config: 'path/to/nightwatch.json',
  localisation: nadda.LOCALISATIONS.ENGLISH,
  env: nadda.BROWSERS.CHROME,
  tags: [['~@wip', '@feature'], ['@done']]
}).finally(function () {
  //do something
});

Writing Yadda Steps

Step files should be written as CommonJS modules exporting a single function that will, at runtime, be passed a yadda library (the type of which can be defined using the 'localisation' option) on which to register steps e.g.

module.exports = function (lib) {
    lib.when(/I type in (\w*)/, function (searchTerm) {
        this.browser.setValue('input#search_form_input_homepage', searchTerm);
    })
    .when('I click search', function () {
        this.browser.waitForElementVisible('input#search_button_homepage', 1000)
            .click('input#search_button_homepage')
            .pause(1000);
    });
};

Each step itself has access to the nightwatch browser object (this.browser) and a context object (this.ctx). The context object can be used to pass data between steps and is initially populated with the amalgamated annotations (this.ctx.annotations) of the feature and scenario currently being run (if a feature and scenario annotation of the same name exist the scenario annotation will win out).