Skip to content

Commit

Permalink
additional cucumber args
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Mucsicska committed Dec 5, 2016
1 parent baf0c36 commit d33eec6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
20 changes: 19 additions & 1 deletion README.md
Expand Up @@ -146,6 +146,23 @@ nightwatch

## Features

### Passing additional CLI options for Cucumber.js.

For that you can use the `cucumberArgs` configuration property. For available Cucumber.js CLI options see the [Cucumber.js docs](https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md)

```
// nightwatch.conf.js
require('nightwatch-cucumber')({
nightwatchClientAsParameter: true,
cucumberArgs: '--format progress --format-options {"colorsEnabled":false}'
})
module.exports = {
...
}
```

### Step definition handling
In step definitions the Nightwatch api will be available as `this`. Step definitons which uses Nightwatch api should be synchronous! Please avoid using asynchronous (callback based, returning Promise, generators or async functions) steps or hooks with Nightwatch API as this will cause errors.

Expand Down Expand Up @@ -507,7 +524,8 @@ The default configuration object is.
htmlReport: 'reports/cucumber.html',
openReport: false,
stepTimeout: 30000,
nightwatchClientAsParameter: false
nightwatchClientAsParameter: false,
cucumberArgs: ''
}
```

Expand Down
6 changes: 5 additions & 1 deletion lib/cucumber-api.js
Expand Up @@ -106,7 +106,7 @@ module.exports = class CucumberAPI {
* run (jsonReport) {
yield mkdirp(path.dirname(jsonReport))
const formats = ['pretty', `json:${jsonReport}`]
const argv = process.argv.slice(0, 2)
let argv = process.argv.slice(0, 2)
this.options.stepDefinitions.concat(this.options.supportFiles).forEach((file) => {
argv.push('--require')
argv.push(file)
Expand All @@ -125,6 +125,10 @@ module.exports = class CucumberAPI {
argv.push(file)
})

if (this.options.cucumberArgs) {
argv = argv.concat(this.options.cucumberArgs.split(' '))
}

const cli = new Cucumber.Cli({
argv,
cwd: process.cwd(),
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Expand Up @@ -40,7 +40,8 @@ module.exports = function (providedOptions) {
htmlReport: 'reports/cucumber.html',
openReport: false,
stepTimeout: 30000,
nightwatchClientAsParameter: false
nightwatchClientAsParameter: false,
cucumberArgs: ''
}, providedOptions)

options.featureFiles.forEach((featureSource) => {
Expand Down
31 changes: 31 additions & 0 deletions test/config.test.js
@@ -0,0 +1,31 @@
/* eslint-env mocha */
const chai = require('chai')
chai.should()
const testCaseFactory = require('./test-case-factory')

describe('Config', () => {
it('should pass cucumberArgs as additional CLI parameters to cucumber', () => {
return testCaseFactory
.create('config-cucumber-args-test', {
nightwatchClientAsParameter: true,
cucumberArgs: '--format progress --format-options {"colorsEnabled":false}'
})
.feature('addition')
.scenario('small numbers')
.given('User is on the simple calculator page', (client) => { client.init() })
.and('User enter 4 in A field', (client) => { client.setValue('#a', 4) })
.and('User enter 5 in B field', (client) => { client.setValue('#b', 5) })
.when('User press Add button', (client) => { client.click('#add') })
.then('The result should contain 9', (client) => { client.assert.containsText('#result', 9) })
.scenario('big numbers')
.given('User is on the simple calculator page')
.and('User enter 4 in A field')
.and('User enter 5 in B field')
.when('User press Add button')
.then('The result should contain 9')
.run()
.then((result) => {
result.output.should.contain('..........')
})
})
})
5 changes: 4 additions & 1 deletion test/fixture/nightwatch.conf.js.tmpl
Expand Up @@ -21,7 +21,10 @@ require('../../lib/index')({
}
<% } %>
<% if (nightwatchClientAsParameter) {%>
nightwatchClientAsParameter: true
nightwatchClientAsParameter: true,
<% } %>
<% if (cucumberArgs) {%>
cucumberArgs: '<%=cucumberArgs%>'
<% } %>
})

Expand Down
3 changes: 2 additions & 1 deletion test/test-case-factory.js
Expand Up @@ -25,7 +25,8 @@ class TestCaseFactory {
gulp: false,
grunt: false,
programmatical: false,
nightwatchClientAsParameter: false
nightwatchClientAsParameter: false,
cucumberArgs: false
}, options)
this.groups = []
this.stepDefinitions = []
Expand Down

0 comments on commit d33eec6

Please sign in to comment.