diff --git a/lib/frameworks/cucumber.js b/lib/frameworks/cucumber.js index b5e572da8..90ad5f436 100644 --- a/lib/frameworks/cucumber.js +++ b/lib/frameworks/cucumber.js @@ -58,17 +58,65 @@ exports.run = function(runner, specs) { } global.cucumber = Cucumber.Cli(execOptions); + var testResult = []; + var failedCount = 0; + // Add a listener into cucumber so that protractor can find out which + // steps passed/failed + var addResultListener = function(formatter) { + var handleStepResultEvent = formatter.handleStepResultEvent; + var newHandleStepResultEvent = function(event, callback) { + + var stepResult = event.getPayloadItem('stepResult'); + if (stepResult.isSuccessful()) { + runner.emit('testPass'); + testResult.push({ + description: stepResult.getStep().getName(), + result: [{ + passed: true + }], + duration: stepResult.getDuration() + }); + } + else if (stepResult.isFailed()) { + runner.emit('testFail'); + ++failedCount; + var failureMessage = stepResult.getFailureException(); + testResult.push({ + description: stepResult.getStep().getName(), + assertions: [{ + passed: false, + errorMsg: failureMessage.message, + stackTrace: failureMessage.stack + }], + duration: stepResult.getDuration() + }); + } + + if (handleStepResultEvent && typeof(handleStepResultEvent) === 'function') { + handleStepResultEvent(event, callback); + } else { + callback(); + } + } + formatter.handleStepResultEvent = newHandleStepResultEvent; + }; + return runner.runTestPreparer().then(function () { return q.promise(function (resolve, reject) { - global.cucumber.run(function (succeeded) { + var cucumberConf = Cucumber.Cli.Configuration(execOptions); + var runtime = Cucumber.Runtime(cucumberConf); + var formatter = cucumberConf.getFormatter(); + addResultListener(formatter); + runtime.attachListener(formatter); + runtime.start(function (succeeded) { try { if (runner.getConfig().onComplete) { runner.getConfig().onComplete(); } - var resolvedObj = { - failedCount: succeeded ? 0 : 1 - }; - resolve(resolvedObj); + resolve({ + failedCount: failedCount, + specResults: testResult + }); } catch (err) { reject(err); }