Skip to content

Commit

Permalink
feat(cucumber): better support cucumber
Browse files Browse the repository at this point in the history
 add support coffee(flag)
 update version (-> 0.4.0)
 add example test for scenarion outline

Closes angular#702
  • Loading branch information
a.konovalov committed Apr 18, 2014
1 parent 7334e6c commit 4ffa9ba
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ Runner.prototype.runCucumber_ = function(specs, done) {
execOptions.push('-f');
execOptions.push(self.config_.cucumberOpts.format);
}

if (self.config_.cucumberOpts.coffee) {
execOptions.push('--coffee');
}
}
cucumber = Cucumber.Cli(execOptions);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"chai-as-promised": "~4.1.0",
"jasmine-reporters": "~0.2.1",
"mocha": "~1.16.0",
"cucumber": "~0.3.3",
"cucumber": "~0.4.0",
"express": "~3.3.4",
"lodash": "~2.4.1",
"rimraf": "~2.2.6",
Expand Down
1 change: 1 addition & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var scripts = [
'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/cucumberConfWithCoffee.js',
'node lib/cli.js spec/withLoginConf.js',
'node lib/cli.js spec/suitesConf.js --suite okmany',
'node lib/cli.js spec/suitesConf.js --suite okspec'
Expand Down
14 changes: 12 additions & 2 deletions spec/cucumber/lib.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ Feature: Running Cucumber with 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 Outline: Running Cucumber Scenario Outline with Protractor
Given I run Cucumber with Protractor
Then it should expose the correct global variable "<variable>"

Examples:
| variable |
|protractor|
| browser |
| by |
| element |
| $ |

Scenario: Wrapping WebDriver
Given I go on "index.html"
Then the title should equal "My AngularJS App"
45 changes: 45 additions & 0 deletions spec/cucumber/stepDefinitions.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Use the external Chai As Promised to deal with resolving promises in

This comment has been minimized.

Copy link
@juliemr

juliemr Apr 21, 2014

I don't think that we need a separate set of tests for cucumber in coffee. This should be tested by Cucumber. Let's trust that cucumber does the right then when it's the passed the --coffee flag and remove this and the related config file.

This comment has been minimized.

Copy link
@inotnako

inotnako Apr 22, 2014

Owner

ok

# expectations.
chai = require 'chai'
chaiAsPromised = require 'chai-as-promised'
chai.use(chaiAsPromised)

expect = chai.expect

g =
protractor:protractor
browser:browser
by:`by`
element:element
'$':$

module.exports = ->

@Given /^I run Cucumber with Protractor$/, (next) ->
next()

@Given /^I go on(?: the website)? "([^"]*)"$/, (url, next) ->
browser.get(url)
next()

@Then /^it should still do normal tests$/, (next) ->
expect(true).to.equal(true)
next()

@Then /^it should expose the correct global variables$/, (next) ->
expect(protractor).to.exist
expect(browser).to.exist
expect(`by`).to.exist
expect(element).to.exist
expect($).to.exist
next()


@Then /^it should expose the correct global variable "([^"]*)"$/, (variable,next) ->
expect(g[variable]).to.exist
next()


@Then /the title should equal "([^"]*)"$/, (text, next) ->
expect(browser.getTitle()).to.eventually.equal(text).and.notify(next)

14 changes: 14 additions & 0 deletions spec/cucumber/stepDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ chai.use(chaiAsPromised);

var expect = chai.expect;

var g = {
protractor:protractor,
browser:browser,
by:by,
element:element,
'$':$
};

module.exports = function() {

this.Given(/^I run Cucumber with Protractor$/, function(next) {
Expand All @@ -31,6 +39,12 @@ module.exports = function() {
next();
});

this.Then(/^it should expose the correct global variable "([^"]*)"$/, function(variable,next) {
expect(g[variable]).to.exist;
next();
});


this.Then(/the title should equal "([^"]*)"$/, function(text, next) {
expect(browser.getTitle()).to.eventually.equal(text).and.notify(next);
});
Expand Down
1 change: 0 additions & 1 deletion spec/cucumberConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ exports.config = {

cucumberOpts: {
require: 'cucumber/stepDefinitions.js',
tags: '@dev',
format: 'summary'
}
};
30 changes: 30 additions & 0 deletions spec/cucumberConfWithCoffee.js
Original file line number Diff line number Diff line change
@@ -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:' + (process.env.HTTP_PORT || '8000'),

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

cucumberOpts: {
require: 'cucumber/stepDefinitions.coffee',
format: 'summary',
coffee: true
}
};

0 comments on commit 4ffa9ba

Please sign in to comment.