Skip to content

Commit

Permalink
Fixed top-level soft assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Jan 28, 2024
1 parent 5252916 commit 945a15b
Show file tree
Hide file tree
Showing 61 changed files with 836 additions and 499 deletions.
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
<gson.version>2.10.1</gson.version>
<junit5.version>5.10.0</junit5.version>
<mockito.version>3.3.3</mockito.version>
<assertj.version>3.24.2</assertj.version>
<assertj.version>3.25.0</assertj.version>
<opentest.version>1.3.0</opentest.version>
<commons.lang.version>3.14.0</commons.lang.version>
<commons.lang2.version>2.6</commons.lang2.version>
<commons.io.version>2.15.1</commons.io.version>
Expand Down Expand Up @@ -151,6 +152,7 @@
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
Expand Down Expand Up @@ -448,6 +450,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>
Expand Down
1 change: 0 additions & 1 deletion serenity-ant-task/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion serenity-appium-screenplay-poc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
<version>3.8.0</version>
<version>${assertj.version}</version>
</dependency>
</dependencies>
<build>
Expand Down
3 changes: 2 additions & 1 deletion serenity-appium/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.7.0</version>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
5 changes: 5 additions & 0 deletions serenity-bitbar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2 changes: 1 addition & 1 deletion serenity-browsermob-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>org.opentest4j</groupId>
<artifactId>opentest4j</artifactId>
<version>1.2.0</version>
<version>${opentest.version}</version>
</dependency>

<!-- TEST DEPENDENCIES -->
Expand Down
5 changes: 5 additions & 0 deletions serenity-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,9 @@ public StepMutator updateCurrentStepTitle(String updatedStepTitle) {
}

public void updateCurrentStepFailureCause(Throwable failure) {
// if (currentStepExists()) {
// getCurrentStep().failedWith(failure);
// } else {
this.currentTestOutcome.lastStepFailedWith(failure);
// }
if (this.currentTestOutcome != null) {
this.currentTestOutcome.lastStepFailedWith(failure);
}
}

public class StepMutator {
Expand Down Expand Up @@ -1174,7 +1172,7 @@ private void removeFirstScreenshotOfCurrentStep() {
}

private void removeScreenshot(ScreenshotAndHtmlSource screenshot) {
if(screenshot.getScreenshot().delete() && currentStep().isPresent()) {
if (screenshot.getScreenshot().delete() && currentStep().isPresent()) {
getCurrentStep().getScreenshots().remove(screenshot);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*
* @author johnsmart
*/
public class StepInterceptor implements MethodErrorReporter,Interceptor {
public class StepInterceptor implements MethodErrorReporter, Interceptor {

private final Class<?> testStepClass;
private Throwable error = null;
Expand All @@ -69,6 +69,7 @@ public static void resetExpectedExceptionType() {
private final List<StepInterceptionListener> listeners = new ArrayList<>();

CleanupMethodLocator cleanupMethodLocator;

StepInterceptor(final Class<?> testStepClass) {
this.testStepClass = testStepClass;
this.environmentVariables = ConfiguredEnvironment.getEnvironmentVariables();
Expand Down Expand Up @@ -114,13 +115,17 @@ private boolean baseClassMethod(final Method method, Object obj) {
}

private boolean isSilent(Class callingClass, Method method, Object obj) {
if (IsSilent.class.isAssignableFrom(callingClass)) { return true; }
if (IsSilent.class.isAssignableFrom(callingClass)) {
return true;
}

if ((CanBeSilent.class.isAssignableFrom(callingClass) && method.getName().equals("isSilent"))) {
return true;
}

if (CanBeSilent.class.isAssignableFrom(callingClass) && ((CanBeSilent) obj).isSilent()) { return true; }
if (CanBeSilent.class.isAssignableFrom(callingClass) && ((CanBeSilent) obj).isSilent()) {
return true;
}

if (isNestedInSilentTask()) {
return true;
Expand Down Expand Up @@ -517,21 +522,29 @@ private Object invokeMethod(final Object obj, final Object[] args, final Method
try {
return zuperMethod.invoke(obj, args);
} catch (InvocationTargetException invocationTargetException) {
throw invocationTargetException.getCause();
if (isAnAssertionError(invocationTargetException) && StepEventBus.getEventBus().softAssertsActive()) {
return null;
} else {
throw invocationTargetException.getCause();
}
}
}

private boolean isAnAssertionError(InvocationTargetException invocationTargetException) {
return (invocationTargetException.getTargetException() instanceof AssertionError)
|| (invocationTargetException.getCause() instanceof AssertionError);
}

private boolean isPending(final Method method) {
return (method.getAnnotation(Pending.class) != null);
}

private void notifyStepFinishedFor(final Method method, final Object[] args) {
if (TestSession.isSessionStarted()) {
LOGGER.debug("SRP:Actor finished step in session " + Thread.currentThread());
LOGGER.debug("SRP:Actor finished step in session " + Thread.currentThread());
List<ScreenshotAndHtmlSource> screenshotList = TestSession.getTestSessionContext().getStepEventBus().takeScreenshots();
TestSession.addEvent(new StepFinishedEvent(screenshotList));
}
else {
} else {
StepEventBus.getParallelEventBus().stepFinished();
}
}
Expand All @@ -540,41 +553,37 @@ private void notifySkippedStepFinishedFor(final Method method, final Object[] ar
if (TestSession.isSessionStarted()) {
StepIgnoredEvent stepIgnoredEvent = new StepIgnoredEvent();
TestSession.addEvent(stepIgnoredEvent);
}
else {
} else {
StepEventBus.getParallelEventBus().stepIgnored();
}
}

private void notifyStepPending(String message) {
if (TestSession.isSessionStarted()) {
TestSession.addEvent(new StepPendingEvent(message));
}
else {
} else {
StepEventBus.getParallelEventBus().stepPending(message);
}
}

private void notifyAssumptionViolated(String message) {
if (TestSession.isSessionStarted()) {
TestSession.addEvent(new AssumptionViolatedEvent(message));
}
else {
} else {
StepEventBus.getParallelEventBus().assumptionViolated(message);
}
}

private void notifyStepIgnored() {
if (TestSession.isSessionStarted()) {
TestSession.addEvent(new StepIgnoredEvent());
}
else {
} else {
StepEventBus.getParallelEventBus().stepIgnored();
}
}

private String getTestNameFrom(final Method method, final Object[] args) {
return StepNamer.nameFor(method,args);
return StepNamer.nameFor(method, args);
}

private void notifyStepSkippedFor(final Method method, final Object[] args) {
Expand Down Expand Up @@ -613,10 +622,9 @@ private void notifyOfStepFailure(final Object object, final Method method, final
private void finishAnyCucumberSteps() {
if (TestSession.isSessionStarted()) {
WrapupCurrentCucumberStepEvent wrapupCurrentCucumberStepEvent = new WrapupCurrentCucumberStepEvent();
LOGGER.debug("SRP:Actor started event in session " + wrapupCurrentCucumberStepEvent + " " + Thread.currentThread());
LOGGER.debug("SRP:Actor started event in session " + wrapupCurrentCucumberStepEvent + " " + Thread.currentThread());
TestSession.addEvent(wrapupCurrentCucumberStepEvent);
}
else {
} else {
StepEventBus.getParallelEventBus().wrapUpCurrentCucumberStep();
}
}
Expand All @@ -628,12 +636,11 @@ private boolean shouldThrowExceptionImmediately() {
private void notifyStepStarted(final Object object, final Method method, final Object[] args) {
ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args), args)
.withDisplayedFields(fieldValuesIn(object));
if(TestSession.isSessionStarted()) {
if (TestSession.isSessionStarted()) {
StepStartedEvent stepStartedEvent = new StepStartedEvent(description);
LOGGER.debug("SRP:Actor started step in session " + stepStartedEvent + " " + Thread.currentThread());
LOGGER.debug("SRP:Actor started step in session " + stepStartedEvent + " " + Thread.currentThread());
TestSession.addEvent(stepStartedEvent);
}
else {
} else {
StepEventBus.getParallelEventBus().stepStarted(description);
}
}
Expand Down Expand Up @@ -670,11 +677,11 @@ private String shortenedClassName(String className) {
String[] classNameElements = StringUtils.split(className, ".");
return classNameElements[classNameElements.length - 1];
}

private StepEventBus getStepEventBus() {
if (TestSession.isSessionStarted()) {
return TestSession.getTestSessionContext().getStepEventBus();
}
else {
} else {
return StepEventBus.getParallelEventBus();
}
}
Expand Down
5 changes: 5 additions & 0 deletions serenity-crossbrowsertesting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
<artifactId>junit</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2 changes: 1 addition & 1 deletion serenity-cucumber-smoke-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.23.1</version>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion serenity-cucumber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
Expand Down
1 change: 1 addition & 0 deletions serenity-ensure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
</dependencies>

Expand Down
Loading

0 comments on commit 945a15b

Please sign in to comment.