Skip to content

Commit

Permalink
Possible fix for #3393
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Feb 4, 2024
1 parent a5a6214 commit 05ce9e4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.thucydides.core.steps.session.TestSession;
import net.thucydides.model.ThucydidesSystemProperty;
import net.thucydides.model.adapters.TestFramework;
import net.thucydides.model.domain.TestResult;
import net.thucydides.model.domain.stacktrace.StackTraceSanitizer;
import net.thucydides.model.screenshots.ScreenshotAndHtmlSource;
import net.thucydides.model.steps.AnnotatedStepDescription;
Expand Down Expand Up @@ -612,6 +613,9 @@ private void notifyOfStepFailure(final Object object, final Method method, final
if (!TestSession.isSessionStarted()) {
//no step failure for the parallel runner, rely only on Cucumber events
StepEventBus.getParallelEventBus().stepFailed(failure);
} else {
List<ScreenshotAndHtmlSource> screenshotList = TestSession.getTestSessionContext().getStepEventBus().takeScreenshots(TestResult.FAILURE);
TestSession.addEvent(new StepFailedEvent(failure,screenshotList));
}
if (shouldThrowExceptionImmediately()) {
finishAnyCucumberSteps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.cucumber.messages.types.Tag;
import net.thucydides.core.steps.StepEventBus;
import net.thucydides.core.steps.events.StepEventBusEvent;
import net.thucydides.core.steps.events.StepFailedEvent;
import net.thucydides.core.steps.events.StepStartedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -51,6 +53,19 @@ public static void addEvent(StepEventBusEvent event) {
sessionContext.get().addStepBusEvent(event);
}

public static boolean currentStepHasFailed() {
List<StepEventBusEvent> events = sessionContext.get().getStepEventBusEvents();
for (int i = events.size() - 1; i >= 0; i--) {
if (events.get(i) instanceof StepStartedEvent) {
break;
}
if (events.get(i) instanceof StepFailedEvent) {
return true;
}
}
return false;
}

public static List<StepEventBusEvent> getSessionEvents() {
return sessionContext.get().getStepEventBusEvents();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class StackTraceSanitizer {
"net.serenitybdd.cucumber",
"net.serenitybdd.jbehave",
"net.serenitybdd.screenplay",
"net.thucydides.core",
"net.thucydides.model",
"net.thucydides.junit",
"net.thucydides.plugins",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public void reportStepFailureFor(Performable todo, Throwable e) {
if (!TestSession.isSessionStarted()) {
StepEventBus.getParallelEventBus().stepFailed(new StepFailure(taskDescription, e));
} else {
List<ScreenshotAndHtmlSource> screenshotList = TestSession.getTestSessionContext().getStepEventBus().takeScreenshots(TestResult.FAILURE);
TestSession.addEvent(new StepFailedEvent(new StepFailure(taskDescription, e),screenshotList));
if (!TestSession.currentStepHasFailed()) {
List<ScreenshotAndHtmlSource> screenshotList = TestSession.getTestSessionContext().getStepEventBus().takeScreenshots(TestResult.FAILURE);
TestSession.addEvent(new StepFailedEvent(new StepFailure(taskDescription, e), screenshotList));
}
}
}

Expand All @@ -47,8 +49,10 @@ public <T> void reportStepFailureFor(Consequence<T> consequence, Throwable e) {
if (!TestSession.isSessionStarted()) {
StepEventBus.getParallelEventBus().stepFailed(new StepFailure(consequenceDescription, e));
} else {
List<ScreenshotAndHtmlSource> screenshotList = TestSession.getTestSessionContext().getStepEventBus().takeScreenshots(TestResult.FAILURE);
TestSession.addEvent(new StepFailedEvent(new StepFailure(consequenceDescription, e ), screenshotList));
if (!TestSession.currentStepHasFailed()) {
List<ScreenshotAndHtmlSource> screenshotList = TestSession.getTestSessionContext().getStepEventBus().takeScreenshots(TestResult.FAILURE);
TestSession.addEvent(new StepFailedEvent(new StepFailure(consequenceDescription, e), screenshotList));
}
}
}

Expand Down

0 comments on commit 05ce9e4

Please sign in to comment.