@@ -59,37 +59,61 @@ exports.run = function(runner, specs) {
59
59
global . cucumber = Cucumber . Cli ( execOptions ) ;
60
60
61
61
var testResult = [ ] ;
62
+ var stepResults = {
63
+ description : null ,
64
+ assertions : [ ] ,
65
+ duration : 0
66
+ } ;
67
+ var scenarioFailed = false ;
68
+
62
69
var failedCount = 0 ;
63
70
// Add a listener into cucumber so that protractor can find out which
64
71
// steps passed/failed
65
72
var addResultListener = function ( formatter ) {
73
+ var originalHandleAfterScenarioEvent = formatter . handleAfterScenarioEvent ;
74
+ formatter . handleAfterScenarioEvent = function ( event , callback ) {
75
+ var scenario = event . getPayloadItem ( 'scenario' ) ;
76
+ stepResults . description = scenario . getName ( ) ;
77
+ if ( scenarioFailed ) {
78
+ ++ failedCount ;
79
+ runner . emit ( 'testFail' ) ;
80
+ } else {
81
+ runner . emit ( 'testPass' ) ;
82
+ }
83
+
84
+ testResult . push ( stepResults ) ;
85
+ stepResults = {
86
+ description : null ,
87
+ assertions : [ ] ,
88
+ duration : 0
89
+ } ;
90
+ scenarioFailed = false ;
91
+
92
+ if ( originalHandleAfterScenarioEvent
93
+ && typeof ( originalHandleAfterScenarioEvent ) === 'function' ) {
94
+ originalHandleAfterScenarioEvent ( event , callback ) ;
95
+ } else {
96
+ callback ( ) ;
97
+ }
98
+ } ;
99
+
66
100
var originalHandleStepResultEvent = formatter . handleStepResultEvent ;
67
101
formatter . handleStepResultEvent = function ( event , callback ) {
68
-
69
102
var stepResult = event . getPayloadItem ( 'stepResult' ) ;
70
103
if ( stepResult . isSuccessful ( ) ) {
71
- runner . emit ( 'testPass' ) ;
72
- testResult . push ( {
73
- description : stepResult . getStep ( ) . getName ( ) ,
74
- assertions : [ {
75
- passed : true
76
- } ] ,
77
- duration : stepResult . getDuration ( )
104
+ stepResults . assertions . push ( {
105
+ passed : true
78
106
} ) ;
79
- }
80
- else if ( stepResult . isFailed ( ) ) {
81
- runner . emit ( 'testFail' ) ;
82
- ++ failedCount ;
107
+ stepResults . duration += stepResult . getDuration ( ) ;
108
+ } else if ( stepResult . isFailed ( ) ) {
109
+ scenarioFailed = true ;
83
110
var failureMessage = stepResult . getFailureException ( ) ;
84
- testResult . push ( {
85
- description : stepResult . getStep ( ) . getName ( ) ,
86
- assertions : [ {
87
- passed : false ,
88
- errorMsg : failureMessage . message ,
89
- stackTrace : failureMessage . stack
90
- } ] ,
91
- duration : stepResult . getDuration ( )
111
+ stepResults . assertions . push ( {
112
+ passed : false ,
113
+ errorMsg : failureMessage . message ,
114
+ stackTrace : failureMessage . stack
92
115
} ) ;
116
+ stepResults . duration += stepResult . getDuration ( ) ;
93
117
}
94
118
95
119
if ( originalHandleStepResultEvent
0 commit comments