Skip to content
Permalink
Browse files
fix(cucumber): cucumber adapter waits for async tasks to complete bef…
…ore starting a scenario

This is to align the behaviour with @serenity-js/jasmine and ensure restarting the browser when the
@serenity-js/cucumber module is combined with @serenity-js/protractor does not cause invalid
WebDriver session errors.

Closes #56
  • Loading branch information
jan-molak committed Jan 19, 2020
1 parent ad5a2b6 commit 0ed2d4c023f39857355eb98ff8311d0e5ed174dc
@@ -4,3 +4,13 @@ Feature: Interactions

When Umbra navigates to the test website
Then she should see the title of "Test Website"

Scenario: Actor interacts with a website 2

When Umbra navigates to the test website
Then she should see the title of "Test Website"

Scenario: Actor interacts with a website 3

When Umbra navigates to the test website
Then she should see the title of "Test Website"
@@ -7,6 +7,8 @@ exports.config = {
chromeDriver: require('chromedriver/lib/chromedriver').path,
SELENIUM_PROMISE_MANAGER: false,

// restartBrowserBetweenTests: true,

directConnect: true,

allScriptsTimeout: 11000,
@@ -31,7 +33,6 @@ exports.config = {
'features/support/setup.ts',
],
'require-module': ['ts-node/register'],
tags: [ '@wip' ],
},

capabilities: {
@@ -16,7 +16,7 @@ describe('CucumberEventProtocolAdapter', () => {
type CucumberHook = () => Promise<void> | void;

const fakeCucumber = {
After: (hook: CucumberHook) => Promise.resolve(hook()),
Before: (hook: CucumberHook) => Promise.resolve(hook()),
AfterAll: (hook: CucumberHook) => Promise.resolve(hook()),
};

@@ -20,6 +20,11 @@ export = function ({ notifier, loader, cache }: Dependencies) {
loader.load(get(feature, 'uri').as(Path)).then(_ => callback(), error => callback(error));
});

this.registerHandler('BeforeScenario', function (scenario, callback) {
serenity.waitForNextCue()
.then(() => callback(), error => callback(error));
});

this.registerHandler('BeforeScenario', function (scenario) {
const
path = get(scenario, 'uri').as(Path),
@@ -73,15 +78,9 @@ export = function ({ notifier, loader, cache }: Dependencies) {
notifier.scenarioFinished(map.get(Scenario).onLine(line), map.getFirst(Feature), scenarioOutcomeFrom(result));
});

this.registerHandler('AfterScenario', function (scenario, callback) {
serenity.waitForNextCue()
.then(() => callback(), error => callback(error));
});

this.registerHandler('AfterFeatures', (features, callback) => {
notifier.testRunFinished();

serenity.waitForNextCue()
.then(() => notifier.testRunFinished())
.then(() => callback(), error => callback(error));
});
};
@@ -4,14 +4,14 @@ import { Dependencies } from './Dependencies';

export = function (dependencies: Dependencies) {

dependencies.cucumber.defineSupportCode(({ After, AfterAll }) => {
After(function () {
dependencies.cucumber.defineSupportCode(({ Before, AfterAll }) => {
Before(function () {
return serenity.waitForNextCue();
});

AfterAll(function () {
dependencies.notifier.testRunFinished();
return serenity.waitForNextCue();
return serenity.waitForNextCue()
.then(() => dependencies.notifier.testRunFinished());
});
});

@@ -3,15 +3,15 @@ import { cucumberEventProtocolAdapter } from './CucumberEventProtocolAdapter';
import { Dependencies } from './Dependencies';

export = function (dependencies: Dependencies) {
const { After, AfterAll } = dependencies.cucumber;
const { Before, AfterAll } = dependencies.cucumber;

After(function () {
Before(function () {
return serenity.waitForNextCue();
});

AfterAll(function () {
dependencies.notifier.testRunFinished();
return serenity.waitForNextCue();
return serenity.waitForNextCue()
.then(() => dependencies.notifier.testRunFinished());
});

return cucumberEventProtocolAdapter(dependencies);

0 comments on commit 0ed2d4c

Please sign in to comment.