diff --git a/plugins/trx-plugin/src/main/java/io/qameta/allure/trx/TrxPlugin.java b/plugins/trx-plugin/src/main/java/io/qameta/allure/trx/TrxPlugin.java index 3b2959300..ca54d9b11 100644 --- a/plugins/trx-plugin/src/main/java/io/qameta/allure/trx/TrxPlugin.java +++ b/plugins/trx-plugin/src/main/java/io/qameta/allure/trx/TrxPlugin.java @@ -4,7 +4,9 @@ import io.qameta.allure.context.RandomUidContext; import io.qameta.allure.core.Configuration; import io.qameta.allure.core.ResultsVisitor; +import io.qameta.allure.entity.StageResult; import io.qameta.allure.entity.Status; +import io.qameta.allure.entity.Step; import io.qameta.allure.entity.TestResult; import io.qameta.allure.entity.Time; import io.qameta.allure.parser.XmlElement; @@ -24,11 +26,13 @@ import java.time.ZonedDateTime; import java.time.chrono.ChronoZonedDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import static io.qameta.allure.entity.LabelName.RESULT_FORMAT; import static java.nio.file.Files.newDirectoryStream; @@ -65,6 +69,7 @@ public class TrxPlugin implements Reader { public static final String MESSAGE_ELEMENT_NAME = "Message"; public static final String STACK_TRACE_ELEMENT_NAME = "StackTrace"; public static final String ERROR_INFO_ELEMENT_NAME = "ErrorInfo"; + public static final String STDOUT_ELEMENT_NAME = "StdOut"; @Override public void readResults(final Configuration configuration, @@ -161,6 +166,16 @@ protected void parseUnitTestResult(final XmlElement unitTestResult, .setTime(getTime(startTime, endTime)); getStatusMessage(unitTestResult).ifPresent(result::setStatusMessage); getStatusTrace(unitTestResult).ifPresent(result::setStatusTrace); + getLogMessage(unitTestResult).ifPresent(logMessage -> { + final List lines = splitLines(logMessage); + final List steps = lines + .stream() + .map(line -> new Step().setName(line)) + .collect(Collectors.toList()); + final StageResult stageResult = new StageResult() + .setSteps(steps); + result.setTestStage(stageResult); + }); Optional.ofNullable(tests.get(executionId)).ifPresent(unitTest -> { result.setParameters(unitTest.getParameters()); result.setDescription(unitTest.getDescription()); @@ -170,6 +185,16 @@ protected void parseUnitTestResult(final XmlElement unitTestResult, visitor.visitTestResult(result); } + private List splitLines(final String str) { + return Arrays.asList(str.split("\\r?\\n")); + } + + private Optional getLogMessage(final XmlElement unitTestResult) { + return unitTestResult.getFirst(OUTPUT_ELEMENT_NAME) + .flatMap(output -> output.getFirst(STDOUT_ELEMENT_NAME)) + .map(XmlElement::getValue); + } + private Optional getStatusMessage(final XmlElement unitTestResult) { return unitTestResult.getFirst(OUTPUT_ELEMENT_NAME) .flatMap(output -> output.getFirst(ERROR_INFO_ELEMENT_NAME)) diff --git a/plugins/trx-plugin/src/test/java/io/qameta/allure/trx/TrxPluginTest.java b/plugins/trx-plugin/src/test/java/io/qameta/allure/trx/TrxPluginTest.java index 861a62368..84b5365a5 100644 --- a/plugins/trx-plugin/src/test/java/io/qameta/allure/trx/TrxPluginTest.java +++ b/plugins/trx-plugin/src/test/java/io/qameta/allure/trx/TrxPluginTest.java @@ -90,6 +90,24 @@ public void shouldParseErrorInfo() throws Exception { .containsExactly(tuple("Some message", "Some trace")); } + @Test + public void shouldParseStdOutOnFail() throws Exception { + process( + "trxdata/sample.trx", + "sample.trx" + ); + + final ArgumentCaptor captor = ArgumentCaptor.forClass(TestResult.class); + verify(visitor, times(4)).visitTestResult(captor.capture()); + + assertThat(captor.getAllValues()) + .filteredOn(result -> result.getStatus() == Status.FAILED) + .filteredOn(result -> result.getTestStage().getSteps().size() == 10) + .filteredOn(result -> result.getTestStage().getSteps().get(1).getName().contains("Given I have entered 50 into the calculator")) + .filteredOn(result -> result.getTestStage().getSteps().get(3).getName().contains("And I have entered -1 into the calculator")) + .hasSize(1); + } + private void process(String... strings) throws IOException { Path resultsDirectory = folder.newFolder().toPath(); Iterator iterator = Arrays.asList(strings).iterator();