I donโt have enough points to add a comment to @jbpros answer, but it should be noted that the Scripting scripts have now completed cucumber.js, as indicated here .
For instance:
World:
// features/support/world.js var zombie = require('zombie'); var World = function World(callback) { this.browser = new zombie(); // this.browser will be available in step definitions this.visit = function(url, callback) { this.browser.visit(url, callback); }; callback(); // tell Cucumber we're finished and to use 'this' as the world instance }; exports.World = World;
Characteristic:
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 | | 200 | 65 | 135 | | 200 | 5 | 194 |
Step Definition:
var aTest = function () { this.World = require("../support/world.js").World; this.start = 0; this.eat = 0; this.Given(/^there are (\d+) cucumbers$/, function(number, next) { this.start = parseInt(number); callback(); }); this.When(/^I eat (\d+) cucumbers$/, function (number, next) { this.eat = parseInt(number); callback(); }); this.Then(/^I should have (\d+) cucumbers$/, function (number, next) { var left = this.start - this.eat; if ( left != number) callback.fail(new Error("This test didn't pass, I started with: " + this.start + ", ate: " + this.eat + " and was left with: " + left + ". Expected: " + number)); callback(); }); }; module.exports = aTest;
source share