Skip to content

Commit

Permalink
Revert "Revert "feat(runner): add adapter for cucumber.js""
Browse files Browse the repository at this point in the history
This reverts commit 21e52a9.
  • Loading branch information
juliemr committed Feb 5, 2014
1 parent fb902ce commit 6bc5e29
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 3 deletions.
47 changes: 46 additions & 1 deletion lib/runner.js
Expand Up @@ -262,6 +262,12 @@ var runTests = function() {
if (!resolvedSpecs.length) {
throw new Error('Spec patterns did not match any files.');
}
if (config.cucumberOpts && config.cucumberOpts.require) {
var cucumberRequire = config.cucumberOpts.require;
cucumberRequire = typeof cucumberRequire === 'string' ?
[cucumberRequire] : cucumberRequire;
var cucumberResolvedRequire = resolveFilePatterns(cucumberRequire);
}

// TODO: This should not be tied to the webdriver promise loop, it should use
// another promise system instead.
Expand Down Expand Up @@ -300,7 +306,7 @@ var runTests = function() {

// Do the framework setup here so that jasmine and mocha globals are
// available to the onPrepare function.
var minijn, mocha;
var minijn, mocha, cucumber;
if (config.framework === 'jasmine') {
minijn = require('minijasminenode');
require('../jasminewd');
Expand Down Expand Up @@ -329,6 +335,29 @@ var runTests = function() {
});

mocha.loadFiles();
} else if (config.framework === 'cucumber') {
var Cucumber = require('cucumber');
var execOptions = ['node', 'node_modules/.bin/cucumber-js'];
execOptions = execOptions.concat(resolvedSpecs);

if (config.cucumberOpts) {
if (cucumberResolvedRequire && cucumberResolvedRequire.length) {
execOptions.push('-r');
execOptions = execOptions.concat(cucumberResolvedRequire);
}

if (config.cucumberOpts.tags) {
execOptions.push('-t');
execOptions.push(config.cucumberOpts.tags);
}

if (config.cucumberOpts.format) {
execOptions.push('-f');
execOptions.push(config.cucumberOpts.format);
}
}

cucumber = Cucumber.Cli(execOptions);
} else {
throw 'config.framework ' + config.framework +
' is not a valid framework.';
Expand Down Expand Up @@ -376,6 +405,22 @@ var runTests = function() {
});
});
});
} else if (config.framework === 'cucumber') {
cucumber.run(function(succeeded) {
// Warning: hack to make it have the same signature as Jasmine 1.3.1.
if (originalOnComplete) {
originalOnComplete();
}
driver.quit().then(function() {
runDeferred.fulfill({
results: function() {
return {
failedCount: succeeded ? 0 : 1
};
}
});
});
});
}
});
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -25,6 +25,7 @@
"chai-as-promised": "~4.1.0",
"jasmine-reporters": "~0.2.1",
"mocha": "~1.16.0",
"cucumber": "~0.3.3",
"express": "~3.3.4",
"mustache": "~0.7.2"
},
Expand All @@ -38,7 +39,7 @@
},
"main": "lib/protractor.js",
"scripts": {
"test": "node lib/cli.js spec/basicConf.js; node lib/cli.js spec/altRootConf.js; node lib/cli.js spec/onPrepareConf.js; node lib/cli.js spec/mochaConf.js; node lib/cli.js spec/withLoginConf.js; node_modules/.bin/minijasminenode jasminewd/spec/adapterSpec.js"
"test": "node lib/cli.js spec/basicConf.js; node lib/cli.js spec/altRootConf.js; node lib/cli.js spec/onPrepareConf.js; node lib/cli.js spec/mochaConf.js; node lib/cli.js spec/cucumberConf.js; node lib/cli.js spec/withLoginConf.js; node_modules/.bin/minijasminenode jasminewd/spec/adapterSpec.js"
},
"license" : "MIT",
"version": "0.18.1",
Expand Down
12 changes: 11 additions & 1 deletion referenceConf.js
Expand Up @@ -104,7 +104,7 @@ exports.config = {

// ----- The test framework -----
//
// Jasmine is fully supported as a test and assertion framework.
// Jasmine and Cucumber are fully supported as a test and assertion framework.
// Mocha has limited beta support. You will need to include your own
// assertion framework if working with mocha.
framework: 'jasmine',
Expand Down Expand Up @@ -133,6 +133,16 @@ exports.config = {
reporter: 'list'
},

// ----- Options to be passed to cucumber -----
cucumberOpts: {
// Require files before executing the features.
require: 'cucumber/stepDefinitions.js',
// Only execute the features or scenarios with tags matching @dev.
tags: '@dev',
// How to format features (default: progress)
format: 'summary'
},

// ----- The cleanup step -----
//
// A callback function called once the tests have finished running and
Expand Down
15 changes: 15 additions & 0 deletions spec/cucumber/lib.feature
@@ -0,0 +1,15 @@
Feature: Running Cucumber with Protractor
As a user of Protractor
I should be able to use Cucumber
to run my E2E tests

@dev
Scenario: Running Cucumber with Protractor
Given I run Cucumber with Protractor
Then it should still do normal tests
Then it should expose the correct global variables

@dev
Scenario: Wrapping WebDriver
Given I go on "index.html"
Then the title should equal "My AngularJS App"
38 changes: 38 additions & 0 deletions spec/cucumber/stepDefinitions.js
@@ -0,0 +1,38 @@
// Use the external Chai As Promised to deal with resolving promises in
// expectations.
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

var expect = chai.expect;

module.exports = function() {

this.Given(/^I run Cucumber with Protractor$/, function(next) {
next();
});

this.Given(/^I go on(?: the website)? "([^"]*)"$/, function(url, next) {
browser.get(url);
next();
});

this.Then(/^it should still do normal tests$/, function(next) {
expect(true).to.equal(true);
next();
});

this.Then(/^it should expose the correct global variables$/, function(next) {
expect(protractor).to.exist;
expect(browser).to.exist;
expect(by).to.exist;
expect(element).to.exist;
expect($).to.exist;
next();
});

this.Then(/the title should equal "([^"]*)"$/, function(text, next) {
expect(browser.getTitle()).to.eventually.equal(text).and.notify(next);
});

};
30 changes: 30 additions & 0 deletions spec/cucumberConf.js
@@ -0,0 +1,30 @@
// A small suite to make sure the cucumber framework works.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',

framework: 'cucumber',

// Spec patterns are relative to this directory.
specs: [
'cucumber/*.feature'
],

capabilities: {
'browserName': 'chrome'
},

baseUrl: 'http://localhost:8000',

params: {
login: {
user: 'Jane',
password: '1234'
}
},

cucumberOpts: {
require: 'cucumber/stepDefinitions.js',
tags: '@dev',
format: 'summary'
}
};

0 comments on commit 6bc5e29

Please sign in to comment.