Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 88c339f

Browse files
yannickcrjuliemr
authored andcommitted
feat(runner): add adapter for cucumber.js
Conflicts: lib/runner.js
1 parent 90ba174 commit 88c339f

File tree

6 files changed

+142
-3
lines changed

6 files changed

+142
-3
lines changed

lib/runner.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ var runTests = function() {
262262
if (!resolvedSpecs.length) {
263263
throw new Error('Spec patterns did not match any files.');
264264
}
265+
if (config.cucumberOpts && config.cucumberOpts.require) {
266+
var cucumberRequire = config.cucumberOpts.require;
267+
cucumberRequire = typeof cucumberRequire === 'string' ?
268+
[cucumberRequire] : cucumberRequire;
269+
var cucumberResolvedRequire = resolveFilePatterns(cucumberRequire);
270+
}
265271

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

301307
// Do the framework setup here so that jasmine and mocha globals are
302308
// available to the onPrepare function.
303-
var minijn, mocha;
309+
var minijn, mocha, cucumber;
304310
if (config.framework === 'jasmine') {
305311
minijn = require('minijasminenode');
306312
require('../jasminewd');
@@ -329,6 +335,29 @@ var runTests = function() {
329335
});
330336

331337
mocha.loadFiles();
338+
} else if (config.framework === 'cucumber') {
339+
var Cucumber = require('cucumber');
340+
var execOptions = ['node', 'node_modules/.bin/cucumber-js'];
341+
execOptions = execOptions.concat(resolvedSpecs);
342+
343+
if (config.cucumberOpts) {
344+
if (cucumberResolvedRequire && cucumberResolvedRequire.length) {
345+
execOptions.push('-r');
346+
execOptions = execOptions.concat(cucumberResolvedRequire);
347+
}
348+
349+
if (config.cucumberOpts.tags) {
350+
execOptions.push('-t');
351+
execOptions.push(config.cucumberOpts.tags);
352+
}
353+
354+
if (config.cucumberOpts.format) {
355+
execOptions.push('-f');
356+
execOptions.push(config.cucumberOpts.format);
357+
}
358+
}
359+
360+
cucumber = Cucumber.Cli(execOptions);
332361
} else {
333362
throw 'config.framework ' + config.framework +
334363
' is not a valid framework.';
@@ -376,6 +405,22 @@ var runTests = function() {
376405
});
377406
});
378407
});
408+
} else if (config.framework === 'cucumber') {
409+
cucumber.run(function(succeeded) {
410+
// Warning: hack to make it have the same signature as Jasmine 1.3.1.
411+
if (originalOnComplete) {
412+
originalOnComplete();
413+
}
414+
driver.quit().then(function() {
415+
runDeferred.fulfill({
416+
results: function() {
417+
return {
418+
failedCount: succeeded ? 0 : 1
419+
};
420+
}
421+
});
422+
});
423+
});
379424
}
380425
});
381426
});

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"chai-as-promised": "~4.1.0",
2626
"jasmine-reporters": "~0.2.1",
2727
"mocha": "~1.16.0",
28+
"cucumber": "~0.3.3",
2829
"express": "~3.3.4",
2930
"mustache": "~0.7.2"
3031
},
@@ -38,7 +39,7 @@
3839
},
3940
"main": "lib/protractor.js",
4041
"scripts": {
41-
"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"
42+
"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"
4243
},
4344
"license" : "MIT",
4445
"version": "0.18.0",

referenceConf.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ exports.config = {
104104

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

136+
// ----- Options to be passed to cucumber -----
137+
cucumberOpts: {
138+
// Require files before executing the features.
139+
require: 'cucumber/stepDefinitions.js',
140+
// Only execute the features or scenarios with tags matching @dev.
141+
tags: '@dev',
142+
// How to format features (default: progress)
143+
format: 'summary'
144+
},
145+
136146
// ----- The cleanup step -----
137147
//
138148
// A callback function called once the tests have finished running and

spec/cucumber/lib.feature

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Running Cucumber with Protractor
2+
As a user of Protractor
3+
I should be able to use Cucumber
4+
to run my E2E tests
5+
6+
@dev
7+
Scenario: Running Cucumber with Protractor
8+
Given I run Cucumber with Protractor
9+
Then it should still do normal tests
10+
Then it should expose the correct global variables
11+
12+
@dev
13+
Scenario: Wrapping WebDriver
14+
Given I go on "index.html"
15+
Then the title should equal "My AngularJS App"

spec/cucumber/stepDefinitions.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Use the external Chai As Promised to deal with resolving promises in
2+
// expectations.
3+
var chai = require('chai');
4+
var chaiAsPromised = require('chai-as-promised');
5+
chai.use(chaiAsPromised);
6+
7+
var expect = chai.expect;
8+
9+
module.exports = function() {
10+
11+
this.Given(/^I run Cucumber with Protractor$/, function(next) {
12+
next();
13+
});
14+
15+
this.Given(/^I go on(?: the website)? "([^"]*)"$/, function(url, next) {
16+
browser.get(url);
17+
next();
18+
});
19+
20+
this.Then(/^it should still do normal tests$/, function(next) {
21+
expect(true).to.equal(true);
22+
next();
23+
});
24+
25+
this.Then(/^it should expose the correct global variables$/, function(next) {
26+
expect(protractor).to.exist;
27+
expect(browser).to.exist;
28+
expect(by).to.exist;
29+
expect(element).to.exist;
30+
expect($).to.exist;
31+
next();
32+
});
33+
34+
this.Then(/the title should equal "([^"]*)"$/, function(text, next) {
35+
expect(browser.getTitle()).to.eventually.equal(text).and.notify(next);
36+
});
37+
38+
};

spec/cucumberConf.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// A small suite to make sure the cucumber framework works.
2+
exports.config = {
3+
seleniumAddress: 'http://localhost:4444/wd/hub',
4+
5+
framework: 'cucumber',
6+
7+
// Spec patterns are relative to this directory.
8+
specs: [
9+
'cucumber/*.feature'
10+
],
11+
12+
capabilities: {
13+
'browserName': 'chrome'
14+
},
15+
16+
baseUrl: 'http://localhost:8000',
17+
18+
params: {
19+
login: {
20+
user: 'Jane',
21+
password: '1234'
22+
}
23+
},
24+
25+
cucumberOpts: {
26+
require: 'cucumber/stepDefinitions.js',
27+
tags: '@dev',
28+
format: 'summary'
29+
}
30+
};

0 commit comments

Comments
 (0)