Skip to content

Commit

Permalink
introduce "isInDataDrivenTest" flag for stepFailed methods of StepLis…
Browse files Browse the repository at this point in the history
…tener of StepListener (#3358)
  • Loading branch information
cliviu authored Dec 15, 2023
1 parent fb0e27d commit 0c443b8
Show file tree
Hide file tree
Showing 17 changed files with 246 additions and 1,155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,7 @@ public void stepFailed(StepFailure failure) {
currentStepDone(failureAnalysis.resultFor(failure));
}


public void stepFailed(StepFailure failure, List<ScreenshotAndHtmlSource> screenshotList) {
public void stepFailed(StepFailure failure, List<ScreenshotAndHtmlSource> screenshotList, boolean isInDataDrivenTest) {

if (!aStepHasFailed()) {
// This is the actual failure, so record all the details
Expand All @@ -925,10 +924,15 @@ public void stepFailed(StepFailure failure, List<ScreenshotAndHtmlSource> screen
getCurrentTestOutcome().appendTestFailure(failureCause);

recordFailureDetails(failure);
// Step marked as done with the appropriate result before
if (isInDataDrivenTest) {
currentStepDone(failureAnalysis.resultFor(failure));
}
}
if (!isInDataDrivenTest) {
// Step marked as done with the appropriate result before
currentStepDone(failureAnalysis.resultFor(failure));
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,14 @@ public void stepFailed(final StepFailure failure) {
stepFailed = true;
}

public void stepFailed(final StepFailure failure, List<ScreenshotAndHtmlSource> screenshotList) {

public void stepFailed(final StepFailure failure, List<ScreenshotAndHtmlSource> screenshotList, boolean isInDataDrivenTest) {

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

for (StepListener stepListener : getAllListeners()) {
stepListener.stepFailed(failure,screenshotList);
stepListener.stepFailed(failure,screenshotList,isInDataDrivenTest);
}
stepFailed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ private void notifyOfStepFailure(final Object object, final Method method, final

if (TestSession.isSessionStarted()) {
List<ScreenshotAndHtmlSource> screenshotList = TestSession.getTestSessionContext().getStepEventBus().takeScreenshots(TestResult.FAILURE);
StepFailedEvent stepFailedEvent = new StepFailedEvent(failure,screenshotList);
StepFailedEvent stepFailedEvent = new StepFailedEvent(failure,screenshotList,TestSession.getTestSessionContext().isInDataDrivenTest());
TestSession.addEvent(stepFailedEvent);
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.thucydides.core.steps.events;

import net.thucydides.core.steps.session.TestSession;
import net.thucydides.model.screenshots.ScreenshotAndHtmlSource;
import net.thucydides.model.steps.StepFailure;
import org.slf4j.Logger;
Expand All @@ -16,18 +17,28 @@ public class StepFailedEvent

private final List<ScreenshotAndHtmlSource> screenshotList;

private boolean isInDataDrivenTest;

public StepFailedEvent(StepFailure stepFailure, List<ScreenshotAndHtmlSource> screenshotList) {
this.stepFailure = stepFailure;
this.screenshotList = screenshotList;
if (TestSession.isSessionStarted()) {
this.isInDataDrivenTest = TestSession.getTestSessionContext().isInDataDrivenTest();
}
}

public StepFailedEvent(StepFailure stepFailure, List<ScreenshotAndHtmlSource> screenshotList, boolean isInDataDrivenTest) {
this.stepFailure = stepFailure;
this.screenshotList = screenshotList;
this.isInDataDrivenTest = isInDataDrivenTest;
}


@Override
public void play() {
LOGGER.debug("SRP:PlayStepFinishedEvent with screenshot size "
+ ((screenshotList != null) ? screenshotList.size() : 0));
getStepEventBus().stepFailed(stepFailure, screenshotList);
getStepEventBus().stepFailed(stepFailure, screenshotList, isInDataDrivenTest);
}

public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ public class TestSessionContext {

private String currentTestName;

private boolean isInDataDrivenTest = false;

private AtomicBoolean sessionStarted = new AtomicBoolean(false);
private final AtomicBoolean sessionStarted = new AtomicBoolean(false);

private List<StepEventBusEvent> stepEventBusEvents = Collections.synchronizedList(new LinkedList<>());
private final List<StepEventBusEvent> stepEventBusEvents = Collections.synchronizedList(new LinkedList<>());

public AtomicBoolean getSessionStarted() {
return sessionStarted;
Expand Down Expand Up @@ -90,4 +91,12 @@ public WebDriver getWebDriver() {
public void setWebDriver(WebDriver webDriver) {
this.webDriver = webDriver;
}

public boolean isInDataDrivenTest() {
return isInDataDrivenTest;
}

public void setInDataDrivenTest(boolean inDataDrivenTest) {
isInDataDrivenTest = inDataDrivenTest;
}
}
Original file line number Diff line number Diff line change
@@ -1,129 +1,12 @@
package net.thucydides.core;

import net.thucydides.model.domain.DataTable;
import net.thucydides.model.domain.Story;
import net.thucydides.model.domain.TestOutcome;
import net.thucydides.model.domain.TestResult;
import net.thucydides.model.screenshots.ScreenshotAndHtmlSource;
import net.thucydides.model.steps.ExecutedStepDescription;
import net.thucydides.model.steps.StepFailure;
import net.thucydides.model.steps.StepListener;
import net.thucydides.model.steps.StepListenerAdapter;
import org.openqa.selenium.WebDriver;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;

public class ListenerInWrongPackage implements StepListener {
public void testSuiteStarted(Class<?> storyClass) {

}

public void testSuiteStarted(Story story) {

}

public void testSuiteFinished() {
}

public void testStarted(String description) {

}

@Override
public void testStarted(String description, String id) {

}

@Override
public void testStarted(String description, String id, ZonedDateTime startTime) {

}

public void testFinished(TestOutcome result) {

}

@Override
public void testFinished(TestOutcome result, boolean isInDataDrivenTest, ZonedDateTime finishTime) {

}

public void testRetried() {
}

public void stepStarted(ExecutedStepDescription description) {

}

public void skippedStepStarted(ExecutedStepDescription description) {
}

public void stepFailed(StepFailure failure) {

}

@Override
public void stepFailed(StepFailure failure, List<ScreenshotAndHtmlSource> screenshotList) {

}

public void lastStepFailed(StepFailure failure) {
}

public void stepIgnored() {

}

public void stepIgnored(String message) {
}

public void stepPending() {

}

public void stepPending(String message) {
}

public void stepFinished() {

}

@Override
public void stepFinished(List<ScreenshotAndHtmlSource> screenshotList) {

}

@Override
public void stepFinished(List<ScreenshotAndHtmlSource> screenshotList, ZonedDateTime time) {

}

public void testFailed(TestOutcome testOutcome, Throwable cause) {
}

public void testIgnored() {
}

@Override
public void testSkipped() {

}

@Override
public void testAborted() {

}

@Override
public void testPending() {

}

@Override
public void testIsManual() {

}
public class ListenerInWrongPackage extends StepListenerAdapter {

public List<TestOutcome> getTestOutcomes() {
return null;
Expand All @@ -132,44 +15,4 @@ public List<TestOutcome> getTestOutcomes() {
public WebDriver getDriver() {
return null;
}

public void notifyScreenChange() {
}

public void useExamplesFrom(DataTable table) {
//To change body of implemented methods use File | Settings | File Templates.
}

@Override
public void addNewExamplesFrom(DataTable table) {

}

public void exampleStarted(Map<String,String> data) {
//To change body of implemented methods use File | Settings | File Templates.
}

public void exampleFinished() {
//To change body of implemented methods use File | Settings | File Templates.
}

@Override
public void assumptionViolated(String message) {
//To change body of implemented methods use File | Settings | File Templates.
}

@Override
public void testRunFinished() {

}

@Override
public void takeScreenshots(List<ScreenshotAndHtmlSource> screenshots) {

}

@Override
public void takeScreenshots(TestResult testResult, List<ScreenshotAndHtmlSource> screenshots) {

}
}
Loading

0 comments on commit 0c443b8

Please sign in to comment.