Skip to content

Commit

Permalink
Revert "make failed step behavior consistent even if exception is cau…
Browse files Browse the repository at this point in the history
…ght and …" (#3602)

This reverts commit 699abc9.
  • Loading branch information
wakaleo authored Jan 21, 2025
1 parent 699abc9 commit c310c02
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.serenitybdd.annotations.TestAnnotations;
import net.thucydides.core.junit.SerenityJUnitTestCase;
import net.thucydides.model.domain.*;
import net.thucydides.model.domain.failures.FailureAnalysis;
import net.thucydides.model.domain.stacktrace.FailureCause;
import net.thucydides.model.screenshots.ScreenshotAndHtmlSource;
import net.thucydides.core.steps.session.TestSession;
Expand Down Expand Up @@ -904,6 +905,8 @@ private void markCurrentStepAs(final TestResult result) {
);
}

FailureAnalysis failureAnalysis = new FailureAnalysis();

public void stepFailed(StepFailure failure) {

if (!aStepHasFailed() || StepEventBus.getEventBus().softAssertsActive()) {
Expand All @@ -915,6 +918,9 @@ public void stepFailed(StepFailure failure) {

recordFailureDetails(failure);
}

// In all cases, mark the step as done with the appropriate result
currentStepDone(failureAnalysis.resultFor(failure));
}

public void stepFailed(StepFailure failure,
Expand All @@ -931,6 +937,8 @@ public void stepFailed(StepFailure failure,

recordFailureDetails(failure);
}
// Step marked as done with the appropriate result before
currentStepDone(failureAnalysis.resultFor(failure), timestamp);
}


Expand All @@ -943,7 +951,8 @@ public void stepFailedWithException(Throwable failure) {

recordFailureDetails(failure);
}
}
currentStepDone(failureAnalysis.resultFor(failure));
}

public void lastStepFailed(StepFailure failure) {
takeEndOfStepScreenshotFor(FAILURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ private void stepDone() {

public void stepFailed(final StepFailure failure) {

stepDone();
getResultTally().logFailure(failure);

for (StepListener stepListener : getAllListeners()) {
Expand All @@ -627,6 +628,7 @@ public void stepFailed(final StepFailure failure,
boolean isInDataDrivenTest,
ZonedDateTime timestamp) {

stepDone();
getResultTally().logFailure(failure);

for (StepListener stepListener : getAllListeners()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,8 @@ private void logStepFailure(Object object, Method method, Object[] args, Throwab
if (StepEventBus.getEventBus().aStepInTheCurrentTestHasFailed() && !StepEventBus.getEventBus().softAssertsActive()) {
return;
}
try {
LOGGER.debug("STEP FAILED: {} - {}", StepName.fromStepAnnotationIn(method).orElse(method.getName()), assertionError.getMessage());
notifyOfStepFailure(object, method, args, assertionError);
} finally {
notifyStepFinishedFor(method, args);
}
notifyOfStepFailure(object, method, args, assertionError);
LOGGER.debug("STEP FAILED: {} - {}", StepName.fromStepAnnotationIn(method).orElse(method.getName()), assertionError.getMessage());
}

private Object executeTestStepMethod(Object obj, Method method, Object[] args, Method zuperMethod, Object result) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ public void addHighPriorityStepEventBusEvent(String scenarioId, StepEventBusEven

public void addStepEventBusEvent(StepEventBusEvent event) {
if (TestSession.isSessionStarted()) {
if (event instanceof StepFinishedWithResultEvent) {
if (Status.FAILED.equals(((StepFinishedWithResultEvent) event).getResult().getStatus()) && TestSession.currentStepHasFailed()) {
LOGGER.debug("SRP:ignored event " + event + " " + Thread.currentThread() + " because current Step has already failed");
return;
}
}
TestSession.addEvent(event);
event.setStepEventBus(stepEventBus);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private void failed(String stepTitle, Throwable cause, List<ScreenshotAndHtmlSou
getStepEventBus().stepFailed(stepFailure, screenshots, isInDataDrivenTest);
}
}
this.getStepEventBus().stepFinished(this.screenshotList, this.getTimestamp());
}

private void skipped(String stepTitle, Throwable cause) {
Expand Down

0 comments on commit c310c02

Please sign in to comment.