Skip to content

Commit

Permalink
Call protractor's afterEach before features run...trust me
Browse files Browse the repository at this point in the history
Kind of strange to have to call this in setup, but all scenarios fail up
until it is called when `restartBrowserBetweenTests` is used. Protractor
is setting some internal runner state that is affecting this.

angular/protractor@23bc943

Should fix #100
Should fix #88
  • Loading branch information
darrinholst committed Sep 16, 2017
1 parent a40bce7 commit a8461e0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
15 changes: 12 additions & 3 deletions lib/resultsCapturer.js
Expand Up @@ -26,19 +26,28 @@ let scenarioFailed = false;
let stepResults = buildStepResults();

function registerHandlers() {
this.registerHandler('BeforeFeatures', clearResults);
this.registerHandler('BeforeFeatures', setup);
this.registerHandler('AfterScenario', afterScenarioHandler);
this.registerHandler('StepResult', stepResultHandler);
}

function eventListeners(options) {
options.eventBroadcaster.on('gherkin-document', cacheDocument);
options.eventBroadcaster.on('test-run-started', clearResults);
options.eventBroadcaster.on('test-run-started', setup);
options.eventBroadcaster.on('test-case-finished', testCaseFinished);
options.eventBroadcaster.on('test-step-finished', testStepFinished);
}

function clearResults() {
function setup() {
/*
* Kind of strange to have to call this in setup, but all scenarios fail up
* until it is called when `restartBrowserBetweenTests` is used. Protractor
* is setting some internal runner state that is affecting this.
*
* https://github.com/angular/protractor/commit/23bc943a8a65bf4abab10197c5d3545189785b9a
*
*/
if (state.runner.afterEach) state.runner.afterEach();
state.results.failedCount = 0;
state.results.specResults = [];
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "protractor-cucumber-framework",
"version": "4.0.7",
"version": "4.0.8",
"description": "Protractor framework for Cucumber.js",
"main": "index.js",
"engines": {
Expand Down
16 changes: 16 additions & 0 deletions test/restart-browser.spec.js
@@ -0,0 +1,16 @@
let util = require('./test_util');

describe('restart browsers between tests', function() {
it('should run all scenarios successfully', function() {
let cmd =
'test/cucumber/conf/cucumber3Conf.js --restartBrowserBetweenTests';

return util
.runOne(cmd)
.cucumberVersion3()
.expectExitCode(0)
.expectOutput('3 scenarios (3 passed)')
.expectErrors([])
.run();
});
});

0 comments on commit a8461e0

Please sign in to comment.