@@ -51,11 +51,6 @@ public abstract class AbstractReporter implements Formatter, Reporter {
5151 protected static final String COLON_INFIX = ": " ;
5252 private static final String SKIPPED_ISSUE_KEY = "skippedIssue" ;
5353
54- protected String stepPrefix ;
55-
56- protected Queue <String > outlineIterations ;
57- private Boolean inBackground ;
58-
5954 protected final ThreadLocal <String > currentFeatureUri = new ThreadLocal <>();
6055 protected final ThreadLocal <RunningContext .FeatureContext > currentFeatureContext = new ThreadLocal <>();
6156 protected final ThreadLocal <RunningContext .ScenarioContext > currentScenarioContext = new ThreadLocal <>();
@@ -98,12 +93,6 @@ public Launch get() {
9893 }
9994 });
10095
101- protected AbstractReporter () {
102- outlineIterations = new ArrayDeque <>();
103- stepPrefix = "" ;
104- inBackground = false ;
105- }
106-
10796 /**
10897 * Extension point to customize ReportPortal instance
10998 *
@@ -152,6 +141,15 @@ protected void afterFeature() {
152141 }
153142 }
154143
144+ protected RunningContext .ScenarioContext getCurrentScenarioContext () {
145+ RunningContext .ScenarioContext context = currentScenarioContext .get ();
146+ if (context == null ) {
147+ context = new RunningContext .ScenarioContext ();
148+ currentScenarioContext .set (context );
149+ }
150+ return context ;
151+ }
152+
155153 /**
156154 * Start Cucumber Feature (if not started) and Scenario
157155 *
@@ -179,27 +177,30 @@ protected void beforeScenario(Scenario scenario, String outlineIteration) {
179177 Maybe <String > id = Utils .startNonLeafNode (
180178 launch .get (),
181179 currentFeature .getId (),
182- Utils .buildStatementName (scenario , null , AbstractReporter . COLON_INFIX , outlineIteration ),
180+ Utils .buildStatementName (scenario , null , outlineIteration ),
183181 currentFeatureUri .get (),
184182 codeRef ,
185183 scenario .getTags (),
186184 getScenarioTestItemType ()
187185 );
188- currentScenarioContext .set (new RunningContext .ScenarioContext (id ));
186+ RunningContext .ScenarioContext context = getCurrentScenarioContext ();
187+ context .setId (id );
189188 }
190189
191190 /**
192191 * Finish Cucumber scenario
193192 */
194193 protected void afterScenario () {
195- RunningContext .ScenarioContext context = currentScenarioContext . get ();
194+ RunningContext .ScenarioContext context = getCurrentScenarioContext ();
196195 Utils .finishTestItem (launch .get (), context .getId (), context .getStatus ());
196+ currentScenarioContext .set (null );
197197 }
198198
199199 /**
200200 * Start Cucumber step
201201 *
202- * @param step Step object
202+ * @param step Step object
203+ * @param match Match object
203204 */
204205 protected abstract void beforeStep (Step step , Match match );
205206
@@ -250,10 +251,8 @@ protected void reportResult(Result result, String message) {
250251 if (message != null ) {
251252 Utils .sendLog (message , level , null );
252253 }
253- RunningContext .ScenarioContext currentScenario = currentScenarioContext .get ();
254- if (currentScenario != null ) {
255- currentScenario .updateStatus (Utils .mapStatus (result .getStatus ()));
256- }
254+ RunningContext .ScenarioContext currentScenario = getCurrentScenarioContext ();
255+ currentScenario .updateStatus (Utils .mapStatus (result .getStatus ()));
257256 }
258257
259258 /**
@@ -281,7 +280,8 @@ public void before(Match match, Result result) {
281280 @ Override
282281 public void result (Result result ) {
283282 afterStep (result );
284- if (!inBackground && currentScenarioContext .get ().noMoreSteps ()) {
283+ RunningContext .ScenarioContext context = getCurrentScenarioContext ();
284+ if (!context .isInBackground () && context .noMoreSteps ()) {
285285 beforeHooks (false );
286286 }
287287 }
@@ -293,7 +293,7 @@ public void after(Match match, Result result) {
293293
294294 @ Override
295295 public void match (Match match ) {
296- beforeStep (currentScenarioContext . get ().getNextStep (), match );
296+ beforeStep (getCurrentScenarioContext ().getNextStep (), match );
297297 }
298298
299299 @ Override
@@ -334,40 +334,46 @@ public void scenarioOutline(ScenarioOutline scenarioOutline) {
334334 @ Override
335335 public void examples (Examples examples ) {
336336 // examples always have headers; therefore up to num - 1
337- IntStream .range (1 , examples .getRows ().size ()).forEach (it -> outlineIterations .add (String .format ("[%d]" , it )));
337+ RunningContext .ScenarioContext context = getCurrentScenarioContext ();
338+ Queue <String > iterations = context .getOutlineIterations ();
339+ IntStream .range (1 , examples .getRows ().size ()).forEach (it -> iterations .add (String .format ("[%d]" , it )));
338340 }
339341
340342 @ Override
341343 public void startOfScenarioLifeCycle (Scenario scenario ) {
342- inBackground = false ;
343- beforeScenario (scenario , outlineIterations .poll ());
344+ RunningContext .ScenarioContext context = getCurrentScenarioContext ();
345+ String iteration = context .getOutlineIterations ().poll ();
346+ context .setInBackground (false );
347+ beforeScenario (scenario , iteration );
344348 beforeHooks (true );
345349 }
346350
347351 @ Override
348352 public void background (Background background ) {
349353 afterHooks (true );
350- inBackground = true ;
351- stepPrefix = background .getKeyword ().toUpperCase () + AbstractReporter .COLON_INFIX ;
354+ RunningContext .ScenarioContext context = getCurrentScenarioContext ();
355+ context .setInBackground (true );
356+ context .setStepPrefix (background .getKeyword ().toUpperCase () + AbstractReporter .COLON_INFIX );
352357 }
353358
354359 @ Override
355360 public void scenario (Scenario scenario ) {
356- if (!inBackground ) { // if there was no background
361+ RunningContext .ScenarioContext context = getCurrentScenarioContext ();
362+ if (!context .isInBackground ()) { // if there was no background
357363 afterHooks (true );
358364 } else {
359- inBackground = false ;
365+ context . setInBackground ( false ) ;
360366 }
361- stepPrefix = "" ;
367+ context . setStepPrefix ( "" ) ;
362368 }
363369
364370 @ Override
365371 public void step (Step step ) {
366- RunningContext .ScenarioContext currentScenario = currentScenarioContext .get ();
367- if (currentScenario != null ) {
368- currentScenario .addStep (step );
372+ RunningContext .ScenarioContext context = currentScenarioContext .get ();
373+ if (context != null ) {
374+ // Skip scenario outlines steps without initialized parameters
375+ context .addStep (step );
369376 }
370- // otherwise it's a step collection in an outline, useless.
371377 }
372378
373379 @ Override
0 commit comments