From f350f19da46f8575785bd2234a2d40d4599d8890 Mon Sep 17 00:00:00 2001 From: PHe Date: Mon, 8 Oct 2018 16:43:42 +0200 Subject: [PATCH 1/4] fix trx logger parses stdout on fail --- .../java/io/qameta/allure/trx/TrxPlugin.java | 12 ++++++++++++ .../io/qameta/allure/trx/TrxPluginTest.java | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) 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..83c612dce 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 @@ -65,6 +65,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 +162,11 @@ protected void parseUnitTestResult(final XmlElement unitTestResult, .setTime(getTime(startTime, endTime)); getStatusMessage(unitTestResult).ifPresent(result::setStatusMessage); getStatusTrace(unitTestResult).ifPresent(result::setStatusTrace); + if (result.getStatus() != Status.PASSED) { + getLogMessage(unitTestResult).ifPresent(logMessage -> { + result.setStatusTrace(result.getStatusTrace() + logMessage); + }); + } Optional.ofNullable(tests.get(executionId)).ifPresent(unitTest -> { result.setParameters(unitTest.getParameters()); result.setDescription(unitTest.getDescription()); @@ -170,6 +176,12 @@ protected void parseUnitTestResult(final XmlElement unitTestResult, visitor.visitTestResult(result); } + 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..d576d3cf1 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,23 @@ 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.getStatusTrace().contains("Given I have entered 50 into the calculator")) + .filteredOn(result -> result.getStatusTrace().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(); From 50213f894a1e2f4f3f26960d385efe606660e5d6 Mon Sep 17 00:00:00 2001 From: PHe Date: Tue, 9 Oct 2018 10:14:03 +0200 Subject: [PATCH 2/4] fix trx plugin stores standard output into steps --- .../java/io/qameta/allure/trx/TrxPlugin.java | 17 ++++++++++++++++- .../io/qameta/allure/trx/TrxPluginTest.java | 5 +++-- 2 files changed, 19 insertions(+), 3 deletions(-) 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 83c612dce..23093af3d 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; @@ -164,7 +168,14 @@ protected void parseUnitTestResult(final XmlElement unitTestResult, getStatusTrace(unitTestResult).ifPresent(result::setStatusTrace); if (result.getStatus() != Status.PASSED) { getLogMessage(unitTestResult).ifPresent(logMessage -> { - result.setStatusTrace(result.getStatusTrace() + 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 -> { @@ -176,6 +187,10 @@ 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)) 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 d576d3cf1..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 @@ -102,8 +102,9 @@ public void shouldParseStdOutOnFail() throws Exception { assertThat(captor.getAllValues()) .filteredOn(result -> result.getStatus() == Status.FAILED) - .filteredOn(result -> result.getStatusTrace().contains("Given I have entered 50 into the calculator")) - .filteredOn(result -> result.getStatusTrace().contains("And I have entered -1 into the calculator")) + .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); } From af9109f9bd167b287890dc6ac7b9ffd1e4311002 Mon Sep 17 00:00:00 2001 From: PHe Date: Tue, 9 Oct 2018 10:20:52 +0200 Subject: [PATCH 3/4] fix missing parenthesis causing build failure --- .../src/main/java/io/qameta/allure/trx/TrxPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 23093af3d..7fce184cd 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 @@ -171,7 +171,7 @@ protected void parseUnitTestResult(final XmlElement unitTestResult, final List lines = splitLines(logMessage); final List steps = lines .stream() - .map(line -> new Step.setName(line)) + .map(line -> new Step().setName(line)) .collect(Collectors.toList()); final StageResult stageResult = new StageResult() .setSteps(steps); From 9402996ee4a584f6f032467fa82d4855a0a363f5 Mon Sep 17 00:00:00 2001 From: PHe Date: Tue, 9 Oct 2018 14:19:08 +0200 Subject: [PATCH 4/4] fixed standard output is also included in passed tests --- .../java/io/qameta/allure/trx/TrxPlugin.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) 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 7fce184cd..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 @@ -166,18 +166,16 @@ protected void parseUnitTestResult(final XmlElement unitTestResult, .setTime(getTime(startTime, endTime)); getStatusMessage(unitTestResult).ifPresent(result::setStatusMessage); getStatusTrace(unitTestResult).ifPresent(result::setStatusTrace); - if (result.getStatus() != Status.PASSED) { - 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); - }); - } + 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());