node-gherkin-runner
Node module that transforme feature files into full javascript (using https://github.com/gregorylimoratto/gherkin-specs-api.git and run then using mocha, jasmine-node or protractor
Any feedback is appreciated !
Usage
Install
node-gherkin-runner is available as an npm module
Install locally with
npm install node-gherkin-runner --save-dev
Features
The examples are written with Gherkin language : https://github.com/cucumber/cucumber/wiki/Gherkin
Feature: Calculator addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
@ignore
Scenario: Add two other numbers
Given I have entered 10 into the calculator
And I have entered 79 into the calculator
When I press add
Then the result should be 89 on the screen
And failed the test
Each Gherkin Feature will become a jasmine/mocha/protractor describe
And each Scenario will become a it
Some tags will allow you to ignore feature execution : jasmine/mocha/protractor xdescribe() / xit()
- @ignore - ignore Feature or Scenario
- @ignoreOthers - ignore all other feature / scenario exept those with this tag
Javascript Specs
The module will look for feature files (gherkin) in process.cwd()
and all subdirectories.
The featureSteps() function host a set of steps that will be available for each feature that match the featureSteps regexp
var gherkin = ; gherkinapi ; gherkinapi ;
given/when/then step can be string or regular expression that match a step in the feature file.
var gherkin = ; gherkinapi ;
Each step is executed on an isolated scope (this) which can hold current scenario state. (reset for each scenario)
You can add test initialize and cleanup :
var gherkin = ; gherkinapi ...
To install :
npm install node-gherkin-runner --save-dev
And just include the module as a file to test in your test runner
Example gruntfile using mocha (and grunt-mocha-test) :
mochaTest: {
test: {
options: {
reporter: 'spec'
},
src: ['tests/**/*.js', 'node_module/node-gherkin-runner/lib/gherkin-runner.js']
}
}
Examples
Using protractor :
demo.feature:
Feature: angularjs homepage
Background:
Given I browse angular website
Scenario: Must greet the user
Given I insert 'Greg' in the "yourName" field
When I look at the greeting message
Then I see 'Hello Greg!'
Scenario: Must display a pre-set todo list
Given The todo list is displayed by default with 2 elements
When I look at the todo elements
Then There is 2 elements in todo list
And The text for the number 2 is 'build an angular app'
Scenario: Must add a todo when Add button is click
Given The todo list is displayed by default with 2 elements
When I insert 'write a protractor test using gherkin' in the input field
And I click on Add button
And I look at the todo elements
Then There is 3 elements in todo list
And The text for the number 3 is 'write a protractor test using gherkin'
demo.feature-specs.js
var gherkin = ; { 'use strict'; gherkinapi };
e2e.config (protractor) :
var gherkinRunnerPath = runnerPath;gherkinRunnerPath = gherkinRunnerPath;console;exportsconfig = framework: 'jasmine2' seleniumAddress: 'http://localhost:4444/wd/hub' specs: 'spec/demo.feature-specs.js' gherkinRunnerPath