From 893f8bfc46c85d28391ba34217d060cdf8201a00 Mon Sep 17 00:00:00 2001 From: Igor Muchychka Date: Thu, 25 Jan 2018 08:12:27 +0100 Subject: [PATCH] feat: CucumberJS 4.0.0 support BREAKING CHANGE: CucumberJS 3.x support has been dropped. --- .../features/step_definitions/steps.js | 42 +++++------ examples/babel-example/nightwatch.conf.js | 2 +- .../features/step_definitions/steps.js | 32 ++++---- .../features/step_definitions/steps.js | 28 +++---- .../features/step_definitions/steps.js | 46 +++++------- .../features/step_definitions/steps.js | 46 +++++------- .../features/step_definitions/steps.js | 32 ++++---- .../features/step_definitions/steps.js | 32 ++++---- .../features/step_definitions/steps.js | 46 +++++------- .../features/step_definitions/steps.js | 28 +++---- .../features/step_definitions/steps.js | 46 +++++------- .../features/step_definitions/steps.js | 28 +++---- .../features/step_definitions/steps.js | 46 +++++------- lib/nightwatch-api.js | 3 +- package.json | 16 ++-- site/data/advanced-features/babel-support.md | 27 +++---- site/data/configuration/hooks.md | 32 ++++---- site/data/intro/demo-test.md | 27 +++---- site/data/patterns/page-objects.md | 25 +++---- site/data/patterns/session-handling.md | 12 ++- test/fixture/nightwatch.conf.js.tmpl | 2 +- test/test-case-factory.js | 12 +-- yarn.lock | 74 ++++++++++--------- 23 files changed, 308 insertions(+), 376 deletions(-) diff --git a/examples/babel-example/features/step_definitions/steps.js b/examples/babel-example/features/step_definitions/steps.js index d1a9b88..fcb0e40 100644 --- a/examples/babel-example/features/step_definitions/steps.js +++ b/examples/babel-example/features/step_definitions/steps.js @@ -1,26 +1,20 @@ import { client } from 'nightwatch-cucumber' -import { defineSupportCode } from 'cucumber' +import { Given, Then, When } from 'cucumber' -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, async () => { - await client.url('http://google.com') - await client.waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, async (text) => { - await client.assert.title(text) - }) - - Then(/^the Google search form exists$/, async () => { - await client.assert.visible('input[name="q"]') - }) - - Given(/^I open Yahoo`s search page$/, async () => { - await client.url('http://yahoo.com') - await client.waitForElementVisible('body', 1000) - }) - - Then(/^the Yahoo search form exists$/, async () => { - await client.assert.visible('input[name="p"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, async () => { + await client.url('http://google.com') + await client.waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, async (text) => { + await client.assert.title(text) +}) +Then(/^the Google search form exists$/, async () => { + await client.assert.visible('input[name="q"]') +}) +Given(/^I open Yahoo`s search page$/, async () => { + await client.url('http://yahoo.com') + await client.waitForElementVisible('body', 1000) +}) +Then(/^the Yahoo search form exists$/, async () => { + await client.assert.visible('input[name="p"]') +}) diff --git a/examples/babel-example/nightwatch.conf.js b/examples/babel-example/nightwatch.conf.js index 2f1db61..858e5f7 100644 --- a/examples/babel-example/nightwatch.conf.js +++ b/examples/babel-example/nightwatch.conf.js @@ -3,7 +3,7 @@ const phantomjs = require('phantomjs-prebuilt') const chromedriver = require('chromedriver') require('nightwatch-cucumber')({ - cucumberArgs: ['--compiler', 'js:babel-core/register', '--require', 'features/step_definitions', '--format', 'json:reports/cucumber.json', 'features'] + cucumberArgs: ['--require-module', 'babel-core/register', '--require', 'features/step_definitions', '--format', 'json:reports/cucumber.json', 'features'] }) module.exports = { diff --git a/examples/background-example/features/step_definitions/steps.js b/examples/background-example/features/step_definitions/steps.js index 8ab8fbf..8de8cfb 100644 --- a/examples/background-example/features/step_definitions/steps.js +++ b/examples/background-example/features/step_definitions/steps.js @@ -1,20 +1,16 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - When(/^I search for "(.*?)"$/, (text) => { - return client - .setValue('input[name=q]', text) - .submitForm('input[name=q]') - }) - - Then(/^the search result should contain "(.*?)"$/, (text) => { - return client.assert.containsText('body', text) - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +When(/^I search for "(.*?)"$/, (text) => { + return client + .setValue('input[name=q]', text) + .submitForm('input[name=q]') +}) +Then(/^the search result should contain "(.*?)"$/, (text) => { + return client.assert.containsText('body', text) +}) diff --git a/examples/group-example/features/step_definitions/steps.js b/examples/group-example/features/step_definitions/steps.js index 20beba1..fe64c4c 100644 --- a/examples/group-example/features/step_definitions/steps.js +++ b/examples/group-example/features/step_definitions/steps.js @@ -1,18 +1,14 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, (text) => { - return client.assert.title(text) - }) - - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return client.assert.title(text) +}) +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]') +}) diff --git a/examples/hooks-example/features/step_definitions/steps.js b/examples/hooks-example/features/step_definitions/steps.js index 92e0549..f456752 100644 --- a/examples/hooks-example/features/step_definitions/steps.js +++ b/examples/hooks-example/features/step_definitions/steps.js @@ -1,28 +1,22 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, (text) => { - return client.assert.title(text) - }) - - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]') - }) - - Given(/^I open Yahoo`s search page$/, () => { - return client - .url('http://yahoo.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the Yahoo search form exists$/, () => { - return client.assert.visible('input[name="p"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return client.assert.title(text) +}) +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]') +}) +Given(/^I open Yahoo`s search page$/, () => { + return client + .url('http://yahoo.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the Yahoo search form exists$/, () => { + return client.assert.visible('input[name="p"]') +}) diff --git a/examples/multi-example/features/step_definitions/steps.js b/examples/multi-example/features/step_definitions/steps.js index 92e0549..f456752 100644 --- a/examples/multi-example/features/step_definitions/steps.js +++ b/examples/multi-example/features/step_definitions/steps.js @@ -1,28 +1,22 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, (text) => { - return client.assert.title(text) - }) - - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]') - }) - - Given(/^I open Yahoo`s search page$/, () => { - return client - .url('http://yahoo.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the Yahoo search form exists$/, () => { - return client.assert.visible('input[name="p"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return client.assert.title(text) +}) +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]') +}) +Given(/^I open Yahoo`s search page$/, () => { + return client + .url('http://yahoo.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the Yahoo search form exists$/, () => { + return client.assert.visible('input[name="p"]') +}) diff --git a/examples/outlines-example/features/step_definitions/steps.js b/examples/outlines-example/features/step_definitions/steps.js index 329c669..a90d822 100644 --- a/examples/outlines-example/features/step_definitions/steps.js +++ b/examples/outlines-example/features/step_definitions/steps.js @@ -1,20 +1,16 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - When(/^I search for (.*?)$/, (expression) => { - return client - .setValue('input[name=q]', expression) - .submitForm('input[name=q]') - }) - - Then(/^the search result should contain (.*?)$/, (result) => { - return client.assert.containsText('body', result) - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +When(/^I search for (.*?)$/, (expression) => { + return client + .setValue('input[name=q]', expression) + .submitForm('input[name=q]') +}) +Then(/^the search result should contain (.*?)$/, (result) => { + return client.assert.containsText('body', result) +}) diff --git a/examples/page-object-example/features/step_definitions/steps.js b/examples/page-object-example/features/step_definitions/steps.js index a655070..c2d3b8c 100644 --- a/examples/page-object-example/features/step_definitions/steps.js +++ b/examples/page-object-example/features/step_definitions/steps.js @@ -1,22 +1,18 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Yahoo`s search page$/, () => { - const yahoo = client.page.yahoo() +Given(/^I open Yahoo`s search page$/, () => { + const yahoo = client.page.yahoo() - return yahoo - .navigate() - .waitForElementVisible('@body', 1000) - }) + return yahoo + .navigate() + .waitForElementVisible('@body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return client.assert.title(text) +}) +Then(/^the Yahoo search form exists$/, () => { + const yahoo = client.page.yahoo() - Then(/^the title is "(.*?)"$/, (text) => { - return client.assert.title(text) - }) - - Then(/^the Yahoo search form exists$/, () => { - const yahoo = client.page.yahoo() - - return yahoo.assert.visible('@searchBar') - }) -}) \ No newline at end of file + return yahoo.assert.visible('@searchBar') +}) diff --git a/examples/paralell-example/features/step_definitions/steps.js b/examples/paralell-example/features/step_definitions/steps.js index 92e0549..f456752 100644 --- a/examples/paralell-example/features/step_definitions/steps.js +++ b/examples/paralell-example/features/step_definitions/steps.js @@ -1,28 +1,22 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, (text) => { - return client.assert.title(text) - }) - - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]') - }) - - Given(/^I open Yahoo`s search page$/, () => { - return client - .url('http://yahoo.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the Yahoo search form exists$/, () => { - return client.assert.visible('input[name="p"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return client.assert.title(text) +}) +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]') +}) +Given(/^I open Yahoo`s search page$/, () => { + return client + .url('http://yahoo.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the Yahoo search form exists$/, () => { + return client.assert.visible('input[name="p"]') +}) diff --git a/examples/pending-with-no-strict-example/features/step_definitions/steps.js b/examples/pending-with-no-strict-example/features/step_definitions/steps.js index 0263ccd..b666dda 100644 --- a/examples/pending-with-no-strict-example/features/step_definitions/steps.js +++ b/examples/pending-with-no-strict-example/features/step_definitions/steps.js @@ -1,18 +1,14 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, (text) => { - return 'pending' - }) - - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return 'pending' +}) +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]') +}) diff --git a/examples/programmatical-example/features/step_definitions/steps.js b/examples/programmatical-example/features/step_definitions/steps.js index 92e0549..f456752 100644 --- a/examples/programmatical-example/features/step_definitions/steps.js +++ b/examples/programmatical-example/features/step_definitions/steps.js @@ -1,28 +1,22 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, (text) => { - return client.assert.title(text) - }) - - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]') - }) - - Given(/^I open Yahoo`s search page$/, () => { - return client - .url('http://yahoo.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the Yahoo search form exists$/, () => { - return client.assert.visible('input[name="p"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return client.assert.title(text) +}) +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]') +}) +Given(/^I open Yahoo`s search page$/, () => { + return client + .url('http://yahoo.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the Yahoo search form exists$/, () => { + return client.assert.visible('input[name="p"]') +}) diff --git a/examples/simple-example/features/step_definitions/steps.js b/examples/simple-example/features/step_definitions/steps.js index 20beba1..fe64c4c 100644 --- a/examples/simple-example/features/step_definitions/steps.js +++ b/examples/simple-example/features/step_definitions/steps.js @@ -1,18 +1,14 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, (text) => { - return client.assert.title(text) - }) - - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return client.assert.title(text) +}) +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]') +}) diff --git a/examples/tag-example/features/step_definitions/steps.js b/examples/tag-example/features/step_definitions/steps.js index 92e0549..f456752 100644 --- a/examples/tag-example/features/step_definitions/steps.js +++ b/examples/tag-example/features/step_definitions/steps.js @@ -1,28 +1,22 @@ const { client } = require('nightwatch-cucumber') -const { defineSupportCode } = require('cucumber') +const { Given, Then, When } = require('cucumber') -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google`s search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the title is "(.*?)"$/, (text) => { - return client.assert.title(text) - }) - - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]') - }) - - Given(/^I open Yahoo`s search page$/, () => { - return client - .url('http://yahoo.com') - .waitForElementVisible('body', 1000) - }) - - Then(/^the Yahoo search form exists$/, () => { - return client.assert.visible('input[name="p"]') - }) -}) \ No newline at end of file +Given(/^I open Google`s search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the title is "(.*?)"$/, (text) => { + return client.assert.title(text) +}) +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]') +}) +Given(/^I open Yahoo`s search page$/, () => { + return client + .url('http://yahoo.com') + .waitForElementVisible('body', 1000) +}) +Then(/^the Yahoo search form exists$/, () => { + return client.assert.visible('input[name="p"]') +}) diff --git a/lib/nightwatch-api.js b/lib/nightwatch-api.js index c5c5c98..e069eac 100644 --- a/lib/nightwatch-api.js +++ b/lib/nightwatch-api.js @@ -326,7 +326,8 @@ module.exports = class NightwatchApi { }).then(resolve, reject) }) self._startSession(this.options) - executionSuccess = yield * testRunner(modules) + const executionResult = yield * testRunner(modules) + executionSuccess = !!executionResult.success } catch (err) { error = err } diff --git a/package.json b/package.json index f57cd6e..894dfd4 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "resources" ], "peerDependencies": { - "cucumber": "3.0.0 - 3.2.1", + "cucumber": "3.0.0 - 4.0.0", "nightwatch": "0.9.0 - 0.9.19" }, "devDependencies": { @@ -62,12 +62,12 @@ "babel-plugin-transform-async-to-generator": "^6.24.1", "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", "chai": "^4.1.2", - "chromedriver": "^2.34.1", + "chromedriver": "^2.35.0", "coveralls": "^3.0.0", - "cucumber": "3.2.1", + "cucumber": "4.0.0", "cucumber-html-reporter": "3.0.4", "cz-conventional-changelog": "^2.1.0", - "eslint": "^4.15.0", + "eslint": "^4.16.0", "eslint-config-standard": "^11.0.0-beta.0", "eslint-plugin-import": "^2.7.0", "eslint-plugin-no-only-tests": "^2.0.0", @@ -78,20 +78,20 @@ "gulp": "^3.9.1", "gulp-nightwatch": "^0.3.2", "istanbul": "^0.4.5", - "jsdom": "^11.5.1", + "jsdom": "11.5.1", "markdown-it": "^8.4.0", "markdown-it-anchor": "^4.0.0", "markdown-it-table-of-contents": "^0.3.3", - "mocha": "^4.1.0", + "mocha": "^5.0.0", "nightwatch": "0.9.19", "phantomjs-prebuilt": "^2.1.16", - "prismjs": "^1.9.0", + "prismjs": "^1.10.0", "prismjs-components-loader": "^2.0.0", "rimraf": "^2.6.2", "selenium-server": "3.7.1", "semantic-release": "7.0.2", "twemoji": "^2.5.0", - "simple-icons": "^1.2.18" + "simple-icons": "^1.2.19" }, "config": { "commitizen": { diff --git a/site/data/advanced-features/babel-support.md b/site/data/advanced-features/babel-support.md index 0b9deb5..11608a7 100644 --- a/site/data/advanced-features/babel-support.md +++ b/site/data/advanced-features/babel-support.md @@ -1,12 +1,12 @@ ## Babel support You can write tests using latest ECMAScript features using [Babel](https://babeljs.io/). Using `async` function is especially useful. -For that you need install `babel-core`, setup `.babelrc` and add Babel as compiler +For that you need install `babel-core`, setup `.babelrc` and add Babel as require-module ```javascript // nightwatch.conf.js require('nightwatch-cucumber')({ - cucumberArgs: ['--compiler', 'js:babel-core/register', '--require', 'features/step_definitions', 'features'] + cucumberArgs: ['--require-module', 'babel-core/register', '--require', 'features/step_definitions', 'features'] }) ... ``` @@ -15,22 +15,19 @@ require('nightwatch-cucumber')({ // features/step_definitions/google.js import { client } from 'nightwatch-cucumber'; -import { defineSupportCode } from 'cucumber'; +import { Given, Then, When } from 'cucumber'; -defineSupportCode(({ Given, Then, When }) => { - Given(/^I open Google's search page$/, async () => { - await client.url('http://google.com') - await client.waitForElementVisible('body', 1000); - }); - - Then(/^the title is "([^"]*)"$/, async (title) => { - await client.assert.title(title); - }); +Given(/^I open Google's search page$/, async () => { + await client.url('http://google.com') + await client.waitForElementVisible('body', 1000); +}); - Then(/^the Google search form exists$/, async () => { - await client.assert.visible('input[name="q"]'); - }); +Then(/^the title is "([^"]*)"$/, async (title) => { + await client.assert.title(title); +}); +Then(/^the Google search form exists$/, async () => { + await client.assert.visible('input[name="q"]'); }); ``` diff --git a/site/data/configuration/hooks.md b/site/data/configuration/hooks.md index a138eae..1a937ac 100644 --- a/site/data/configuration/hooks.md +++ b/site/data/configuration/hooks.md @@ -22,23 +22,21 @@ module.exports = { ```javascript // hooks.js -const {defineSupportCode} = require('cucumber'); +const { Before, After } = require('cucumber'); -defineSupportCode(({Before, After}) => { - Before(() => new Promise(resolve => { - console.log('Before start'); - setTimeout(() => { - console.log('Before end'); - resolve(); - }, 1000); - })); +Before(() => new Promise(resolve => { + console.log('Before start'); + setTimeout(() => { + console.log('Before end'); + resolve(); + }, 1000); +})); - After(() => new Promise(resolve => { - console.log('After start'); - setTimeout(() => { - console.log('After end'); - resolve(); - }, 1000); - })); -}) +After(() => new Promise(resolve => { + console.log('After start'); + setTimeout(() => { + console.log('After end'); + resolve(); + }, 1000); +})); ``` diff --git a/site/data/intro/demo-test.md b/site/data/intro/demo-test.md index e662f4a..bcfa37b 100644 --- a/site/data/intro/demo-test.md +++ b/site/data/intro/demo-test.md @@ -19,24 +19,21 @@ Step definitions files are located in `features/step_definitions` folder by defa ```javascript // features/step_definitions/google.js -const {client} = require('nightwatch-cucumber'); -const {defineSupportCode} = require('cucumber'); +const { client } = require('nightwatch-cucumber'); +const { Given, Then, When } = require('cucumber'); -defineSupportCode(({Given, Then, When}) => { - Given(/^I open Google's search page$/, () => { - return client - .url('http://google.com') - .waitForElementVisible('body', 1000); - }); - - Then(/^the title is "([^"]*)"$/, (title) => { - return client.assert.title(title); - }); +Given(/^I open Google's search page$/, () => { + return client + .url('http://google.com') + .waitForElementVisible('body', 1000); +}); - Then(/^the Google search form exists$/, () => { - return client.assert.visible('input[name="q"]'); - }); +Then(/^the title is "([^"]*)"$/, (title) => { + return client.assert.title(title); +}); +Then(/^the Google search form exists$/, () => { + return client.assert.visible('input[name="q"]'); }); ``` diff --git a/site/data/patterns/page-objects.md b/site/data/patterns/page-objects.md index fb6d170..e70b6df 100644 --- a/site/data/patterns/page-objects.md +++ b/site/data/patterns/page-objects.md @@ -31,23 +31,20 @@ Now we can use page objects from step definitions ```javascript //step-definitions/yahoo.js -const {client} = require('nightwatch-cucumber'); -const {defineSupportCode} = require('cucumber'); +const { client } = require('nightwatch-cucumber'); +const { Given, Then, When } = require('cucumber'); -defineSupportCode(({Given, Then, When}) => { - Given(/^I open Yahoo's search page$/, () => { - const yahoo = client.page.yahoo(); +Given(/^I open Yahoo's search page$/, () => { + const yahoo = client.page.yahoo(); - return yahoo - .navigate() - .waitForElementVisible('@body', 1000); - }); - - Then(/^the Yahoo search form exists$/, () => { - const yahoo = client.page.yahoo(); + return yahoo + .navigate() + .waitForElementVisible('@body', 1000); +}); - return yahoo.assert.visible('@searchBar'); - }); +Then(/^the Yahoo search form exists$/, () => { + const yahoo = client.page.yahoo(); + return yahoo.assert.visible('@searchBar'); }); ``` diff --git a/site/data/patterns/session-handling.md b/site/data/patterns/session-handling.md index c3beeea..3966b1d 100644 --- a/site/data/patterns/session-handling.md +++ b/site/data/patterns/session-handling.md @@ -9,12 +9,10 @@ As starter you can use the following support code. ```javascript const { client } = require('nightwatch-cucumber'); -const { defineSupportCode } = require('cucumber'); +const { After } = require('cucumber'); -defineSupportCode(({ After }) => { - After(() => client.execute(` - localStorage.clear(); - sessionStorage.clear(); - `).deleteCookies().refresh()); -}); +After(() => client.execute(` + localStorage.clear(); + sessionStorage.clear(); +`).deleteCookies().refresh()); ``` diff --git a/test/fixture/nightwatch.conf.js.tmpl b/test/fixture/nightwatch.conf.js.tmpl index a305606..237059b 100644 --- a/test/fixture/nightwatch.conf.js.tmpl +++ b/test/fixture/nightwatch.conf.js.tmpl @@ -28,7 +28,7 @@ module.exports = { <% } %> selenium: { - start_process: true , + start_process: true, server_path: seleniumServer.path, log_path: '', host: '127.0.0.1', diff --git a/test/test-case-factory.js b/test/test-case-factory.js index f1f7944..4abe8a4 100644 --- a/test/test-case-factory.js +++ b/test/test-case-factory.js @@ -109,8 +109,8 @@ class TestCaseFactory { .replace(/<(.*?)>/g, '(.*?)') .replace(/"(.*?)"/g, '"(.*?)"') const regex = `/^${namePattern}$/` - stepDefinition = setIdentation(stepDefinition.toString(), 2) - this.stepDefinitions.push(`\n ${definitionType}(${regex}, ${stepDefinition})\n`) + stepDefinition = setIdentation(stepDefinition.toString(), 0) + this.stepDefinitions.push(`${definitionType}(${regex}, ${stepDefinition})\n`) } return this } @@ -194,14 +194,14 @@ class TestCaseFactory { let importCode if (this.options.babel) { importCode = `import { client } from '${main}' -import { defineSupportCode } from 'cucumber'` +import { Given, Then, When } from 'cucumber'` } else { importCode = `const { client } = require('${main}') -const { defineSupportCode } = require('cucumber')` +const { Given, Then, When } = require('cucumber')` } const steps = `${importCode} ${this.prependStepDefinitions.join('')} -defineSupportCode(({ Given, Then, When }) => {${this.stepDefinitions.join('')}})` +${this.stepDefinitions.join('')}` if (this.stepDefinitions.length) { fs.writeFileSync(path.join(this.testCasePath, 'features', 'step_definitions', 'steps.js'), steps) } @@ -236,7 +236,7 @@ defineSupportCode(({ Given, Then, When }) => {${this.stepDefinitions.join('')}}) let args = ['--require', 'features/step_definitions'] if (this.options.babel) { - args = ['--compiler', `js:babel-core/register`].concat(args) + args = ['--require-module', `babel-core/register`].concat(args) } if (this.options.cucumberArgs.length) { diff --git a/yarn.lock b/yarn.lock index ca47353..c187550 100644 --- a/yarn.lock +++ b/yarn.lock @@ -39,9 +39,9 @@ conventional-changelog "1.1.4" github-url-from-git "^1.4.0" -"@types/node@^6.0.46": - version "6.0.90" - resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.90.tgz#0ed74833fa1b73dcdb9409dcb1c97ec0a8b13b02" +"@types/node@*": + version "9.3.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-9.3.0.tgz#3a129cda7c4e5df2409702626892cb4b96546dd5" JSONStream@^1.0.4: version "1.3.1" @@ -78,10 +78,14 @@ acorn@^3.0.4: version "3.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" -acorn@^5.0.0, acorn@^5.1.2: +acorn@^5.0.0: version "5.1.2" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.2.tgz#911cb53e036807cf0fa778dc5d370fbd864246d7" +acorn@^5.1.2: + version "5.3.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822" + acorn@^5.2.1: version "5.2.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.2.1.tgz#317ac7821826c22c702d66189ab8359675f135d7" @@ -645,9 +649,9 @@ check-error@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82" -chromedriver@^2.34.1: - version "2.34.1" - resolved "https://registry.yarnpkg.com/chromedriver/-/chromedriver-2.34.1.tgz#4ceff1b1ef785fb41bd75029167e94b50bd77844" +chromedriver@^2.35.0: + version "2.35.0" + resolved "https://registry.yarnpkg.com/chromedriver/-/chromedriver-2.35.0.tgz#c103ba2fb3d1671f666058159f5cbaa816902e4d" dependencies: del "^3.0.0" extract-zip "^1.6.5" @@ -1008,9 +1012,9 @@ cucumber-tag-expressions@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/cucumber-tag-expressions/-/cucumber-tag-expressions-1.1.1.tgz#7f5c7b70009bc2b666591bfe64854578bedee85a" -cucumber@3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/cucumber/-/cucumber-3.2.1.tgz#7898509bf6f3fe4ef5fa30ba987bd53d88d53251" +cucumber@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/cucumber/-/cucumber-4.0.0.tgz#09f078b852d817c8f818737d0dcc34d40f31534f" dependencies: assertion-error-formatter "^2.0.1" babel-runtime "^6.11.6" @@ -1028,7 +1032,7 @@ cucumber@3.2.1: indent-string "^3.1.0" is-generator "^1.0.2" is-stream "^1.1.0" - lodash "^4.0.0" + lodash "^4.17.4" mz "^2.4.0" progress "^2.0.0" resolve "^1.3.3" @@ -1231,9 +1235,9 @@ doctrine@1.5.0: esutils "^2.0.2" isarray "^1.0.0" -doctrine@^2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.0.2.tgz#68f96ce8efc56cc42651f1faadb4f175273b0075" +doctrine@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d" dependencies: esutils "^2.0.2" @@ -1417,9 +1421,9 @@ eslint-visitor-keys@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d" -eslint@^4.15.0: - version "4.15.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.15.0.tgz#89ab38c12713eec3d13afac14e4a89e75ef08145" +eslint@^4.16.0: + version "4.16.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.16.0.tgz#934ada9e98715e1d7bbfd6f6f0519ed2fab35cc1" dependencies: ajv "^5.3.0" babel-code-frame "^6.22.0" @@ -1427,7 +1431,7 @@ eslint@^4.15.0: concat-stream "^1.6.0" cross-spawn "^5.1.0" debug "^3.1.0" - doctrine "^2.0.2" + doctrine "^2.1.0" eslint-scope "^3.7.1" eslint-visitor-keys "^1.0.0" espree "^3.5.2" @@ -2737,7 +2741,7 @@ jschardet@^1.4.2: version "1.5.1" resolved "https://registry.yarnpkg.com/jschardet/-/jschardet-1.5.1.tgz#c519f629f86b3a5bedba58a88d311309eec097f9" -jsdom@^11.5.1: +jsdom@11.5.1: version "11.5.1" resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-11.5.1.tgz#5df753b8d0bca20142ce21f4f6c039f99a992929" dependencies: @@ -3408,9 +3412,9 @@ mocha-nightwatch@3.2.2: mkdirp "0.5.1" supports-color "3.1.2" -mocha@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-4.1.0.tgz#7d86cfbcf35cb829e2754c32e17355ec05338794" +mocha@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.0.0.tgz#cccac988b0bc5477119cba0e43de7af6d6ad8f4e" dependencies: browser-stdout "1.3.0" commander "2.11.0" @@ -3788,10 +3792,10 @@ parse-passwd@^1.0.0: resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6" parse5@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/parse5/-/parse5-3.0.2.tgz#05eff57f0ef4577fb144a79f8b9a967a6cc44510" + version "3.0.3" + resolved "https://registry.yarnpkg.com/parse5/-/parse5-3.0.3.tgz#042f792ffdd36851551cf4e9e066b3874ab45b5c" dependencies: - "@types/node" "^6.0.46" + "@types/node" "*" path-exists@^2.0.0: version "2.1.0" @@ -3907,8 +3911,8 @@ pluralize@^7.0.0: resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777" pn@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/pn/-/pn-1.0.0.tgz#1cf5a30b0d806cd18f88fc41a6b5d4ad615b3ba9" + version "1.1.0" + resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb" prelude-ls@~1.1.2: version "1.1.2" @@ -3926,9 +3930,9 @@ prismjs-components-loader@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/prismjs-components-loader/-/prismjs-components-loader-2.0.0.tgz#2cb9bbdd011d5d56b6a66f67981e6acb61957360" -prismjs@^1.9.0: - version "1.9.0" - resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.9.0.tgz#fa3e2d9edc3c3887c1f1f3095d41f1f9b4200f0f" +prismjs@^1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.10.0.tgz#77e5187c2ae6b3253fcc313029cf25fe53778721" optionalDependencies: clipboard "^1.7.1" @@ -4394,9 +4398,9 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" -simple-icons@^1.2.18: - version "1.2.18" - resolved "https://registry.yarnpkg.com/simple-icons/-/simple-icons-1.2.18.tgz#b38dd2169ec65efca752021dbeba255636eaf1d4" +simple-icons@^1.2.19: + version "1.2.19" + resolved "https://registry.yarnpkg.com/simple-icons/-/simple-icons-1.2.19.tgz#e2277b6f64e4fddd78a730763a3cd0cde488d678" slash@^1.0.0: version "1.0.0" @@ -4984,8 +4988,8 @@ whatwg-encoding@^1.0.1: iconv-lite "0.4.13" whatwg-url@^6.3.0: - version "6.3.0" - resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.3.0.tgz#597ee5488371abe7922c843397ddec1ae94c048d" + version "6.4.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.4.0.tgz#08fdf2b9e872783a7a1f6216260a1d66cc722e08" dependencies: lodash.sortby "^4.7.0" tr46 "^1.0.0"