From 23d69dbfa5a788cb86372d7101532b9aafc7465e Mon Sep 17 00:00:00 2001 From: Noor Date: Sun, 29 Nov 2026 16:04:32 +0200 Subject: [PATCH 1/5] Support the Cucumber-JS 13 built-in junit report format Cucumber-JS 13 writes junit reports with its built-in junit formatter: one per scenario or Examples row, with the step results in system-out. The cucumber-js handler now reads this format. The legacy cucumber-junit format (one per scenario, Cucumber-JS 7 and earlier) is no longer supported. - CucumberJsHandler: rewritten for the new format. It matches features by name and scenarios by testcase name (rule, Examples name, row number). It reads step statuses from system-out. Undefined, pending and ambiguous steps are reported as failed. A scenario that failed outside its steps, e.g. in a hook, is reported with skipped steps. - BddFrameworkHandler.getOutlineIndex() (default: empty), OctaneFeature.findScenario(name, outlineIndex), Bdd2Octane: match an Examples row by its reported row number. Other handlers are unchanged and still match rows in report order. - Tests: Cucumber-JS 13.3.0 sample features and reports, new expected results for the 3 Cucumber-JS integration tests, 23 unit tests in TestCucumberJsHandler. The legacy cucumber-junit fixtures are removed. - README: Cucumber-JS 13.3.0 is the tested version, with notes on the new format. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 20 +- .../java/com/microfocus/bdd/Bdd2Octane.java | 5 +- .../com/microfocus/bdd/CucumberJsHandler.java | 192 ++-- .../bdd/api/BddFrameworkHandler.java | 12 +- .../com/microfocus/bdd/api/OctaneFeature.java | 4 + .../bdd/it/Bdd2OctaneHandlerITCase.java | 6 +- .../microfocus/bdd/ut/FilesLocatorTest.java | 2 +- .../bdd/ut/TestCucumberJsHandler.java | 374 ++++++-- .../13.3.0/features/basics.feature | 62 ++ .../cucumber-js/13.3.0/features/hooks.feature | 11 + .../13.3.0/features/outlines.feature | 31 + .../cucumber-js/13.3.0/features/rules.feature | 17 + .../cucumber-js/13.3.0/reports/junit.xml | 154 +++ .../13.3.0/reports/split/basics.xml | 73 ++ .../13.3.0/reports/split/outlines.xml | 59 ++ .../all-passed-junit-test-report.xml | 157 --- ...mber-js-junit-test-with-skipped-status.xml | 282 ------ .../cucumber-junit-test-report.xml | 137 --- ...junit-test-with-examples-has-same-name.xml | 246 ----- ...rd-multipleDifferent-cucumber-js-final.xml | 551 +++++------ ...tandard-multipleSame-cucumber-js-final.xml | 893 ++++++++++++------ .../standard-single-cucumber-js-final.xml | 316 ++++--- 22 files changed, 1923 insertions(+), 1681 deletions(-) create mode 100644 src/test/resources/cucumber-js/13.3.0/features/basics.feature create mode 100644 src/test/resources/cucumber-js/13.3.0/features/hooks.feature create mode 100644 src/test/resources/cucumber-js/13.3.0/features/outlines.feature create mode 100644 src/test/resources/cucumber-js/13.3.0/features/rules.feature create mode 100644 src/test/resources/cucumber-js/13.3.0/reports/junit.xml create mode 100644 src/test/resources/cucumber-js/13.3.0/reports/split/basics.xml create mode 100644 src/test/resources/cucumber-js/13.3.0/reports/split/outlines.xml delete mode 100644 src/test/resources/cucumber-js/all-passed-junit-test-report.xml delete mode 100644 src/test/resources/cucumber-js/cucmber-js-junit-test-with-skipped-status.xml delete mode 100644 src/test/resources/cucumber-js/cucumber-junit-test-report.xml delete mode 100644 src/test/resources/cucumber-js/cucumber-junit-test-with-examples-has-same-name.xml diff --git a/README.md b/README.md index 3e81614..db04b64 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This tool is configured as a build step before the "ALM Octane Cucumber test rep The following frameworks are currently supported out-of-the-box: - cucumber-js - > verfied versions: 4.2.1, 5.1.0, 6.0.5, 7.3.0 + > tested version: 13.3.0, with the built-in junit formatter (since bdd2octane 1.1.14) - php-behat > verified versions: 3.8.1 - python-radish @@ -61,13 +61,17 @@ SpecFlow test result injection is supported via the use of a template file for r ### Notes on Cucumber-js handler -* Cucumber-js using the Gherkin library to parse the feature file. For Cucumber-js version 6.x and below, it uses the Gherkin - library in version 5 or below which does not support the keyword "Example". - If a feature file contains "Example" as keyword, the program will throw an error. - It is recommended to use "Scenario" instead of "Example" as the scenario keyword to avoid this error. -* "Example" keyword was added to the Gherkin library in version 6.0.13 on 9/25 - 2018 [Gherkin library changelog](https://github.com/cucumber/common/blob/main/gherkin/CHANGELOG.md#6013---2018-09-25). - Cucumber-js version 7 and above applies the updated Gherkin library and won't have this problem. +* The handler reads the report of the built-in junit formatter of Cucumber-js, for example + `cucumber-js --format junit:reports/junit.xml`: one testcase per scenario or Examples row, with the step results + in system-out. The report of the `cucumber-junit` converter (one testsuite per scenario), used with Cucumber-js 7 + and earlier, is no longer supported. +* The report has no feature file path, so scenarios are matched to feature files by feature name. Feature names must be + unique among the feature files. +* The report has no step durations, so steps are reported with a duration of 0. +* A scenario that failed outside its steps, for example in a Before or After hook, is reported with skipped steps and + a warning, because the Octane result can only report failures of steps. +* A failed BeforeAll or AfterAll hook is reported as a testcase of no scenario. It is skipped with a message, so + Octane does not show the hook failure. ### Notes on Cucumber-jvm handler * If **useFileNameCompatibleName** is enabled, the space character in a feature name is replaced with underscore(_) in JUnit report, diff --git a/src/main/java/com/microfocus/bdd/Bdd2Octane.java b/src/main/java/com/microfocus/bdd/Bdd2Octane.java index c165216..ad26bae 100644 --- a/src/main/java/com/microfocus/bdd/Bdd2Octane.java +++ b/src/main/java/com/microfocus/bdd/Bdd2Octane.java @@ -147,7 +147,10 @@ public void run() throws IOException, XMLStreamException, InstantiationException } //3. Merge steps into a scenario. - Optional scenario = octaneFeature.findScenarioAndUpdateOutlineIndex(scenarioName); + OptionalInt outlineIndex = bddFrameworkHandler.getOutlineIndex(); + Optional scenario = outlineIndex.isPresent() + ? octaneFeature.findScenario(scenarioName, outlineIndex.getAsInt()) + : octaneFeature.findScenarioAndUpdateOutlineIndex(scenarioName); if (!scenario.isPresent()) { System.err.println("cannot find scenario: " + scenarioName + " from feature"); skipped++; diff --git a/src/main/java/com/microfocus/bdd/CucumberJsHandler.java b/src/main/java/com/microfocus/bdd/CucumberJsHandler.java index 24d08d6..39a705c 100644 --- a/src/main/java/com/microfocus/bdd/CucumberJsHandler.java +++ b/src/main/java/com/microfocus/bdd/CucumberJsHandler.java @@ -32,16 +32,34 @@ package com.microfocus.bdd; import com.microfocus.bdd.api.*; +import io.cucumber.messages.types.Examples; +import io.cucumber.messages.types.FeatureChild; +import io.cucumber.messages.types.Rule; +import io.cucumber.messages.types.RuleChild; +import io.cucumber.messages.types.Scenario; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.OptionalInt; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +/** + * Reads a testcase of the built-in junit formatter of Cucumber-js. The testcase is named + * "[rule - ]scenario[ - examples - #e.r[: pickle name]]" and its system-out has one + * "keyword step text....status" line per step. Step durations are not reported. + */ public class CucumberJsHandler implements BddFrameworkHandler { + private static final Pattern STEP_RESULT = Pattern.compile(".+\\.\\.(passed|failed|skipped|pending|undefined|ambiguous|unknown)"); + private Element element; - private String failureStep; - private String errorMessage; - private Optional failureDuration; - private Map> passedStepWithDuration; - private boolean isSkipped = false; + private List stepResults; + private String failure; + private boolean failedOutsideSteps; + private int nextStepResult; + private int outlineIndex; @Override public String getName() { @@ -51,92 +69,132 @@ public String getName() { @Override public void setElement(Element element) { this.element = element; - passedStepWithDuration = new HashMap<>(); - if(!element.getChildren().isEmpty()) { - for(Element stepElement: element.getChildren()) { - if(stepElement.getName().equals("testcase")) { - if(stepElement.getChildren().isEmpty()) { - passedStepWithDuration.put(stepElement.getAttribute("name"), convertToLong(stepElement.getAttribute("time"))); - } else if (stepElement.getChildren().get(0).getName().equals("failure")) { - Element failedStep = stepElement.getChildren().get(0); - failureStep = stepElement.getAttribute("name"); - errorMessage = failedStep.getText(); - failureDuration = convertToLong(failedStep.getAttribute("time")); - } else if (stepElement.getChildren().get(0).getName().equals("skipped")) { - isSkipped = true; - } - } - } - } - } - - private Optional convertToLong(String time) { - if(time != null) { - Double value = Double.parseDouble(time); - return Optional.of(Math.round(value * 1000)); - } - return null; + List lines = element.getChild("system-out") + .map(systemOut -> Arrays.stream(systemOut.getText().split("\n")).map(String::trim) + .filter(line -> !line.isEmpty()).collect(Collectors.toList())) + .orElse(new ArrayList<>()); + stepResults = lines.stream().allMatch(line -> STEP_RESULT.matcher(line).matches()) ? lines : new ArrayList<>(); + failure = element.getChild("failure") + .map(f -> f.getText().isEmpty() && f.getAttribute("message") != null ? f.getAttribute("message") : f.getText()) + .orElse(null); + // e.g. a hook failed: the testcase failed, but none of its steps + failedOutsideSteps = (element.getChild("failure").isPresent() || element.getChild("error").isPresent()) + && stepResults.stream().noneMatch(line -> toStatus(line) == Status.FAILED); + nextStepResult = 0; + outlineIndex = 0; } @Override public Optional getFeatureName(OctaneFeatureLocator... octaneFeatureLocator) { - return Optional.empty(); + return Optional.ofNullable(element.getAttribute("classname")); } @Override public Optional getFeatureFile() { - return findFeatureFile(); + return Optional.empty(); } + /** + * @return the name of the scenario or scenario outline that the testcase is named after, null if there is none + */ @Override public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... octaneFeatureLocator) { - String featureName = feature.getName(); - String featureNameWithDash = featureName.replaceAll(" ", "-"); - featureNameWithDash = featureNameWithDash.substring(0, 1).toLowerCase() + featureNameWithDash.substring(1); - String elementName = element.getAttribute("name"); - String scenarioNameFromElement = elementName.replace(featureNameWithDash.toLowerCase(), "").substring(1); - for (OctaneScenario scenario : feature.getScenarios()) { - String currentScenarioName = scenario.getOutlineName(); - String changedScenarioName = currentScenarioName.replace(" ", "-").replace(" ", ""); - if (changedScenarioName.equalsIgnoreCase(scenarioNameFromElement)) { - return scenario.getName(); + Optional scenario = findScenario(feature); + outlineIndex = scenario.map(OctaneScenario::getOutlineIndex).orElse(0); + return scenario.map(OctaneScenario::getName).orElse(null); + } + + @Override + public OptionalInt getOutlineIndex() { + return outlineIndex > 0 ? OptionalInt.of(outlineIndex) : OptionalInt.empty(); + } + + private Optional findScenario(OctaneFeature feature) { + String name = element.getAttribute("name"); + for (FeatureChild child : feature.getGherkinDocument().getFeature().get().getChildren()) { + if (child.getScenario().isPresent()) { + Optional scenario = findScenario(feature, name, "", child.getScenario().get()); + if (scenario.isPresent()) { + return scenario; + } + } + if (child.getRule().isPresent()) { + Rule rule = child.getRule().get(); + for (RuleChild ruleChild : rule.getChildren()) { + if (ruleChild.getScenario().isPresent()) { + Optional scenario = findScenario(feature, name, rule.getName(), ruleChild.getScenario().get()); + if (scenario.isPresent()) { + return scenario; + } + } + } } + } + return Optional.empty(); + } + private static Optional findScenario(OctaneFeature feature, String name, String ruleName, Scenario scenario) { + String scenarioName = join(ruleName, scenario.getName()); + if (scenario.getExamples().isEmpty()) { + return scenarioName.equals(name) ? feature.findScenario(scenario.getName(), 0) : Optional.empty(); + } + int outlineIndex = 0; + for (int e = 0; e < scenario.getExamples().size(); e++) { + Examples examples = scenario.getExamples().get(e); + for (int r = 0; r < examples.getTableBody().size(); r++) { + outlineIndex++; + String exampleName = join(scenarioName, examples.getName(), "#" + (e + 1) + "." + (r + 1)); + if (name.equals(exampleName) || name.startsWith(exampleName + ": ")) { + return feature.findScenario(scenario.getName(), outlineIndex); + } + } } - return null; + return Optional.empty(); + } + + private static String join(String... names) { + return Arrays.stream(names).filter(name -> !name.isEmpty()).collect(Collectors.joining(" - ")); } + /** + * Sets the status of the step from the next step line. + */ @Override public void fillStep(OctaneStep octaneStep) { - String stepWithKeyWord = octaneStep.getCompleteStepName(); - if(failureStep != null && failureStep.equals(stepWithKeyWord)) { - octaneStep.setStatus(Status.FAILED); - octaneStep.setErrorMessage(errorMessage); - if(failureDuration != null && failureDuration.isPresent()) { - octaneStep.setDuration(failureDuration.get()); - } - } else if (passedStepWithDuration.containsKey(stepWithKeyWord)) { - octaneStep.setStatus(Status.PASSED); - if (passedStepWithDuration.get(stepWithKeyWord) != null) { - octaneStep.setDuration(passedStepWithDuration.get(stepWithKeyWord).get()); - } - } else if (isSkipped) { + if (failedOutsideSteps) { + System.err.println("Scenario \"" + element.getAttribute("name") + + "\" failed outside its steps, its steps are reported as skipped"); octaneStep.setStatus(Status.SKIPPED); + return; + } + String stepResult = nextStepResult < stepResults.size() ? stepResults.get(nextStepResult++) : ""; + if (!stepResult.startsWith(octaneStep.getCompleteStepName() + "..")) { + System.err.println("Step \"" + octaneStep.getCompleteStepName() + "\" of scenario \"" + + element.getAttribute("name") + "\" is not in the report, it is reported as skipped"); + octaneStep.setStatus(Status.SKIPPED); + return; + } + octaneStep.setStatus(toStatus(stepResult)); + if (octaneStep.getStatus() == Status.FAILED) { + octaneStep.setErrorMessage(failure == null || failure.isEmpty() + ? "The step is " + stepResult.substring(stepResult.lastIndexOf('.') + 1) : failure); } } - public Optional findFeatureFile() { - Element propertiesElements = element.getChild("properties").get(); - for (Element property: propertiesElements.getChildren()){ - if (property.getAttribute("name").equals("URI")) { - return Optional.of(property.getAttribute("value")); - } - + private static Status toStatus(String stepResult) { + switch (stepResult.substring(stepResult.lastIndexOf('.') + 1)) { + case "passed": + return Status.PASSED; + case "skipped": + case "unknown": + return Status.SKIPPED; + default: + return Status.FAILED; } - return Optional.empty(); } + @Override public String getTestCaseElementName() { - return "testsuite"; + return "testcase"; } -} +} \ No newline at end of file diff --git a/src/main/java/com/microfocus/bdd/api/BddFrameworkHandler.java b/src/main/java/com/microfocus/bdd/api/BddFrameworkHandler.java index 4d4c560..c598175 100644 --- a/src/main/java/com/microfocus/bdd/api/BddFrameworkHandler.java +++ b/src/main/java/com/microfocus/bdd/api/BddFrameworkHandler.java @@ -34,6 +34,7 @@ import com.microfocus.bdd.OctaneFeatureLocator; import java.util.Optional; + import java.util.OptionalInt; public interface BddFrameworkHandler { @@ -72,6 +73,16 @@ public interface BddFrameworkHandler { */ String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... octaneFeatureLocator); + /** + * This method is invoked after getScenarioName. If the XML element identifies the Examples row of a scenario + * outline, the implementation returns the position of that row, counted from 1 across all the Examples of the + * outline. Otherwise, the rows of an outline are matched in the order of the XML elements. + * @return the outline index of the Examples row + */ + default OptionalInt getOutlineIndex() { + return OptionalInt.empty(); + } + /** * This method is invoked to get back the status of the OctaneStep, the implementation should set correct Status * based on the XML element, and in case of failure, set the errorMessage as well. @@ -83,7 +94,6 @@ public interface BddFrameworkHandler { /** * @return the XML element name of a scenario, most of bdd frameworks use "testcase" - * cucumber-js uses "testsuite" */ String getTestCaseElementName(); diff --git a/src/main/java/com/microfocus/bdd/api/OctaneFeature.java b/src/main/java/com/microfocus/bdd/api/OctaneFeature.java index 387adc6..02bc2af 100644 --- a/src/main/java/com/microfocus/bdd/api/OctaneFeature.java +++ b/src/main/java/com/microfocus/bdd/api/OctaneFeature.java @@ -95,6 +95,10 @@ public Optional findScenarioAndUpdateOutlineIndex(String scenari } } + public Optional findScenario(String scenarioName, int outlineIndex) { + return getScenarios(scenarioName).stream().filter(sce -> sce.getOutlineIndex() == outlineIndex).findFirst(); + } + private int nextOutlineIndex(String scenarioName) { return ++scenarios.get(scenarioName).outlineIndex; } diff --git a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java index 214df4b..25f02b6 100644 --- a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java +++ b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java @@ -52,21 +52,21 @@ public class Bdd2OctaneHandlerITCase extends Bdd2OctaneITCase { public static List data() { return Arrays.asList(new Object[][]{ //single feature file - {Framework.CUCUMBER_JS, "src/test/resources/cucumber-js/cucumber-junit-test-with-examples-has-same-name.xml", "src/test/resources/features/robustgherkin03.feature", "singleResults/cucumber-js-final.xml", "**/singleResults/standard-single-cucumber-js-final.xml"}, + {Framework.CUCUMBER_JS, "src/test/resources/cucumber-js/13.3.0/reports/split/basics.xml", "src/test/resources/cucumber-js/13.3.0/features/basics.feature", "singleResults/cucumber-js-final.xml", "**/singleResults/standard-single-cucumber-js-final.xml"}, {Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/junit-passed.xml", "src/test/resources/features/robustgherkin.feature", "singleResults/cucumber-jvm-final.xml", "**/singleResults/standard-single-cucumber-jvm-final.xml"}, {Framework.CUCUMBER_RUBY, "src/test/resources/cucumber-ruby/passed_skipped_failed.xml", "src/test/resources/features/robustgherkin.feature", "singleResults/cucumber-ruby-final.xml", "**/singleResults/standard-single-cucumber-ruby-final.xml"}, {Framework.PHP_BEHAT, "src/test/resources/php-behat/fail-assert-1.xml", "src/test/resources/features/robustgherkin.feature", "singleResults/php-behat-final.xml", "**/singleResults/standard-single-php-behat-final.xml"}, {Framework.PYTHON_BEHAVE, "src/test/resources/python-behave/TESTS-python-behave-pass-skip-fail.xml", "src/test/resources/features/dealer.feature", "singleResults/python-behave-final.xml", "**/singleResults/standard-single-python-behave-final.xml"}, {Framework.PYTHON_RADISH, "src/test/resources/python-radish/python-radish-skipped-passed-failed.xml", "src/test/resources/features/robustgherkin03.feature", "singleResults/python-radish-final.xml", "**/singleResults/standard-single-python-radish-final.xml"}, //multiple feature files - different file path - {Framework.CUCUMBER_JS, "src/test/resources/cucumber-js/cucumber*.xml", "src/test/resources/features/*.feature", "multipleDifferentResults/cucumber-js-final.xml", "**/multipleDifferentResults/standard-multipleDifferent-cucumber-js-final.xml"}, + {Framework.CUCUMBER_JS, "src/test/resources/cucumber-js/13.3.0/reports/split/*.xml", "src/test/resources/cucumber-js/13.3.0/features/*.feature", "multipleDifferentResults/cucumber-js-final.xml", "**/multipleDifferentResults/standard-multipleDifferent-cucumber-js-final.xml"}, {Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/**/*passed.xml", "src/test/resources/features/*.feature", "multipleDifferentResults/cucumber-jvm-final.xml", "**/multipleDifferentResults/standard-multipleDifferent-cucumber-jvm-final.xml"}, {Framework.CUCUMBER_RUBY, "src/test/resources/cucumber-ruby/*passed.xml", "src/test/resources/features/*.feature", "multipleDifferentResults/cucumber-ruby-final.xml", "**/multipleDifferentResults/standard-multipleDifferent-cucumber-ruby-final.xml"}, {Framework.PHP_BEHAT, "src/test/resources/php-behat/*pass*.xml", "src/test/resources/features/*.feature", "multipleDifferentResults/php-behat-final.xml", "**/multipleDifferentResults/standard-multipleDifferent-php-behat-final.xml"}, {Framework.PYTHON_BEHAVE, "src/test/resources/python-behave/*skipped*.xml", "src/test/resources/features/*.feature", "multipleDifferentResults/python-behave-final.xml", "**/multipleDifferentResults/standard-multipleDifferent-python-behave-final.xml"}, {Framework.PYTHON_RADISH, "src/test/resources/python-radish/*all-pass*.xml", "src/test/resources/features/*.feature", "multipleDifferentResults/python-radish-final.xml", "**/multipleDifferentResults/standard-multipleDifferent-python-radish-final.xml"}, //multiple feature files - same file path - {Framework.CUCUMBER_JS, "src/test/resources/cucumber-js/*test-report.xml", "**/*.feature", "multipleSameResults/cucumber-js-final.xml", "**/multipleSameResults/standard-multipleSame-cucumber-js-final.xml"}, + {Framework.CUCUMBER_JS, "src/test/resources/cucumber-js/13.3.0/reports/**/*.xml", "src/test/resources/cucumber-js/13.3.0/features/*.feature", "multipleSameResults/cucumber-js-final.xml", "**/multipleSameResults/standard-multipleSame-cucumber-js-final.xml"}, {Framework.CUCUMBER_JVM, "**/junit-passed.xml", "**/*.feature", "multipleSameResults/cucumber-jvm-final.xml", "**/multipleSameResults/standard-multipleSame-cucumber-jvm-final.xml"}, {Framework.CUCUMBER_RUBY, "src/test/resources/cucumber-ruby/TEST*.xml", "src/test/resources/features/*.feature", "multipleSameResults/cucumber-ruby-final.xml", "**/multipleSameResults/standard-multipleSame-cucumber-ruby-final.xml"}, {Framework.PHP_BEHAT, "src/test/resources/php-behat/*1.xml", "src/test/resources/features/*.feature", "multipleSameResults/php-behat-final.xml", "**/multipleSameResults/standard-multipleSame-php-behat-final.xml"}, diff --git a/src/test/java/com/microfocus/bdd/ut/FilesLocatorTest.java b/src/test/java/com/microfocus/bdd/ut/FilesLocatorTest.java index 7b5e878..d94ccd9 100644 --- a/src/test/java/com/microfocus/bdd/ut/FilesLocatorTest.java +++ b/src/test/java/com/microfocus/bdd/ut/FilesLocatorTest.java @@ -68,6 +68,6 @@ public void matchPatternFailTest() { public void matchPatternPassTest() { final String pattern = "src/**/*junit*.xml"; List reports = FilesLocator.getReportFiles(pattern); - Assert.assertEquals(25, reports.size()); + Assert.assertEquals(22, reports.size()); } } diff --git a/src/test/java/com/microfocus/bdd/ut/TestCucumberJsHandler.java b/src/test/java/com/microfocus/bdd/ut/TestCucumberJsHandler.java index 3b39212..086845d 100644 --- a/src/test/java/com/microfocus/bdd/ut/TestCucumberJsHandler.java +++ b/src/test/java/com/microfocus/bdd/ut/TestCucumberJsHandler.java @@ -31,86 +31,340 @@ */ package com.microfocus.bdd.ut; -import com.microfocus.bdd.*; -import com.microfocus.bdd.api.*; +import com.microfocus.bdd.Bdd2Octane; +import com.microfocus.bdd.CucumberJsHandler; +import com.microfocus.bdd.JunitReportReader; +import com.microfocus.bdd.api.Element; +import com.microfocus.bdd.api.OctaneFeature; +import com.microfocus.bdd.api.OctaneScenario; +import com.microfocus.bdd.api.OctaneStep; +import com.microfocus.bdd.api.Status; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; +import java.util.Optional; + +import static com.microfocus.bdd.api.Status.FAILED; +import static com.microfocus.bdd.api.Status.PASSED; +import static com.microfocus.bdd.api.Status.SKIPPED; public class TestCucumberJsHandler { - private OctaneFeature octaneFeature; + private static final String SAMPLE = "src/test/resources/cucumber-js/13.3.0/"; + private static final String REPORT = "reports/junit.xml"; - @Before - public void setup() { - octaneFeature = TestUtil.parseFeatureFile("src/test/resources/features/robustgherkin.feature"); + @Test + public void testPassedScenario() { + CucumberJsHandler handler = getHandler(REPORT, "All steps pass"); + Assert.assertEquals("handler can get back feature name", "Latest basics", handler.getFeatureName().get()); + Assert.assertFalse("the report has no feature file", handler.getFeatureFile().isPresent()); + assertScenario(handler, "basics.feature", "All steps pass", 0, PASSED, PASSED, PASSED, PASSED); } @Test public void testFailedScenario() { - CucumberJsHandler handler = new CucumberJsHandler(); - Element element = TestUtil.getXmlElement("src/test/resources/cucumber-js/cucumber-junit-test-report.xml", "testsuite", 2); - handler.setElement(element); - Assert.assertEquals("handler can get back feature's partial path", - "features/robustgherkin.feature", - handler.getFeatureFile().get()); - Assert.assertEquals("handler can get back scenario name", - "Some another scenario 2", handler.getScenarioName(octaneFeature)); - Assert.assertEquals("handler can get back file path", - "features/robustgherkin.feature", - handler.getFeatureFile().get()); - String errorMessage = element.getChildren().get(13).getChildren().get(0).getText(); - Assert.assertTrue("handler can get correct error message for failed step", errorMessage.contains("Expected values to be strictly equal")); - } - - @Test - public void testPassedScenario(){ - CucumberJsHandler handler = new CucumberJsHandler(); - Element element = TestUtil.getXmlElement("src/test/resources/cucumber-js/all-passed-junit-test-report.xml", "testsuite", 1); - handler.setElement(element); - Assert.assertEquals("handler can get back feature's partial path", - "features/robustgherkin.feature", - handler.getFeatureFile().get()); - Assert.assertEquals("handler can get back scenario name", - "Some determinable business situation", handler.getScenarioName(octaneFeature)); - List childrenElement = element.getChildren().stream().filter(child -> child.getName().equals("testcase")).collect(Collectors.toList()); - childrenElement.forEach(child -> { - Assert.assertTrue("Each step should not have children",child.getChildren().isEmpty()); - }); + assertScenario(getHandler(REPORT, "Middle step fails"), "basics.feature", "Middle step fails", 0, + PASSED, PASSED, FAILED, SKIPPED); + } + + @Test + public void testUndefinedPendingAndAmbiguousStepsFail() { + for (String scenario : Arrays.asList("Undefined step", "Pending step", "Ambiguous step")) { + assertScenario(getHandler(REPORT, scenario), "basics.feature", scenario, 0, PASSED, PASSED, FAILED, SKIPPED); + } + } + + @Test + public void testSkippedScenario() { + assertScenario(getHandler(REPORT, "Skipped scenario"), "basics.feature", "Skipped scenario", 0, + PASSED, PASSED, SKIPPED, SKIPPED); + } + @Test + public void testRepeatedIdenticalSteps() { + assertScenario(getHandler(REPORT, "Repeated identical steps"), "basics.feature", "Repeated identical steps", 0, + PASSED, PASSED, PASSED, FAILED, SKIPPED); } @Test public void testOutlineScenario() { + assertScenario(getHandler(REPORT, "Eating of cucumbers - Few - #1.2: Eating 5 of 20 cucumbers"), + "outlines.feature", "Eating of cucumbers", 2, PASSED, PASSED, PASSED, FAILED); + } + + @Test + public void testTwoOutlineScenarioWithSameName() { + // both rows are named "Eating 5 of 12 cucumbers" + assertScenario(getHandler(REPORT, "Eating of cucumbers - Few - #1.1: Eating 5 of 12 cucumbers"), + "outlines.feature", "Eating of cucumbers", 1, PASSED, PASSED, PASSED, PASSED); + assertScenario(getHandler(REPORT, "Eating of cucumbers - Many - #2.2: Eating 5 of 12 cucumbers"), + "outlines.feature", "Eating of cucumbers", 4, PASSED, PASSED, PASSED, FAILED); + } + + @Test + public void testOutlineWithoutParametersInItsName() { + // neither the outline name has parameters nor the Examples have a name + assertScenario(getHandler(REPORT, "Counting cucumbers - #1.1"), "outlines.feature", "Counting cucumbers", 1, + PASSED, PASSED, PASSED); + } + + @Test + public void testRuleScenario() { + assertScenario(getHandler(REPORT, "First rule - Rule scenario fails"), "rules.feature", "Rule scenario fails", 0, + PASSED, PASSED, PASSED, FAILED); + } + + @Test + public void testScenarioOfAnotherFeature() { + CucumberJsHandler handler = getHandler(REPORT, "Second rule - Rule scenario passes"); + Assert.assertNull("handler cannot find a scenario of another feature", + handler.getScenarioName(TestUtil.parseFeatureFile(SAMPLE + "features/basics.feature"))); + Assert.assertFalse("handler has no outline index", handler.getOutlineIndex().isPresent()); + } + + @Test + public void testStepNotInReport() { + // the third step of "Shared scenario name" is not the third step result of "All steps pass" + CucumberJsHandler handler = getHandler(REPORT, "All steps pass"); + OctaneScenario scenario = TestUtil.parseFeatureFile(SAMPLE + "features/basics.feature") + .getScenarios("Shared scenario name").get(0); + Assert.assertEquals("handler skips a step that is not in the report", + Arrays.asList(PASSED, PASSED, SKIPPED), fillSteps(handler, scenario)); + } + + @Test + public void testNameAndTestCaseElement() { CucumberJsHandler handler = new CucumberJsHandler(); - Element element = TestUtil.getXmlElement("src/test/resources/cucumber-js/cucumber-junit-test-report.xml", "testsuite", 3); - handler.setElement(element); + Assert.assertEquals("cucumber-js", handler.getName()); + Assert.assertEquals("testcase", handler.getTestCaseElementName()); + } - Assert.assertEquals("handler can get back feature's partial path", - "features/robustgherkin.feature", - handler.getFeatureFile().get()); - String scenarioName = handler.getScenarioName(octaneFeature); - Assert.assertEquals("handler can get back scenario name", - "feeding a cow yum yum yum", scenarioName); + @Test + public void testErrorMessages() { + Assert.assertEquals("the failure of a failed step is its error message", + "AssertionError [ERR_ASSERTION]: middle step failure\n at World. (/work/features/step_definitions/steps.js:37:10)", + errorMessage(getFailedStep(getHandler(REPORT, "Middle step fails"), "Middle step fails"))); + Assert.assertTrue("the failure of a step raising an error is its error message", + errorMessage(getFailedStep(getHandler(REPORT, "Step raises an error"), "Step raises an error")) + .startsWith("TypeError: unexpected error")); + for (String status : Arrays.asList("undefined", "pending", "ambiguous")) { + String scenario = Character.toUpperCase(status.charAt(0)) + status.substring(1) + " step"; + Assert.assertEquals("an empty failure is replaced with the step status", "The step is " + status, + errorMessage(getFailedStep(getHandler(REPORT, scenario), scenario))); + } } @Test - public void testTwoOutlineScenarioWithSameName() { - Element element = TestUtil.getXmlElement( - "src/test/resources/cucumber-js/cucumber-junit-test-with-examples-has-same-name.xml", - "testsuite", - 4); + public void testFailureMessageAttribute() { + CucumberJsHandler handler = getHandler(testcase("Feature A", "Scenario A", + "Given step one..........failed")); + OctaneStep step = givenStepOne(); + handler.fillStep(step); + Assert.assertEquals(FAILED, step.getStatus()); + Assert.assertEquals("the message attribute is used when the failure has no text", "the message", errorMessage(step)); + } + @Test + public void testDataTableAndDocString() { + assertScenario(getHandler(REPORT, "Data table and doc string"), "basics.feature", "Data table and doc string", 0, + PASSED, PASSED, PASSED, PASSED); + } + + @Test + public void testBeforeHookFails() { + // the steps are reported as skipped and the testcase has a failure + assertScenario(getHandler(REPORT, "Before hook fails"), "hooks.feature", "Before hook fails", 0, SKIPPED, SKIPPED); + } + + @Test + public void testAfterHookFails() { + // the steps are reported as passed, but the testcase failed: it must not be reported as passed + assertScenario(getHandler(REPORT, "After hook fails"), "hooks.feature", "After hook fails", 0, SKIPPED, SKIPPED); + } + + @Test + public void testErrorElementWithoutFailedStep() { + CucumberJsHandler handler = getHandler(testcase("Feature A", "Scenario A", + "Given step one..........passed")); + OctaneStep step = givenStepOne(); + handler.fillStep(step); + Assert.assertEquals("a testcase with an error and no failed step is not passed", SKIPPED, step.getStatus()); + } + + @Test + public void testUnknownStatusIsSkipped() { + CucumberJsHandler handler = getHandler(testcase("Feature A", "Scenario A", + "Given step one..........unknown")); + OctaneStep step = givenStepOne(); + handler.fillStep(step); + Assert.assertEquals(SKIPPED, step.getStatus()); + } + + @Test + public void testSystemOutWithoutStepResults() { + // e.g. console output of the test run instead of step results + CucumberJsHandler handler = getHandler(testcase("Feature A", "Scenario A", + "some console output\nGiven step one..........passed")); + OctaneStep step = givenStepOne(); + handler.fillStep(step); + Assert.assertEquals("steps are skipped if system-out is not a list of step results", SKIPPED, step.getStatus()); + } + + @Test + public void testRunHookTestcase() { + // a failed BeforeAll or AfterAll hook is a testcase named after the hook location, without classname + CucumberJsHandler handler = getHandler("" + + ""); + Assert.assertFalse("a run hook has no feature", handler.getFeatureName().isPresent()); + Assert.assertNull("a run hook has no scenario", + handler.getScenarioName(TestUtil.parseFeatureFile(SAMPLE + "features/rules.feature"))); + Assert.assertFalse(handler.getOutlineIndex().isPresent()); + } + + @Test + public void testHandlerReusedForAllTestcases() throws Exception { + // Bdd2Octane uses one handler for all the testcases of a report CucumberJsHandler handler = new CucumberJsHandler(); - handler.setElement(element); - Assert.assertEquals("handler can get back feature's partial path", - "features/robustgherkin03.feature", - handler.getFeatureFile().get()); - String scenarioName = handler.getScenarioName( - TestUtil.parseFeatureFile("src/test/resources/features/robustgherkin03.feature")); - Assert.assertEquals("handler can get back scenario name", - "feeding a cow yum yum yum", scenarioName); - } -} + int outlineRows = 0; + try (JunitReportReader reader = new JunitReportReader(new FileInputStream(SAMPLE + REPORT), "testcase")) { + for (Element element : reader) { + handler.setElement(element); + String featureFile = handler.getFeatureName().get().replace("Latest ", "") + ".feature"; + OctaneFeature feature = TestUtil.parseFeatureFile(SAMPLE + "features/" + featureFile); + String scenarioName = handler.getScenarioName(feature); + Assert.assertNotNull("handler finds the scenario of " + element.getAttribute("name"), scenarioName); + int outlineIndex = handler.getOutlineIndex().orElse(0); + outlineRows += outlineIndex > 0 ? 1 : 0; + OctaneScenario scenario = feature.getScenarios(scenarioName).get(Math.max(outlineIndex - 1, 0)); + for (OctaneStep step : scenario.getSteps()) { + handler.fillStep(step); + Assert.assertNotEquals("step " + step.getCompleteStepName() + " of " + element.getAttribute("name") + + " is in the report", null, step.getStatus()); + } + } + } + Assert.assertEquals("all the Examples rows have an outline index", 5, outlineRows); + } + + @Test + public void testReportOfOneExamplesRow() throws Exception { + // e.g. "cucumber-js features/outlines.feature:19" runs the last row of "Many" only + String report = new String(Files.readAllBytes(Paths.get(SAMPLE + REPORT)), StandardCharsets.UTF_8); + int start = report.indexOf(" of <start> cucumbers - Many - #2.2"); + String row = report.substring(start, report.indexOf("", start) + "".length()); + Path reportFile = Paths.get("target", "cucumber-js-one-examples-row.xml"); + Path resultFile = Paths.get("target", "cucumber-js-one-examples-row-result.xml"); + Files.write(reportFile, ("\n\n" + row + "\n\n") + .getBytes(StandardCharsets.UTF_8)); + + new Bdd2Octane(Collections.singletonList(reportFile.toString()), + Collections.singletonList(SAMPLE + "features/outlines.feature"), resultFile.toString(), "cucumber-js").run(); + + Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(resultFile.toFile()); + NodeList scenarios = result.getElementsByTagName("scenario"); + Assert.assertEquals("only the reported row is in the result", 1, scenarios.getLength()); + org.w3c.dom.Element scenario = (org.w3c.dom.Element) scenarios.item(0); + Assert.assertEquals("the row is matched by its number, not by its order", "4", scenario.getAttribute("outlineIndex")); + NodeList steps = scenario.getElementsByTagName("step"); + List statuses = new ArrayList<>(); + for (int i = 0; i < steps.getLength(); i++) { + statuses.add(((org.w3c.dom.Element) steps.item(i)).getAttribute("status")); + } + Assert.assertEquals(Arrays.asList("passed", "passed", "passed", "failed"), statuses); + Assert.assertEquals("Then I should have 8 cucumbers", ((org.w3c.dom.Element) steps.item(3)).getAttribute("name")); + } + + private static String errorMessage(OctaneStep step) { + StringWriter xml = new StringWriter(); + try { + XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(xml); + step.writeToXml(writer); + writer.flush(); + } catch (XMLStreamException e) { + throw new IllegalStateException(e); + } + String text = xml.toString(); + return text.substring(text.indexOf("")); + } + + private static OctaneStep givenStepOne() { return new OctaneStep("Given", "step one", "Context", Optional.empty(), Optional.empty()); + } + + private static String testcase(String classname, String name, String content) { + return "" + content + ""; + } + + private static CucumberJsHandler getHandler(String testcaseXml) { + String report = "" + testcaseXml + ""; + try (JunitReportReader reader = new JunitReportReader( + new ByteArrayInputStream(report.getBytes(StandardCharsets.UTF_8)), "testcase")) { + CucumberJsHandler handler = new CucumberJsHandler(); + handler.setElement(reader.iterator().next()); + return handler; + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + } + + private static OctaneStep getFailedStep(CucumberJsHandler handler, String scenarioName) { + OctaneFeature feature = TestUtil.parseFeatureFile(SAMPLE + "features/basics.feature"); + Assert.assertEquals(scenarioName, handler.getScenarioName(feature)); + for (OctaneStep step : feature.getScenarios(scenarioName).get(0).getSteps()) { + handler.fillStep(step); + if (step.getStatus() == FAILED) { + return step; + } + } + throw new AssertionError("No failed step in " + scenarioName); + } + + private static CucumberJsHandler getHandler(String report, String testcaseName) { + try (JunitReportReader reader = new JunitReportReader(new FileInputStream(SAMPLE + report), "testcase")) { + for (Element element : reader) { + if (testcaseName.equals(element.getAttribute("name"))) { + CucumberJsHandler handler = new CucumberJsHandler(); + handler.setElement(element); + return handler; + } + } + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + throw new IllegalArgumentException("No testcase \"" + testcaseName + "\" in " + report); + } + + private static void assertScenario(CucumberJsHandler handler, String featureFile, String scenarioName, int outlineIndex, + Status... statuses) { + OctaneFeature feature = TestUtil.parseFeatureFile(SAMPLE + "features/" + featureFile); + Assert.assertEquals("handler can get back scenario name", scenarioName, handler.getScenarioName(feature)); + Assert.assertEquals("handler can get back outline index", outlineIndex, handler.getOutlineIndex().orElse(0)); + OctaneScenario scenario = feature.getScenarios(scenarioName).get(Math.max(outlineIndex - 1, 0)); + Assert.assertEquals("handler can get back step statuses", Arrays.asList(statuses), fillSteps(handler, scenario)); + } + + private static List fillSteps(CucumberJsHandler handler, OctaneScenario scenario) { + List statuses = new ArrayList<>(); + for (OctaneStep step : scenario.getSteps()) { + handler.fillStep(step); + statuses.add(step.getStatus()); + } + return statuses; + } +} \ No newline at end of file diff --git a/src/test/resources/cucumber-js/13.3.0/features/basics.feature b/src/test/resources/cucumber-js/13.3.0/features/basics.feature new file mode 100644 index 0000000..ff65467 --- /dev/null +++ b/src/test/resources/cucumber-js/13.3.0/features/basics.feature @@ -0,0 +1,62 @@ +@BSPID2001REV0.1.0 +Feature: Latest basics + + Background: + Given the background is ready + + Scenario: All steps pass + Given a passing step + When another passing step + Then a final passing step + + Scenario: Middle step fails + Given a passing step + When a step that fails with "middle step failure" + Then a final passing step + + Scenario: Step raises an error + Given a passing step + When a step that raises an error + Then a final passing step + + Scenario: Undefined step + Given a passing step + When a step without any definition + Then a final passing step + + Scenario: Pending step + Given a passing step + When a pending step + Then a final passing step + + Scenario: Ambiguous step + Given a passing step + When an ambiguous step + Then a final passing step + + Scenario: Skipped scenario + Given a passing step + When a step that skips the scenario + Then a final passing step + + Scenario: Repeated identical steps + Given a passing step + When the counter is incremented + And the counter is incremented + Then a final passing step + + Scenario: Data table and doc string + Given the following cucumbers: + | colour | count | + | green | 3 | + | red | 1 | + And the following note: + """ + Line one with & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step diff --git a/src/test/resources/cucumber-js/13.3.0/features/hooks.feature b/src/test/resources/cucumber-js/13.3.0/features/hooks.feature new file mode 100644 index 0000000..f072229 --- /dev/null +++ b/src/test/resources/cucumber-js/13.3.0/features/hooks.feature @@ -0,0 +1,11 @@ +Feature: Latest hooks + + @failing-before-hook + Scenario: Before hook fails + Given a passing step + Then a final passing step + + @failing-after-hook + Scenario: After hook fails + Given a passing step + Then a final passing step diff --git a/src/test/resources/cucumber-js/13.3.0/features/outlines.feature b/src/test/resources/cucumber-js/13.3.0/features/outlines.feature new file mode 100644 index 0000000..0d36d4c --- /dev/null +++ b/src/test/resources/cucumber-js/13.3.0/features/outlines.feature @@ -0,0 +1,31 @@ +Feature: Latest outlines + + Background: + Given the background is ready + + Scenario Outline: Eating of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 | diff --git a/src/test/resources/cucumber-js/13.3.0/features/rules.feature b/src/test/resources/cucumber-js/13.3.0/features/rules.feature new file mode 100644 index 0000000..2c5a8b1 --- /dev/null +++ b/src/test/resources/cucumber-js/13.3.0/features/rules.feature @@ -0,0 +1,17 @@ +Feature: Latest rules + + Background: + Given the background is ready + + Rule: First rule + Background: + Given a rule background step + + Scenario: Rule scenario fails + Given a passing step + Then a step that fails with "rule failure" + + Rule: Second rule + Scenario: Rule scenario passes + Given a passing step + Then a final passing step diff --git a/src/test/resources/cucumber-js/13.3.0/reports/junit.xml b/src/test/resources/cucumber-js/13.3.0/reports/junit.xml new file mode 100644 index 0000000..957d7a0 --- /dev/null +++ b/src/test/resources/cucumber-js/13.3.0/reports/junit.xml @@ -0,0 +1,154 @@ + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + (/work/features/step_definitions/steps.js:41:9)]]> + + + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:59:11)]]> + + + + + + + + + + (/work/features/step_definitions/steps.js:17:9)]]> + + + + (/work/features/step_definitions/steps.js:21:9)]]> + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + \ No newline at end of file diff --git a/src/test/resources/cucumber-js/13.3.0/reports/split/basics.xml b/src/test/resources/cucumber-js/13.3.0/reports/split/basics.xml new file mode 100644 index 0000000..91d0d83 --- /dev/null +++ b/src/test/resources/cucumber-js/13.3.0/reports/split/basics.xml @@ -0,0 +1,73 @@ + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + (/work/features/step_definitions/steps.js:41:9)]]> + + + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:59:11)]]> + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/cucumber-js/13.3.0/reports/split/outlines.xml b/src/test/resources/cucumber-js/13.3.0/reports/split/outlines.xml new file mode 100644 index 0000000..1af18f4 --- /dev/null +++ b/src/test/resources/cucumber-js/13.3.0/reports/split/outlines.xml @@ -0,0 +1,59 @@ + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + \ No newline at end of file diff --git a/src/test/resources/cucumber-js/all-passed-junit-test-report.xml b/src/test/resources/cucumber-js/all-passed-junit-test-report.xml deleted file mode 100644 index 95abe6e..0000000 --- a/src/test/resources/cucumber-js/all-passed-junit-test-report.xml +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/cucumber-js/cucmber-js-junit-test-with-skipped-status.xml b/src/test/resources/cucumber-js/cucmber-js-junit-test-with-skipped-status.xml deleted file mode 100644 index 6c25ba6..0000000 --- a/src/test/resources/cucumber-js/cucmber-js-junit-test-with-skipped-status.xml +++ /dev/null @@ -1,282 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/cucumber-js/cucumber-junit-test-report.xml b/src/test/resources/cucumber-js/cucumber-junit-test-report.xml deleted file mode 100644 index 2f3853e..0000000 --- a/src/test/resources/cucumber-js/cucumber-junit-test-report.xml +++ /dev/null @@ -1,137 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: - - 1 !== -1 - - + expected - actual - - -1 - +-1 - - at World.<anonymous> (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:85:12) - - - - - - - - - - - - - - - - - - - - - - - Error: Weight can not be null - at checkEnergy (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:14:11) - at World.<anonymous> (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17) - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Weight can not be null - at checkEnergy (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:14:11) - at World.<anonymous> (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17) - - - - - - - \ No newline at end of file diff --git a/src/test/resources/cucumber-js/cucumber-junit-test-with-examples-has-same-name.xml b/src/test/resources/cucumber-js/cucumber-junit-test-with-examples-has-same-name.xml deleted file mode 100644 index 1a5ad00..0000000 --- a/src/test/resources/cucumber-js/cucumber-junit-test-with-examples-has-same-name.xml +++ /dev/null @@ -1,246 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Weight can not be null - at checkEnergy (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:14:11) - at World.<anonymous> (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Weight can not be null - at checkEnergy (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:14:11) - at World.<anonymous> (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Error: Weight can not be null - at checkEnergy (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:14:11) - at World.<anonymous> (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17) - - - - - - - \ No newline at end of file diff --git a/src/test/resources/standardOctaneGherkinReport/multipleDifferentResults/standard-multipleDifferent-cucumber-js-final.xml b/src/test/resources/standardOctaneGherkinReport/multipleDifferentResults/standard-multipleDifferent-cucumber-js-final.xml index f2a9f2f..998bfa3 100644 --- a/src/test/resources/standardOctaneGherkinReport/multipleDifferentResults/standard-multipleDifferent-cucumber-js-final.xml +++ b/src/test/resources/standardOctaneGherkinReport/multipleDifferentResults/standard-multipleDifferent-cucumber-js-final.xml @@ -1,313 +1,282 @@ + - - - + + yum yum yum - scenario outline - description - Given the cow weighs kg - When we calculate the feeding requirements - Then the energy should be MJ + Scenario: Undefined step + Given a passing step + When a step without any definition + Then a final passing step - Examples: - | name | weight | energy | - | cow1 | 450 | 26500 | - | cow2 | 500 | 29500 |]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - & "quotes" + Line two + """ + Then the cucumber count is 4 - at World. (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:85:12)]]> - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - - - - + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + + + + (/work/features/step_definitions/steps.js:41:9)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:59:11)]]> + + + + + + + + + + + + + + + + + + + + + + + + of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers - @R1 @R2 @R3 - Rule: first rule - Background: - Given first rule administrator named "RG" - * a blog named "RG's anti-tax rants" - * a customer named "RYBZ" + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | - @Quick @nightly - @TSCID1109 - Example: Some another scenario 2 - scenario 2 description - Given some precondition - And some other precondition with doc string - """ - this is comment - """ - When some action by the actor - And yet another action - Then some testable outcome is achieved - * something else we can check happens too - But I don't see something else + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | - @TSCID1110 - Scenario Outline: feeding a cow yum yum yum - scenario outline - description - Given the cow weighs kg - When we calculate the feeding requirements - Then the energy should be MJ + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is Examples: - | name | weight | energy | - | cow1 | 450 | 26500 | - | cow1 | 480 | 27500 | - | cow2 | 500 | 29500 |]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - + | count | + | 3 |]]> + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + + + + + + diff --git a/src/test/resources/standardOctaneGherkinReport/multipleSameResults/standard-multipleSame-cucumber-js-final.xml b/src/test/resources/standardOctaneGherkinReport/multipleSameResults/standard-multipleSame-cucumber-js-final.xml index d94c1d8..d0663f7 100644 --- a/src/test/resources/standardOctaneGherkinReport/multipleSameResults/standard-multipleSame-cucumber-js-final.xml +++ b/src/test/resources/standardOctaneGherkinReport/multipleSameResults/standard-multipleSame-cucumber-js-final.xml @@ -1,287 +1,630 @@ - + + - - - + + & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step]]> + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + + + + (/work/features/step_definitions/steps.js:41:9)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:59:11)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + yum yum yum - scenario outline - description - Given the cow weighs kg - When we calculate the feeding requirements - Then the energy should be MJ + Given the background is ready + + Scenario Outline: Eating of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is Examples: - | name | weight | energy | - | cow1 | 450 | 26500 | - | cow2 | 500 | 29500 |]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + + + + + + + + + & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step]]> + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + + + + (/work/features/step_definitions/steps.js:41:9)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:59:11)]]> + + + + + + + + + + + + + + + + + + + + + + + + yum yum yum - scenario outline - description - Given the cow weighs kg - When we calculate the feeding requirements - Then the energy should be MJ + Given the background is ready + + Scenario Outline: Eating of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is Examples: - | name | weight | energy | - | cow1 | 450 | 26500 | - | cow2 | 500 | 29500 |]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:85:12)]]> - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - - + | count | + | 3 |]]> + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:84:10)]]> + + + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + + + + + + + diff --git a/src/test/resources/standardOctaneGherkinReport/singleResults/standard-single-cucumber-js-final.xml b/src/test/resources/standardOctaneGherkinReport/singleResults/standard-single-cucumber-js-final.xml index e4f91c4..deea193 100644 --- a/src/test/resources/standardOctaneGherkinReport/singleResults/standard-single-cucumber-js-final.xml +++ b/src/test/resources/standardOctaneGherkinReport/singleResults/standard-single-cucumber-js-final.xml @@ -1,162 +1,174 @@ - + + - - - + + yum yum yum - scenario outline - description - Given the cow weighs kg - When we calculate the feeding requirements - Then the energy should be MJ + Scenario: Data table and doc string + Given the following cucumbers: + | colour | count | + | green | 3 | + | red | 1 | + And the following note: + """ + Line one with & "quotes" + Line two + """ + Then the cucumber count is 4 - Examples: - | name | weight | energy | - | cow1 | 450 | 26500 | - | cow1 | 480 | 27500 | - | cow2 | 500 | 29500 |]]> - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:37:10)]]> + + + + + + + + + + (/work/features/step_definitions/steps.js:41:9)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (/work/features/step_definitions/steps.js:59:11)]]> + + + + + + + + + - - - - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - - - - - - - - - - (C:\Users\zousu\Learning\hellocucumber\features\step_definitions\stepdef.js:103:17)]]> - - - - - - +Line one with <xml> & "quotes" +Line two +"""" duration="0" status="passed"> + + + + + + + + + + + + From 5b8219c50808ed54b93032b3d5ebbf381a59fb91 Mon Sep 17 00:00:00 2001 From: Noor Date: Mon, 30 Nov 2026 12:06:25 +0200 Subject: [PATCH 2/5] Support Cucumber-Ruby 12.0.1 junit reports Converting real Cucumber-Ruby 12.0.1 junit reports showed three problems in the cucumber-ruby handler: - When the same step appears twice in a scenario, the first one was reported as failed, even when the second one failed. The failed step is now found by its line in the failure message. If that line is not the failed step, e.g. because the feature file changed after the run, it is matched by name as before. - A scenario that failed in a Before or After hook was reported as passed. Its steps are now reported as skipped with a warning, as for cucumber-js. - Examples rows were matched in report order, so a report of only some rows (e.g. a rerun) assigned results to the wrong rows. Rows are now matched by the values in the testcase name. Rows with the same values are matched in report order. Tests: Cucumber-Ruby 12.0.1 sample features and reports, an integration test with its expected result, and 17 new unit tests in TestCucumberRubyHandler. README: Cucumber-Ruby 12.0.1 is the tested version, with notes on the handler. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Cucumber-JS 13 writes junit reports with its built-in junit formatter: one per scenario or Examples row, with the step results in system-out. The cucumber-js handler now reads this format. The legacy cucumber-junit format (one per scenario, Cucumber-JS 7 and earlier) is no longer supported. - CucumberJsHandler: rewritten for the new format. It matches features by name and scenarios by testcase name (rule, Examples name, row number). It reads step statuses from system-out. Undefined, pending and ambiguous steps are reported as failed. A scenario that failed outside its steps, e.g. in a hook, is reported with skipped steps. - BddFrameworkHandler.getOutlineIndex() (default: empty), OctaneFeature.findScenario(name, outlineIndex), Bdd2Octane: match an Examples row by its reported row number. Other handlers are unchanged and still match rows in report order. - Tests: Cucumber-JS 13.3.0 sample features and reports, new expected results for the 3 Cucumber-JS integration tests, 23 unit tests in TestCucumberJsHandler. The legacy cucumber-junit fixtures are removed. - README: Cucumber-JS 13.3.0 is the tested version, with notes on the new format. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 13 +- .../microfocus/bdd/CucumberRubyHandler.java | 152 ++++++- .../bdd/it/Bdd2OctaneHandlerITCase.java | 2 + .../bdd/ut/TestCucumberRubyHandler.java | 330 ++++++++++++++ .../12.0.1/features/basics.feature | 62 +++ .../12.0.1/features/hooks.feature | 11 + .../12.0.1/features/outlines.feature | 31 ++ .../12.0.1/features/rules.feature | 17 + .../12.0.1/reports/TEST-features-basics.xml | 154 +++++++ .../12.0.1/reports/TEST-features-hooks.xml | 39 ++ .../12.0.1/reports/TEST-features-outlines.xml | 84 ++++ .../12.0.1/reports/TEST-features-rules.xml | 30 ++ .../standard-cucumber-ruby-12.0.1-final.xml | 403 ++++++++++++++++++ 13 files changed, 1309 insertions(+), 19 deletions(-) create mode 100644 src/test/resources/cucumber-ruby/12.0.1/features/basics.feature create mode 100644 src/test/resources/cucumber-ruby/12.0.1/features/hooks.feature create mode 100644 src/test/resources/cucumber-ruby/12.0.1/features/outlines.feature create mode 100644 src/test/resources/cucumber-ruby/12.0.1/features/rules.feature create mode 100644 src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-basics.xml create mode 100644 src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-hooks.xml create mode 100644 src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-outlines.xml create mode 100644 src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-rules.xml create mode 100644 src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-ruby-12.0.1-final.xml diff --git a/README.md b/README.md index db04b64..bf6836a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The following frameworks are currently supported out-of-the-box: > verifed versions: 2.0.0 - 7.0.0, 7.23.0 > unsupported version: 1.2.6 - cucumber-ruby - > verified versions: 4.0.0, 5.0.0, 6.0.0, 7.0.0 + > tested version: 12.0.1, with the junit formatter (since bdd2octane 1.1.14) You can add your own framework by implementing the interface: [BddFrameworkHandler](./src/main/java/com/microfocus/bdd/api/BddFrameworkHandler.java) SpecFlow test result injection is supported via the use of a template file for report generation. See https://marketplace.opentext.com/appdelivery/content/alm-octane-bdd-automation-with-specflow. @@ -73,6 +73,17 @@ SpecFlow test result injection is supported via the use of a template file for r * A failed BeforeAll or AfterAll hook is reported as a testcase of no scenario. It is skipped with a message, so Octane does not show the hook failure. +### Notes on Cucumber-ruby handler + +* The handler reads the report of the junit formatter of Cucumber-ruby, for example + `cucumber --format junit --out reports/junit`. +* The report has no step results or durations. The failed step is the step at the line of the failure message, the + steps before it are reported as passed and the steps after it as skipped. Steps are reported with a duration of 0. +* An Examples row is identified by its values. Rows with the same values are matched in the order of the report, so in + a report of only some of them, for example a rerun, a result can be assigned to another row with the same values. +* A scenario that failed outside its steps, for example in a Before or After hook, is reported with skipped steps and + a warning, because the Octane result can only report failures of steps. + ### Notes on Cucumber-jvm handler * If **useFileNameCompatibleName** is enabled, the space character in a feature name is replaced with underscore(_) in JUnit report, currently the handler doesn't support this configuration. diff --git a/src/main/java/com/microfocus/bdd/CucumberRubyHandler.java b/src/main/java/com/microfocus/bdd/CucumberRubyHandler.java index e959754..4094f52 100644 --- a/src/main/java/com/microfocus/bdd/CucumberRubyHandler.java +++ b/src/main/java/com/microfocus/bdd/CucumberRubyHandler.java @@ -32,21 +32,54 @@ package com.microfocus.bdd; import com.microfocus.bdd.api.*; +import io.cucumber.messages.types.Examples; +import io.cucumber.messages.types.Feature; import io.cucumber.messages.types.FeatureChild; import io.cucumber.messages.types.Rule; import io.cucumber.messages.types.RuleChild; +import io.cucumber.messages.types.Scenario; +import io.cucumber.messages.types.Step; +import io.cucumber.messages.types.TableCell; +import io.cucumber.messages.types.TableRow; +import java.util.List; import java.util.Optional; +import java.util.OptionalInt; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; public class CucumberRubyHandler implements BddFrameworkHandler { + // "features/a.feature:12:in `step text'", in a scenario outline "features/a.feature:16:9:in `step text'" + // with the line of the Examples row before the line of the step + private static final Pattern STEP_LOCATION = Pattern.compile("^.+\\.feature:(?:\\d+:)?(\\d+):in `(.*)'$"); + // the end of the testcase name of an Examples row: " : | cow1 | 450 | 26500 |)" + private static final Pattern EXAMPLE_ROW = Pattern.compile(" : (\\|.*\\|)\\)$"); private Element element; private String errorMessage; private String failedStep; + private long failedStepLine; + private int failedStepIndex = -1; + private int nextStepIndex; private Status statusTag; + private int outlineIndex; @Override public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... octaneFeatureLocator){ + String scenarioName = findScenarioName(feature); + if (failedStepLine > 0) { + int index = findStepIndex(feature.getGherkinDocument().getFeature().get(), failedStepLine); + // the line tells repeated steps apart, unless the report was created from another version of the feature file + if (index >= 0 && feature.getScenarios(scenarioName).stream().anyMatch(scenario -> + index < scenario.getSteps().size() && scenario.getSteps().get(index).getName().equals(failedStep))) { + failedStepIndex = index; + } + } + return scenarioName; + } + + private String findScenarioName(OctaneFeature feature) { String testcaseNameInReport = element.getAttribute("name"); String[] nameParts = testcaseNameInReport.split("\\(outline example", 2); if (nameParts.length == 2) { @@ -54,22 +87,14 @@ public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... oct for (FeatureChild fChild : feature.getGherkinDocument().getFeature().get().getChildren()) { if (fChild.getScenario().isPresent() && fChild.getScenario().get().getName().equals(testcaseName)) { - if (fChild.getScenario().get().getExamples().isEmpty()) { - return testcaseNameInReport; - } else { - return testcaseName; - } + return getScenarioName(feature, fChild.getScenario().get(), testcaseNameInReport, nameParts[1]); } if (fChild.getRule().isPresent()) { Rule rule = fChild.getRule().get(); for (RuleChild rChild : rule.getChildren()) { if (rChild.getScenario().isPresent() && rChild.getScenario().get().getName().equals(testcaseName)) { - if (rChild.getScenario().get().getExamples().isEmpty()) { - return testcaseNameInReport; - } else { - return testcaseName; - } + return getScenarioName(feature, rChild.getScenario().get(), testcaseNameInReport, nameParts[1]); } } } @@ -80,6 +105,92 @@ public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... oct return ""; } + private String getScenarioName(OctaneFeature feature, Scenario scenario, String testcaseNameInReport, String example) { + if (scenario.getExamples().isEmpty()) { + return testcaseNameInReport; + } + outlineIndex = findOutlineIndex(feature, scenario, example); + return scenario.getName(); + } + + // the first row with the values of the example that is not merged yet, so that rows with the same values are + // merged in the order of the report + private static int findOutlineIndex(OctaneFeature feature, Scenario outline, String example) { + Matcher row = EXAMPLE_ROW.matcher(example); + if (!row.find()) { + return 0; + } + int index = 0; + int firstMatch = 0; + for (Examples examples : outline.getExamples()) { + for (TableRow tableRow : examples.getTableBody()) { + index++; + String values = tableRow.getCells().stream().map(TableCell::getValue).collect(Collectors.joining(" | ", "| ", " |")); + if (values.equals(row.group(1))) { + Optional scenario = feature.findScenario(outline.getName(), index); + if (scenario.isPresent() && !scenario.get().isMerged()) { + return index; + } + firstMatch = firstMatch == 0 ? index : firstMatch; + } + } + } + return firstMatch; + } + + @Override + public OptionalInt getOutlineIndex() { + return outlineIndex > 0 ? OptionalInt.of(outlineIndex) : OptionalInt.empty(); + } + + // the index of the step at the line among the steps of its scenario, which start with the steps of the backgrounds + private static int findStepIndex(Feature feature, long line) { + int backgroundSize = 0; + for (FeatureChild child : feature.getChildren()) { + if (child.getBackground().isPresent()) { + int index = indexOf(child.getBackground().get().getSteps(), line); + if (index >= 0) { + return index; + } + backgroundSize = child.getBackground().get().getSteps().size(); + } + if (child.getScenario().isPresent()) { + int index = indexOf(child.getScenario().get().getSteps(), line); + if (index >= 0) { + return backgroundSize + index; + } + } + if (child.getRule().isPresent()) { + int ruleBackgroundSize = 0; + for (RuleChild ruleChild : child.getRule().get().getChildren()) { + if (ruleChild.getBackground().isPresent()) { + int index = indexOf(ruleChild.getBackground().get().getSteps(), line); + if (index >= 0) { + return backgroundSize + index; + } + ruleBackgroundSize = ruleChild.getBackground().get().getSteps().size(); + } + if (ruleChild.getScenario().isPresent()) { + int index = indexOf(ruleChild.getScenario().get().getSteps(), line); + if (index >= 0) { + return backgroundSize + ruleBackgroundSize + index; + } + } + } + } + } + return -1; + } + + private static int indexOf(List steps, long line) { + for (int i = 0; i < steps.size(); i++) { + if (steps.get(i).getLocation().getLine() == line) { + return i; + } + } + return -1; + } + @Override public String getName() { return "cucumber-ruby"; @@ -115,12 +226,12 @@ public void setElement(Element element) { */ errorMessage = child.getText(); + statusTag = Status.FAILED; if (errorMessage != null && !errorMessage.isEmpty()) { - String lastLine = findLastNonEmptyLine(errorMessage); - String[] stepParts = lastLine.split(":in `"); - if (stepParts.length == 2) { - failedStep = stepParts[1].trim().substring(0, stepParts[1].length() - 1); - statusTag = Status.FAILED; + Matcher location = STEP_LOCATION.matcher(findLastNonEmptyLine(errorMessage)); + if (location.find()) { + failedStepLine = Long.parseLong(location.group(1)); + failedStep = location.group(2); } } } else if (child.getName().equals("skipped")) { @@ -137,15 +248,16 @@ private String findLastNonEmptyLine(String message) { return line; } } - return null; + return ""; } @Override public void fillStep(OctaneStep octaneStep) { + int stepIndex = nextStepIndex++; if (statusTag == null) { octaneStep.setStatus(Status.PASSED); - } else if (statusTag.equals(Status.FAILED)) { - if (octaneStep.getName().equals(failedStep)) { + } else if (statusTag.equals(Status.FAILED) && failedStep != null) { + if (failedStepIndex >= 0 ? stepIndex == failedStepIndex : octaneStep.getName().equals(failedStep)) { octaneStep.setStatus(Status.FAILED); octaneStep.setErrorMessage(errorMessage); } else { @@ -154,6 +266,10 @@ public void fillStep(OctaneStep octaneStep) { } else if (statusTag.equals(Status.SKIPPED)) { octaneStep.setStatus(Status.SKIPPED); } else { + // e.g. a hook failed: do not report the failed scenario as passed + System.err.println("Scenario \"" + element.getAttribute("name") + + "\" failed outside its steps, its steps are reported as skipped"); + octaneStep.setStatus(Status.SKIPPED); } } diff --git a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java index 25f02b6..443abb8 100644 --- a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java +++ b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java @@ -105,6 +105,8 @@ public static List data() { {Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/junit5/*.xml", "src/test/resources/features/junit5/*.feature", "separateResults/cucumber-jvm-final19.xml", "**/separateResults/standard-cucumber-jvm-final19.xml"}, //empty feature name - fallback to scenario name lookup {Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/empty-feature-name/TEST-empty-feature-name.xml", "src/test/resources/features/feature_name_is_empty.feature", "separateResults/cucumber-jvm-final20.xml", "**/separateResults/standard-cucumber-jvm-final20.xml"}, + //cucumber-ruby 12.0.1 reports + {Framework.CUCUMBER_RUBY, "src/test/resources/cucumber-ruby/12.0.1/reports/*.xml", "src/test/resources/cucumber-ruby/12.0.1/features/*.feature", "separateResults/cucumber-ruby-12.0.1-final.xml", "**/separateResults/standard-cucumber-ruby-12.0.1-final.xml"}, }); } diff --git a/src/test/java/com/microfocus/bdd/ut/TestCucumberRubyHandler.java b/src/test/java/com/microfocus/bdd/ut/TestCucumberRubyHandler.java index 72fae56..b652e09 100644 --- a/src/test/java/com/microfocus/bdd/ut/TestCucumberRubyHandler.java +++ b/src/test/java/com/microfocus/bdd/ut/TestCucumberRubyHandler.java @@ -31,18 +31,42 @@ */ package com.microfocus.bdd.ut; +import com.microfocus.bdd.Bdd2Octane; import com.microfocus.bdd.CucumberRubyHandler; import com.microfocus.bdd.api.Element; import com.microfocus.bdd.JunitReportReader; +import com.microfocus.bdd.api.OctaneFeature; +import com.microfocus.bdd.api.OctaneScenario; +import com.microfocus.bdd.api.OctaneStep; +import com.microfocus.bdd.api.Status; import org.junit.Assert; import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.stream.XMLStreamException; +import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; +import java.util.List; + +import static com.microfocus.bdd.api.Status.FAILED; +import static com.microfocus.bdd.api.Status.PASSED; +import static com.microfocus.bdd.api.Status.SKIPPED; public class TestCucumberRubyHandler { + private static final String SAMPLE = "src/test/resources/cucumber-ruby/12.0.1/"; + @Test public void testRubyHandler() throws FileNotFoundException, XMLStreamException { CucumberRubyHandler handler = new CucumberRubyHandler(); @@ -55,4 +79,310 @@ public void testRubyHandler() throws FileNotFoundException, XMLStreamException { "Some determinable business situation", handler.getScenarioName(null)); } + + @Test + public void testNameAndTestCaseElement() { + CucumberRubyHandler handler = new CucumberRubyHandler(); + Assert.assertEquals("cucumber-ruby", handler.getName()); + Assert.assertEquals("testcase", handler.getTestCaseElementName()); + } + + @Test + public void testPassedScenario() { + CucumberRubyHandler handler = getHandler("basics", "All steps pass"); + Assert.assertEquals("Latest basics", handler.getFeatureName().get()); + Assert.assertFalse("the report has no feature file", handler.getFeatureFile().isPresent()); + assertScenario(handler, sampleFeature("basics"), "All steps pass", 0, PASSED, PASSED, PASSED, PASSED); + } + + @Test + public void testFailedScenarios() { + for (String scenario : Arrays.asList("Middle step fails", "Step raises an error", "Undefined step", "Pending step", "Ambiguous step")) { + assertScenario(getHandler("basics", scenario), sampleFeature("basics"), scenario, 0, PASSED, PASSED, FAILED, SKIPPED); + } + } + + @Test + public void testSkippedScenario() { + assertScenario(getHandler("basics", "Skipped scenario"), sampleFeature("basics"), "Skipped scenario", 0, + SKIPPED, SKIPPED, SKIPPED, SKIPPED); + } + + @Test + public void testDataTableAndDocString() { + assertScenario(getHandler("basics", "Data table and doc string"), sampleFeature("basics"), "Data table and doc string", 0, + PASSED, PASSED, PASSED, PASSED); + } + + @Test + public void testRepeatedIdenticalSteps() { + // the line of the failure tells the two "the counter is incremented" steps apart + assertScenario(getHandler("basics", "Repeated identical steps"), sampleFeature("basics"), "Repeated identical steps", 0, + PASSED, PASSED, PASSED, FAILED, SKIPPED); + } + + @Test + public void testLineOfAnotherStep() { + // e.g. the feature file changed after the run: the first step with the name of the failed step fails + for (int line : new int[]{42, 43}) { + // line 42 is "Scenario: Repeated identical steps", line 43 is "Given a passing step" + CucumberRubyHandler handler = getHandler(testcase("Latest basics", "Repeated identical steps", + "features/basics.feature:" + line + ":in `the counter is incremented'")); + assertScenario(handler, sampleFeature("basics"), "Repeated identical steps", 0, PASSED, PASSED, FAILED, SKIPPED, SKIPPED); + } + } + + @Test + public void testRepeatedStepsInBackgrounds() throws IOException { + // all the steps are "a passing step": the line of the failure tells them apart + OctaneFeature feature = repeatedStepsFeature(); + assertFailedStepAtEachLine(feature, "Repeated in backgrounds", 4, 8, 11, 12); + assertFailedStepAtEachLine(feature, "Repeated without rule background", 4, 26, 27); + OctaneFeature noBackground = writeFeature("cucumber-ruby-no-background.feature", + "Feature: No background", + "", + " Scenario: Repeated without background", + " Given a passing step", + " Then a passing step"); + assertFailedStepAtEachLine(noBackground, "Repeated without background", 4, 5); + } + + @Test + public void testHookFails() { + for (String scenario : Arrays.asList("Before hook fails", "After hook fails")) { + assertScenario(getHandler("hooks", scenario), sampleFeature("hooks"), scenario, 0, SKIPPED, SKIPPED); + } + } + + @Test + public void testFailureWithoutText() { + CucumberRubyHandler handler = getHandler("" + + ""); + assertScenario(handler, sampleFeature("hooks"), "Before hook fails", 0, SKIPPED, SKIPPED); + } + + @Test + public void testRuleScenario() { + assertScenario(getHandler("rules", "Rule scenario fails"), sampleFeature("rules"), "Rule scenario fails", 0, + PASSED, PASSED, PASSED, FAILED); + } + + @Test + public void testOutlineRows() { + OctaneFeature feature = sampleFeature("outlines"); + String outline = "Eating of cucumbers"; + assertScenario(getHandler("outlines", outline + " (outline example : | 12 | 5 | 7 |)"), feature, outline, 1, PASSED, PASSED, PASSED, PASSED); + assertScenario(getHandler("outlines", outline + " (outline example : | 20 | 5 | 14 |)"), feature, outline, 2, PASSED, PASSED, PASSED, FAILED); + assertScenario(getHandler("outlines", outline + " (outline example : | 100 | 1 | 99 |)"), feature, outline, 3, PASSED, PASSED, PASSED, PASSED); + assertScenario(getHandler("outlines", outline + " (outline example : | 12 | 5 | 8 |)"), feature, outline, 4, PASSED, PASSED, PASSED, FAILED); + assertScenario(getHandler("outlines", "Counting cucumbers (outline example : | 3 |)"), feature, "Counting cucumbers", 1, PASSED, PASSED, PASSED); + } + + @Test + public void testOutlineRowsWithSameValues() throws IOException { + // rows with the same values are merged in the order of the report + OctaneFeature feature = repeatedStepsFeature(); + String outline = "Same rows "; + assertOutlineRow(feature, outline, "| 1 |", 1); + feature.findScenario(outline, 1).get().markMerged(); + assertOutlineRow(feature, outline, "| 1 |", 3); + // all the rows with the values are merged, e.g. "cucumber --retry" reports each attempt: the first one is merged again + feature.findScenario(outline, 3).get().markMerged(); + assertOutlineRow(feature, outline, "| 1 |", 1); + assertOutlineRow(feature, outline, "| 2 |", 2); + } + + @Test + public void testOutlineRowsWithSpecialValues() throws IOException { + // the rows as cucumber 12.0.1 names them, with the cell values joined by " | " + OctaneFeature feature = writeFeature("cucumber-ruby-special.feature", + "Feature: Special values", + "", + " Scenario Outline: Special ", + " Given the value is \"\"", + "", + " Examples:", + " | value |", + " | a \\| b |", + " | |", + " | \u00fcn\u00ef |", + " | a (b) c |", + "", + " Scenario Outline: Two columns ", + " Given the value is \"\"", + " And the value is \"\"", + "", + " Examples:", + " | a | b |", + " | | x |", + " | y | |"); + assertOutlineRow(feature, "Special ", "| a | b |", 1); + assertOutlineRow(feature, "Special ", "| |", 2); + assertOutlineRow(feature, "Special ", "| \u00fcn\u00ef |", 3); + assertOutlineRow(feature, "Special ", "| a (b) c |", 4); + assertOutlineRow(feature, "Two columns ", "| | x |", 1); + assertOutlineRow(feature, "Two columns ", "| y | |", 2); + } + + @Test + public void testOutlineRowNotInFeature() { + // e.g. the feature file changed after the run: the rows are merged in the order of the report + assertOutlineRow(sampleFeature("outlines"), "Eating of cucumbers", "| 1 | 2 | 3 |", 0); + } + + @Test + public void testOutlineNotInFeature() { + CucumberRubyHandler handler = getHandler(testcase("Latest outlines", "Unknown (outline example : | 1 |)", null)); + Assert.assertEquals("Bdd2Octane skips a testcase without scenario name", "", handler.getScenarioName(sampleFeature("outlines"))); + Assert.assertFalse(handler.getOutlineIndex().isPresent()); + } + + @Test + public void testReportOfOneExamplesRow() throws Exception { + // e.g. "cucumber features/outlines.feature:19" runs the last row of "Many" only + String report = new String(Files.readAllBytes(Paths.get(SAMPLE + "reports/TEST-features-outlines.xml")), StandardCharsets.UTF_8); + int start = report.indexOf("", start) + "".length()); + Path reportFile = Paths.get("target", "cucumber-ruby-one-examples-row.xml"); + Path resultFile = Paths.get("target", "cucumber-ruby-one-examples-row-result.xml"); + Files.write(reportFile, ("\n\n" + row + "\n\n") + .getBytes(StandardCharsets.UTF_8)); + + new Bdd2Octane(Collections.singletonList(reportFile.toString()), + Collections.singletonList(SAMPLE + "features/outlines.feature"), resultFile.toString(), "cucumber-ruby").run(); + + Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(resultFile.toFile()); + NodeList scenarios = result.getElementsByTagName("scenario"); + Assert.assertEquals("only the reported row is in the result", 1, scenarios.getLength()); + org.w3c.dom.Element scenario = (org.w3c.dom.Element) scenarios.item(0); + Assert.assertEquals("the row is matched by its values, not by its order", "4", scenario.getAttribute("outlineIndex")); + NodeList steps = scenario.getElementsByTagName("step"); + List statuses = new ArrayList<>(); + for (int i = 0; i < steps.getLength(); i++) { + statuses.add(((org.w3c.dom.Element) steps.item(i)).getAttribute("status")); + } + Assert.assertEquals(Arrays.asList("passed", "passed", "passed", "failed"), statuses); + org.w3c.dom.Element failedStep = (org.w3c.dom.Element) steps.item(3); + Assert.assertEquals("Then I should have 8 cucumbers", failedStep.getAttribute("name")); + Assert.assertTrue("the failure is the error message of the failed step", + failedStep.getTextContent().contains("7 != 8 (RuntimeError)")); + } + + private static OctaneFeature sampleFeature(String name) { + return TestUtil.parseFeatureFile(SAMPLE + "features/" + name + ".feature"); + } + + private static OctaneFeature repeatedStepsFeature() throws IOException { + return writeFeature("cucumber-ruby-repeated.feature", + "Feature: Repeated steps", + "", + " Background:", + " Given a passing step", + "", + " Rule: A rule", + " Background:", + " Given a passing step", + "", + " Scenario: Repeated in backgrounds", + " Given a passing step", + " Then a passing step", + "", + " Scenario Outline: Same rows ", + " Given a passing step", + "", + " Examples:", + " | value |", + " | 1 |", + " | 2 |", + " | 1 |", + "", + " Rule: Another rule", + "", + " Scenario: Repeated without rule background", + " Given a passing step", + " Then a passing step"); + } + + private static OctaneFeature writeFeature(String fileName, String... lines) throws IOException { + Path featureFile = Paths.get("target", fileName); + Files.write(featureFile, (String.join("\n", lines) + "\n").getBytes(StandardCharsets.UTF_8)); + return TestUtil.parseFeatureFile(featureFile.toString()); + } + + // fails the scenario at each of the given lines of its steps, which are all "a passing step" + private static void assertFailedStepAtEachLine(OctaneFeature feature, String scenarioName, int... stepLines) { + for (int i = 0; i < stepLines.length; i++) { + CucumberRubyHandler handler = getHandler(testcase(feature.getName(), scenarioName, + "features/a.feature:" + stepLines[i] + ":in `a passing step'")); + Status[] statuses = new Status[stepLines.length]; + Arrays.fill(statuses, 0, i, PASSED); + statuses[i] = FAILED; + Arrays.fill(statuses, i + 1, statuses.length, SKIPPED); + assertScenario(handler, feature, scenarioName, 0, statuses); + } + } + + private static void assertOutlineRow(OctaneFeature feature, String outline, String row, int outlineIndex) { + CucumberRubyHandler handler = getHandler(testcase(feature.getName(), outline + " (outline example : " + row + ")", null)); + Assert.assertEquals(outline, handler.getScenarioName(feature)); + Assert.assertEquals("outline index of " + row, outlineIndex, handler.getOutlineIndex().orElse(0)); + } + + // a testcase that failed at the step location, or passed if the location is null + private static String testcase(String classname, String name, String failedStepLocation) { + String failure = failedStepLocation == null ? "" + : ""; + return "", ">") + + "\" time=\"0\">" + failure + ""; + } + + private static CucumberRubyHandler getHandler(String testcaseXml) { + String report = "" + testcaseXml + ""; + try (JunitReportReader reader = new JunitReportReader( + new ByteArrayInputStream(report.getBytes(StandardCharsets.UTF_8)), "testcase")) { + CucumberRubyHandler handler = new CucumberRubyHandler(); + handler.setElement(reader.iterator().next()); + return handler; + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + } + + private static CucumberRubyHandler getHandler(String feature, String testcaseName) { + String report = SAMPLE + "reports/TEST-features-" + feature + ".xml"; + try (JunitReportReader reader = new JunitReportReader(new FileInputStream(report), "testcase")) { + for (Element element : reader) { + if (testcaseName.equals(element.getAttribute("name"))) { + CucumberRubyHandler handler = new CucumberRubyHandler(); + handler.setElement(element); + return handler; + } + } + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + throw new IllegalArgumentException("No testcase \"" + testcaseName + "\" in " + report); + } + + private static void assertScenario(CucumberRubyHandler handler, OctaneFeature feature, String scenarioName, int outlineIndex, + Status... statuses) { + Assert.assertEquals("handler can get back scenario name", scenarioName, handler.getScenarioName(feature)); + Assert.assertEquals("handler can get back outline index", outlineIndex, handler.getOutlineIndex().orElse(0)); + OctaneScenario scenario = feature.getScenarios(scenarioName).get(Math.max(outlineIndex - 1, 0)); + Assert.assertEquals("handler can get back step statuses", Arrays.asList(statuses), fillSteps(handler, scenario)); + } + + // as Bdd2Octane does, the steps after the first step that did not pass are skipped + private static List fillSteps(CucumberRubyHandler handler, OctaneScenario scenario) { + List statuses = new ArrayList<>(); + for (OctaneStep step : scenario.getSteps()) { + if (statuses.isEmpty() || statuses.get(statuses.size() - 1) == PASSED) { + handler.fillStep(step); + statuses.add(step.getStatus()); + } else { + statuses.add(SKIPPED); + } + } + return statuses; + } } diff --git a/src/test/resources/cucumber-ruby/12.0.1/features/basics.feature b/src/test/resources/cucumber-ruby/12.0.1/features/basics.feature new file mode 100644 index 0000000..ff65467 --- /dev/null +++ b/src/test/resources/cucumber-ruby/12.0.1/features/basics.feature @@ -0,0 +1,62 @@ +@BSPID2001REV0.1.0 +Feature: Latest basics + + Background: + Given the background is ready + + Scenario: All steps pass + Given a passing step + When another passing step + Then a final passing step + + Scenario: Middle step fails + Given a passing step + When a step that fails with "middle step failure" + Then a final passing step + + Scenario: Step raises an error + Given a passing step + When a step that raises an error + Then a final passing step + + Scenario: Undefined step + Given a passing step + When a step without any definition + Then a final passing step + + Scenario: Pending step + Given a passing step + When a pending step + Then a final passing step + + Scenario: Ambiguous step + Given a passing step + When an ambiguous step + Then a final passing step + + Scenario: Skipped scenario + Given a passing step + When a step that skips the scenario + Then a final passing step + + Scenario: Repeated identical steps + Given a passing step + When the counter is incremented + And the counter is incremented + Then a final passing step + + Scenario: Data table and doc string + Given the following cucumbers: + | colour | count | + | green | 3 | + | red | 1 | + And the following note: + """ + Line one with & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step diff --git a/src/test/resources/cucumber-ruby/12.0.1/features/hooks.feature b/src/test/resources/cucumber-ruby/12.0.1/features/hooks.feature new file mode 100644 index 0000000..f072229 --- /dev/null +++ b/src/test/resources/cucumber-ruby/12.0.1/features/hooks.feature @@ -0,0 +1,11 @@ +Feature: Latest hooks + + @failing-before-hook + Scenario: Before hook fails + Given a passing step + Then a final passing step + + @failing-after-hook + Scenario: After hook fails + Given a passing step + Then a final passing step diff --git a/src/test/resources/cucumber-ruby/12.0.1/features/outlines.feature b/src/test/resources/cucumber-ruby/12.0.1/features/outlines.feature new file mode 100644 index 0000000..0d36d4c --- /dev/null +++ b/src/test/resources/cucumber-ruby/12.0.1/features/outlines.feature @@ -0,0 +1,31 @@ +Feature: Latest outlines + + Background: + Given the background is ready + + Scenario Outline: Eating of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 | diff --git a/src/test/resources/cucumber-ruby/12.0.1/features/rules.feature b/src/test/resources/cucumber-ruby/12.0.1/features/rules.feature new file mode 100644 index 0000000..2c5a8b1 --- /dev/null +++ b/src/test/resources/cucumber-ruby/12.0.1/features/rules.feature @@ -0,0 +1,17 @@ +Feature: Latest rules + + Background: + Given the background is ready + + Rule: First rule + Background: + Given a rule background step + + Scenario: Rule scenario fails + Given a passing step + Then a step that fails with "rule failure" + + Rule: Second rule + Scenario: Rule scenario passes + Given a passing step + Then a final passing step diff --git a/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-basics.xml b/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-basics.xml new file mode 100644 index 0000000..ec72459 --- /dev/null +++ b/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-basics.xml @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-hooks.xml b/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-hooks.xml new file mode 100644 index 0000000..989ea84 --- /dev/null +++ b/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-hooks.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-outlines.xml b/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-outlines.xml new file mode 100644 index 0000000..7e9f0de --- /dev/null +++ b/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-outlines.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + of cucumbers + +Example row: | 20 | 5 | 14 | + +Message: +]]> + + + + + + + + + + + + + + + + + + + + of cucumbers + +Example row: | 12 | 5 | 8 | + +Message: +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-rules.xml b/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-rules.xml new file mode 100644 index 0000000..63e4639 --- /dev/null +++ b/src/test/resources/cucumber-ruby/12.0.1/reports/TEST-features-rules.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-ruby-12.0.1-final.xml b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-ruby-12.0.1-final.xml new file mode 100644 index 0000000..5637bca --- /dev/null +++ b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-ruby-12.0.1-final.xml @@ -0,0 +1,403 @@ + + + + + + & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 |]]> + + + + + + + + + + + + + + + + + of cucumbers + +Example row: | 20 | 5 | 14 | + +Message: +15 != 14 (RuntimeError) +./features/step_definitions/steps.rb:55:in `"I should have {int} cucumbers"' +features/outlines.feature:14:9:in `I should have 14 cucumbers']]> + + + + + + + + + + + + + + + + + + of cucumbers + +Example row: | 12 | 5 | 8 | + +Message: +7 != 8 (RuntimeError) +./features/step_definitions/steps.rb:55:in `"I should have {int} cucumbers"' +features/outlines.feature:19:9:in `I should have 8 cucumbers']]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b46a912cbaca5673a6bea683ededb8b349f399ce Mon Sep 17 00:00:00 2001 From: Noor Date: Mon, 30 Nov 2026 14:14:00 +0200 Subject: [PATCH 3/5] Support Behave 1.3.3 junit reports Converting real Behave 1.3.3 junit reports showed that the python-behave handler ignored the step results in system-out and lost hook failures. The handler now: - Reads the status and duration of each step from the scenario text in system-out. Durations are written in nanoseconds, the unit of Octane step durations. In a skipped scenario, the steps that passed are now reported as passed. Repeated identical steps are told apart by their order. - Reports the failure of a before_scenario or after_scenario hook on the first step that did not pass, or on the last step if all of them passed, or on the first step if the report has no step results. Such scenarios used to be reported as passed. If the scenario has no steps, the conversion fails with an error. - Identifies an Examples row by the "@." in its name. A report of only some rows, e.g. from behave --no-skipped, is then mapped to the right rows. Tests: Behave 1.3.3 sample features and reports, an integration test with its expected result, and 15 new unit tests in TestPythonBehaveHandler. The step statuses and durations in the 3 existing Behave expected files and in one unit test assertion are updated, verified against their reports. README: Behave 1.3.3 is the tested version, with notes on the handler. --- README.md | 14 +- .../microfocus/bdd/PythonBehaveHandler.java | 113 ++++++ .../bdd/it/Bdd2OctaneHandlerITCase.java | 2 + .../bdd/ut/TestPythonBehaveHandler.java | 326 ++++++++++++++- .../1.3.3/features/basics.feature | 57 +++ .../1.3.3/features/hooks.feature | 11 + .../1.3.3/features/outlines.feature | 31 ++ .../1.3.3/features/rules.feature | 17 + .../1.3.3/reports/TESTS-basics.xml | 161 ++++++++ .../1.3.3/reports/TESTS-hooks.xml | 47 +++ .../1.3.3/reports/TESTS-outlines.xml | 86 ++++ .../1.3.3/reports/TESTS-rules.xml | 29 ++ ...-multipleDifferent-python-behave-final.xml | 32 +- ...ndard-multipleSame-python-behave-final.xml | 44 +-- .../standard-python-behave-1.3.3-final.xml | 373 ++++++++++++++++++ .../standard-single-python-behave-final.xml | 22 +- 16 files changed, 1312 insertions(+), 53 deletions(-) create mode 100644 src/test/resources/python-behave/1.3.3/features/basics.feature create mode 100644 src/test/resources/python-behave/1.3.3/features/hooks.feature create mode 100644 src/test/resources/python-behave/1.3.3/features/outlines.feature create mode 100644 src/test/resources/python-behave/1.3.3/features/rules.feature create mode 100644 src/test/resources/python-behave/1.3.3/reports/TESTS-basics.xml create mode 100644 src/test/resources/python-behave/1.3.3/reports/TESTS-hooks.xml create mode 100644 src/test/resources/python-behave/1.3.3/reports/TESTS-outlines.xml create mode 100644 src/test/resources/python-behave/1.3.3/reports/TESTS-rules.xml create mode 100644 src/test/resources/standardOctaneGherkinReport/separateResults/standard-python-behave-1.3.3-final.xml diff --git a/README.md b/README.md index bf6836a..80183d7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The following frameworks are currently supported out-of-the-box: - python-radish > verified versions: 0.13.2, 0.13.4 - python-behave - > verified versions: 1.2.5, 1.2.6 + > tested version: 1.3.3, with the JUnit reporter (since bdd2octane 1.1.14) - cucumber-jvm > verifed versions: 2.0.0 - 7.0.0, 7.23.0 > unsupported version: 1.2.6 @@ -84,6 +84,18 @@ SpecFlow test result injection is supported via the use of a template file for r * A scenario that failed outside its steps, for example in a Before or After hook, is reported with skipped steps and a warning, because the Octane result can only report failures of steps. +### Notes on Python-behave handler + +* The handler reads the report of the JUnit reporter of behave, for example + `behave features --junit --junit-directory reports/junit`. The status and duration of each step are read from the + scenario text in system-out. +* An Examples row is identified by the `@.` of its name, as in the default + `scenario_outline_annotation_schema`. With another schema, the rows are matched in the order of the report. +* The failure of a before_scenario or after_scenario hook is reported on the first step that did not pass, or on the + last step if all of them passed, or on the first step if the report has no step results. If the scenario has no steps, + the conversion fails with an error. +* The report does not record the failure of a before_feature or after_feature hook. + ### Notes on Cucumber-jvm handler * If **useFileNameCompatibleName** is enabled, the space character in a feature name is replaced with underscore(_) in JUnit report, currently the handler doesn't support this configuration. diff --git a/src/main/java/com/microfocus/bdd/PythonBehaveHandler.java b/src/main/java/com/microfocus/bdd/PythonBehaveHandler.java index 624a0e4..358ac82 100644 --- a/src/main/java/com/microfocus/bdd/PythonBehaveHandler.java +++ b/src/main/java/com/microfocus/bdd/PythonBehaveHandler.java @@ -32,15 +32,37 @@ package com.microfocus.bdd; import com.microfocus.bdd.api.*; +import io.cucumber.messages.types.FeatureChild; +import io.cucumber.messages.types.Scenario; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Optional; +import java.util.OptionalInt; +import java.util.regex.MatchResult; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class PythonBehaveHandler implements BddFrameworkHandler { + // a step in the scenario text of system-out: " Given a step ... passed in 0.001s" + private static final Pattern STEP_RESULT = Pattern.compile("^\\s*(.+) \\.\\.\\. (\\w+)(?: in (\\d+(?:\\.\\d+)?)s)?$"); + // the end of the name of an Examples row, e.g. " -- @2.1 Many" for the first row of the second Examples + private static final Pattern EXAMPLE_ROW = Pattern.compile("^ -- @(\\d+)\\.(\\d+)(?: .*)?$"); + private static final List FAILED_STATUSES = Arrays.asList("failed", "error", "hook_error", "undefined", "pending", "cleanup_error"); + private Element element; private String errorMessage; private Optional featureFilePath = Optional.empty(); private Optional failedStepName = Optional.empty(); private boolean isSkipped = false; + private final List stepResults = new ArrayList<>(); + private int nextStepResult; + // the step result that reports a failure outside the steps, e.g. of a before_scenario or after_scenario hook + private int hookFailureResult = -1; + private String hookFailureMessage; + private boolean hookFailureReported; + private int outlineIndex; @Override public String getName() { @@ -61,6 +83,28 @@ public void setElement(Element element) { isSkipped = true; } } + element.getChild("system-out").ifPresent(systemOut -> { + String text = systemOut.getText(); + int end = text.indexOf("@scenario.end"); + // the steps are in the scenario text, before the captured output + for (String line : (end < 0 ? text : text.substring(0, end)).split("\n")) { + Matcher stepResult = STEP_RESULT.matcher(line); + if (stepResult.matches()) { + stepResults.add(stepResult.toMatchResult()); + } + } + }); + if (errorMessage != null && !failedStepName.isPresent() + && stepResults.stream().noneMatch(stepResult -> FAILED_STATUSES.contains(stepResult.group(2)))) { + // the failure is reported on the first step that did not pass, or on the last step if all of them passed + String message = element.getChildren().get(0).getAttribute("message"); + hookFailureMessage = message == null ? errorMessage : message + "\n" + errorMessage; + for (hookFailureResult = 0; hookFailureResult < stepResults.size() - 1; hookFailureResult++) { + if (!stepResults.get(hookFailureResult).group(2).equals("passed")) { + break; + } + } + } } private Optional findFeatureFile(String wholeMessage) { @@ -96,20 +140,69 @@ public Optional getFeatureFile() { @Override public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... octaneFeatureLocator) { + String scenarioName = findScenarioName(feature); + if (hookFailureMessage != null && scenarioName != null && !feature.getScenarios(scenarioName).isEmpty() + && feature.getScenarios(scenarioName).stream().allMatch(scenario -> scenario.getSteps().isEmpty())) { + throw new IllegalStateException("Scenario \"" + element.getAttribute("name") + "\" failed outside its steps (" + + hookFailureMessage.split("\n")[0] + "), and has no step to report the failure"); + } + return scenarioName; + } + + private String findScenarioName(OctaneFeature feature) { String sceName = element.getAttribute("name"); if (!feature.getScenarios(sceName).isEmpty()) { return sceName; } for (OctaneScenario sce : feature.getScenarios()) { if (sceName.startsWith(sce.getOutlineName())) { + Matcher row = EXAMPLE_ROW.matcher(sceName.substring(sce.getOutlineName().length())); + if (row.matches()) { + outlineIndex = findOutlineIndex(feature, sce.getName(), Integer.parseInt(row.group(1)), Integer.parseInt(row.group(2))); + } return (sce.getName()); } } return null; } + // the index of the row among the rows of all the Examples of the outline + private static int findOutlineIndex(OctaneFeature feature, String outlineName, int examples, int row) { + List scenarios = new ArrayList<>(); + for (FeatureChild child : feature.getGherkinDocument().getFeature().get().getChildren()) { + child.getScenario().ifPresent(scenarios::add); + child.getRule().ifPresent(rule -> rule.getChildren().forEach(ruleChild -> ruleChild.getScenario().ifPresent(scenarios::add))); + } + for (Scenario scenario : scenarios) { + if (scenario.getName().equals(outlineName) && examples <= scenario.getExamples().size() + && row <= scenario.getExamples().get(examples - 1).getTableBody().size()) { + return scenario.getExamples().subList(0, examples - 1).stream().mapToInt(e -> e.getTableBody().size()).sum() + row; + } + } + return 0; + } + + @Override + public OptionalInt getOutlineIndex() { + return outlineIndex > 0 ? OptionalInt.of(outlineIndex) : OptionalInt.empty(); + } + @Override public void fillStep(OctaneStep octaneStep) { + for (int i = nextStepResult; i < stepResults.size(); i++) { + if (stepResults.get(i).group(1).equals(octaneStep.getCompleteStepName())) { + nextStepResult = i + 1; + fillStep(octaneStep, stepResults.get(i), i == hookFailureResult); + return; + } + } + if (hookFailureMessage != null && !hookFailureReported) { + // the report has no result of the step, e.g. without the scenario text in system-out + hookFailureReported = true; + octaneStep.setStatus(Status.FAILED); + octaneStep.setErrorMessage(hookFailureMessage); + return; + } if (isSkipped) { octaneStep.setStatus(Status.SKIPPED); return; @@ -127,6 +220,26 @@ public void fillStep(OctaneStep octaneStep) { } } + private void fillStep(OctaneStep octaneStep, MatchResult stepResult, boolean hookFailure) { + if (stepResult.group(3) != null) { + // the duration of an Octane step is in nanoseconds + octaneStep.setDuration(Math.round(Double.parseDouble(stepResult.group(3)) * 1_000_000_000)); + } + String status = stepResult.group(2); + if (hookFailure) { + hookFailureReported = true; + octaneStep.setStatus(Status.FAILED); + octaneStep.setErrorMessage(hookFailureMessage); + } else if (status.equals("passed")) { + octaneStep.setStatus(Status.PASSED); + } else if (FAILED_STATUSES.contains(status)) { + octaneStep.setStatus(Status.FAILED); + octaneStep.setErrorMessage(errorMessage != null ? errorMessage : "The step is " + status); + } else { + octaneStep.setStatus(Status.SKIPPED); + } + } + @Override public String getTestCaseElementName() { return "testcase"; diff --git a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java index 443abb8..6e1a995 100644 --- a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java +++ b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java @@ -107,6 +107,8 @@ public static List data() { {Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/empty-feature-name/TEST-empty-feature-name.xml", "src/test/resources/features/feature_name_is_empty.feature", "separateResults/cucumber-jvm-final20.xml", "**/separateResults/standard-cucumber-jvm-final20.xml"}, //cucumber-ruby 12.0.1 reports {Framework.CUCUMBER_RUBY, "src/test/resources/cucumber-ruby/12.0.1/reports/*.xml", "src/test/resources/cucumber-ruby/12.0.1/features/*.feature", "separateResults/cucumber-ruby-12.0.1-final.xml", "**/separateResults/standard-cucumber-ruby-12.0.1-final.xml"}, + //python-behave 1.3.3 reports + {Framework.PYTHON_BEHAVE, "src/test/resources/python-behave/1.3.3/reports/*.xml", "src/test/resources/python-behave/1.3.3/features/*.feature", "separateResults/python-behave-1.3.3-final.xml", "**/separateResults/standard-python-behave-1.3.3-final.xml"}, }); } diff --git a/src/test/java/com/microfocus/bdd/ut/TestPythonBehaveHandler.java b/src/test/java/com/microfocus/bdd/ut/TestPythonBehaveHandler.java index 408e7f2..47058b6 100644 --- a/src/test/java/com/microfocus/bdd/ut/TestPythonBehaveHandler.java +++ b/src/test/java/com/microfocus/bdd/ut/TestPythonBehaveHandler.java @@ -32,12 +32,38 @@ package com.microfocus.bdd.ut; import com.microfocus.bdd.api.*; +import com.microfocus.bdd.Bdd2Octane; +import com.microfocus.bdd.JunitReportReader; import com.microfocus.bdd.PythonBehaveHandler; import org.junit.Before; import org.junit.Test; import org.junit.Assert; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static com.microfocus.bdd.api.Status.FAILED; +import static com.microfocus.bdd.api.Status.PASSED; +import static com.microfocus.bdd.api.Status.SKIPPED; public class TestPythonBehaveHandler { + private static final String SAMPLE = "src/test/resources/python-behave/1.3.3/"; private OctaneFeature octaneFeature; @Before @@ -91,9 +117,9 @@ public void testPassSkipFailedScenario() { handler.getScenarioName(octaneFeature)); Assert.assertEquals("handler can get back file path", "features/dealer.feature", handler.getFeatureFile().get()); - OctaneStep passStep = new OctaneStep("Then", "some testable outcome is achieved", null, null, null); - handler.fillStep(passStep); - Assert.assertTrue("Handle recognize passed status", passStep.getStatus()==Status.PASSED); + OctaneStep skippedStep = new OctaneStep("Then", "some testable outcome is achieved", null, null, null); + handler.fillStep(skippedStep); + Assert.assertTrue("Handle recognize skipped status", skippedStep.getStatus()==Status.SKIPPED); OctaneStep failedStep = new OctaneStep( "Given", "the following people exist:", null, null, null); handler.fillStep(failedStep); @@ -127,6 +153,300 @@ public void testOutlineScenario() { Assert.assertEquals("handler can get back scenario name", "feeding a cow yum yum yum", scenarioName); } + @Test + public void testStepResultsAndDurations() { + // "When another passing step ... passed in 0.250s" + List steps = assertScenario(getHandler("basics", "All steps pass"), sampleFeature("basics"), + "All steps pass", 0, PASSED, PASSED, PASSED, PASSED); + Assert.assertEquals("the duration of an Octane step is in nanoseconds", + Arrays.asList("0", "0", "250000000", "0"), steps.stream().map(step -> attribute(step, "duration")).collect(Collectors.toList())); + } + + @Test + public void testFailedSteps() { + List scenarios = Arrays.asList("Middle step fails", "Step raises an error", "Undefined step", "Pending step"); + List messages = Arrays.asList("ASSERT FAILED: middle step failure", "TypeError: unexpected error", + "When a step without any definition ... undefined", "StepNotImplementedError: a pending step"); + for (int i = 0; i < scenarios.size(); i++) { + List steps = assertScenario(getHandler("basics", scenarios.get(i)), sampleFeature("basics"), scenarios.get(i), 0, + PASSED, PASSED, FAILED, SKIPPED); + Assert.assertTrue(scenarios.get(i), stepXml(steps.get(2)).contains(messages.get(i))); + } + } + + @Test + public void testSkippedScenario() { + // the steps before the step that skipped the scenario passed + assertScenario(getHandler("basics", "Skipped scenario"), sampleFeature("basics"), "Skipped scenario", 0, + PASSED, PASSED, SKIPPED, SKIPPED); + } + + @Test + public void testRepeatedIdenticalSteps() throws IOException { + assertScenario(getHandler("basics", "Repeated identical steps"), sampleFeature("basics"), "Repeated identical steps", 0, + PASSED, PASSED, PASSED, FAILED, SKIPPED); + // the steps are told apart by their order in system-out, not by the name of the failing step + PythonBehaveHandler handler = getHandler(testcase("Repeated steps", "error", + "Failing step: * a passing step ... failed in 0.000s\nLocation: features/a.feature:6\nASSERT FAILED: second", + "Given a passing step ... passed in 0.000s", "* a passing step ... passed in 0.000s", "* a passing step ... failed in 0.000s")); + assertScenario(handler, behaveFeature(), "Repeated steps", 0, PASSED, PASSED, FAILED); + } + + @Test + public void testScenarioHookFails() throws IOException { + // the failure is reported on the first step that did not pass, or on the last step if all of them passed + List steps = assertScenario(getHandler("hooks", "Before hook fails"), sampleFeature("hooks"), "Before hook fails", 0, + FAILED, SKIPPED); + Assert.assertTrue(stepXml(steps.get(0)).contains("HOOK-ERROR in before_scenario: RuntimeError: before hook failure")); + steps = assertScenario(getHandler("hooks", "After hook fails"), sampleFeature("hooks"), "After hook fails", 0, + PASSED, FAILED); + Assert.assertTrue(stepXml(steps.get(1)).contains("HOOK-ERROR in after_scenario: RuntimeError: after hook failure")); + // a scenario that skipped itself, and then failed in its after_scenario hook + PythonBehaveHandler handler = getHandler("" + + "" + + ""); + assertScenario(handler, behaveFeature(), "Skipped in the middle", 0, PASSED, FAILED, SKIPPED); + } + + @Test + public void testScenarioHookFailsWithoutScenarioText() { + // -D behave.reporter.junit.show_scenarios=false: the report has no step result, the failure is reported on the first step + PythonBehaveHandler handler = getHandler("" + + "" + + ""); + List steps = assertScenario(handler, sampleFeature("hooks"), "After hook fails", 0, FAILED, SKIPPED); + Assert.assertTrue(stepXml(steps.get(0)).contains("HOOK-ERROR in after_scenario: RuntimeError: after hook failure")); + } + + @Test + public void testStepHookFails() throws IOException { + // the step of a failed before_step or after_step hook has the status hook_error + PythonBehaveHandler handler = getHandler(testcase("Step hook fails", "error", + "Failing step: Given a passing step ... hook_error in 0.000s\nLocation: features/a.feature:9\nRuntimeError: before step hook failure", + "Given a passing step ... hook_error in 0.000s", "Then a final passing step ... skipped in 0.000s")); + assertScenario(handler, behaveFeature(), "Step hook fails", 0, FAILED, SKIPPED); + } + + @Test + public void testScenarioHookFailsWithoutSteps() throws IOException { + PythonBehaveHandler handler = getHandler(testcase("No steps", "error", null)); + try { + handler.getScenarioName(behaveFeature()); + Assert.fail("the failure cannot be reported without steps"); + } catch (IllegalStateException e) { + Assert.assertEquals("Scenario \"No steps\" failed outside its steps (HOOK-ERROR in before_scenario: RuntimeError: " + + "before hook failure), and has no step to report the failure", e.getMessage()); + } + } + + @Test + public void testUntestedSteps() throws IOException { + // e.g. the steps of the scenarios of a feature whose before_feature hook failed, which the report does not record + PythonBehaveHandler handler = getHandler(testcase("Step hook fails", null, null, + "Given a passing step ... untested in 0.000s", "Then a final passing step ... untested in 0.000s")); + assertScenario(handler, behaveFeature(), "Step hook fails", 0, SKIPPED, SKIPPED); + } + + @Test + public void testFailedStepWithoutFailure() throws IOException { + PythonBehaveHandler handler = getHandler(testcase("Step hook fails", null, null, + "Given a passing step ... failed in 0.000s", "Then a final passing step ... skipped in 0.000s")); + List steps = assertScenario(handler, behaveFeature(), "Step hook fails", 0, FAILED, SKIPPED); + Assert.assertTrue(stepXml(steps.get(0)).contains("The step is failed")); + } + + @Test + public void testNameAndFeature() { + PythonBehaveHandler handler = getHandler("basics", "Middle step fails"); + Assert.assertEquals("python-behave", handler.getName()); + Assert.assertEquals("testcase", handler.getTestCaseElementName()); + Assert.assertEquals("Latest basics", handler.getFeatureName().get()); + Assert.assertEquals("the Location of the failing step", "features/basics.feature", handler.getFeatureFile().get()); + Assert.assertFalse(getHandler("basics", "All steps pass").getFeatureFile().isPresent()); + } + + @Test + public void testStepsWithoutTimings() throws IOException { + // -D behave.reporter.junit.show_timings=false, and a line of the captured output after @scenario.end + PythonBehaveHandler handler = getHandler(testcase("Step hook fails", null, null, + "Given a passing step ... passed", "@scenario.end", "Captured stdout:", "Then a final passing step ... failed")); + List steps = assertScenario(handler, behaveFeature(), "Step hook fails", 0, PASSED, PASSED); + Assert.assertEquals("0", attribute(steps.get(0), "duration")); + } + + @Test + public void testOutlineRows() { + OctaneFeature feature = sampleFeature("outlines"); + String outline = "Eating of cucumbers"; + assertScenario(getHandler("outlines", "Eating 5 of 12 cucumbers -- @1.1 Few"), feature, outline, 1, PASSED, PASSED, PASSED, PASSED); + assertScenario(getHandler("outlines", "Eating 5 of 20 cucumbers -- @1.2 Few"), feature, outline, 2, PASSED, PASSED, PASSED, FAILED); + assertScenario(getHandler("outlines", "Eating 1 of 100 cucumbers -- @2.1 Many"), feature, outline, 3, PASSED, PASSED, PASSED, PASSED); + assertScenario(getHandler("outlines", "Eating 5 of 12 cucumbers -- @2.2 Many"), feature, outline, 4, PASSED, PASSED, PASSED, FAILED); + assertScenario(getHandler("outlines", "Counting cucumbers -- @1.1 "), feature, "Counting cucumbers", 1, PASSED, PASSED, PASSED); + } + + @Test + public void testOutlineRowsInRule() throws IOException { + OctaneFeature feature = behaveFeature(); + String outline = "Outline in a rule "; + Assert.assertEquals(3, outlineIndex(feature, outline, "Outline in a rule 3 -- @2.2 B")); + // a row that is not in the Examples, or a name without the row: the rows are merged in the order of the report + Assert.assertEquals(0, outlineIndex(feature, outline, "Outline in a rule 3 -- @3.1 C")); + Assert.assertEquals(0, outlineIndex(feature, outline, "Outline in a rule 3")); + } + + @Test + public void testReportOfOneExamplesRow() throws Exception { + // e.g. "behave --no-skipped features/outlines.feature:19" reports the last row of "Many" only + String report = new String(Files.readAllBytes(Paths.get(SAMPLE + "reports/TESTS-outlines.xml")), StandardCharsets.UTF_8); + int start = report.indexOf("", start) + "".length()); + Path reportFile = Paths.get("target", "python-behave-one-examples-row.xml"); + Path resultFile = Paths.get("target", "python-behave-one-examples-row-result.xml"); + Files.write(reportFile, ("" + row + "").getBytes(StandardCharsets.UTF_8)); + + new Bdd2Octane(Collections.singletonList(reportFile.toString()), + Collections.singletonList(SAMPLE + "features/outlines.feature"), resultFile.toString(), "python-behave").run(); + + Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(resultFile.toFile()); + NodeList scenarios = result.getElementsByTagName("scenario"); + Assert.assertEquals("only the reported row is in the result", 1, scenarios.getLength()); + org.w3c.dom.Element scenario = (org.w3c.dom.Element) scenarios.item(0); + Assert.assertEquals("the row is matched by its number, not by its order", "4", scenario.getAttribute("outlineIndex")); + NodeList steps = scenario.getElementsByTagName("step"); + Assert.assertEquals("Then I should have 8 cucumbers", ((org.w3c.dom.Element) steps.item(3)).getAttribute("name")); + Assert.assertEquals("failed", ((org.w3c.dom.Element) steps.item(3)).getAttribute("status")); + } + + private static OctaneFeature sampleFeature(String name) { + return TestUtil.parseFeatureFile(SAMPLE + "features/" + name + ".feature"); + } + + private static OctaneFeature behaveFeature() throws IOException { + Path featureFile = Paths.get("target", "python-behave-cases.feature"); + Files.write(featureFile, String.join("\n", + "Feature: Behave cases", + "", + " Scenario: Repeated steps", + " Given a passing step", + " * a passing step", + " * a passing step", + "", + " Scenario: Step hook fails", + " Given a passing step", + " Then a final passing step", + "", + " Scenario: Skipped in the middle", + " Given a passing step", + " When a step that skips the scenario", + " Then a final passing step", + "", + " Scenario: No steps", + "", + " Rule: A rule", + "", + " Scenario Outline: Outline in a rule ", + " Given a passing step", + "", + " Examples: A", + " | value |", + " | 1 |", + "", + " Examples: B", + " | value |", + " | 2 |", + " | 3 |", + "").getBytes(StandardCharsets.UTF_8)); + return TestUtil.parseFeatureFile(featureFile.toString()); + } + + // a testcase with the step lines of system-out, which failed if failureText is not null + private static String testcase(String name, String failure, String failureText, String... steps) { + String failureElement = failure == null ? "" : failureText == null + ? "" + + "" + : "<" + failure + " type=\"RuntimeError\" message=\"failure\">"; + return "" + failureElement + ""; + } + + private static PythonBehaveHandler getHandler(String testcaseXml) { + try (JunitReportReader reader = new JunitReportReader( + new ByteArrayInputStream(("" + testcaseXml + "").getBytes(StandardCharsets.UTF_8)), "testcase")) { + PythonBehaveHandler handler = new PythonBehaveHandler(); + handler.setElement(reader.iterator().next()); + return handler; + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + } + + private static PythonBehaveHandler getHandler(String report, String testcaseName) { + String reportFile = SAMPLE + "reports/TESTS-" + report + ".xml"; + try (JunitReportReader reader = new JunitReportReader(new FileInputStream(reportFile), "testcase")) { + for (Element element : reader) { + if (testcaseName.equals(element.getAttribute("name"))) { + PythonBehaveHandler handler = new PythonBehaveHandler(); + handler.setElement(element); + return handler; + } + } + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + throw new IllegalArgumentException("No testcase \"" + testcaseName + "\" in " + reportFile); + } + + private static int outlineIndex(OctaneFeature feature, String outline, String testcaseName) { + PythonBehaveHandler handler = getHandler(testcase(testcaseName, null, null, "Given a passing step ... passed in 0.000s")); + Assert.assertEquals(outline, handler.getScenarioName(feature)); + return handler.getOutlineIndex().orElse(0); + } + + // fills the steps as Bdd2Octane does: the steps after the first step that did not pass are skipped + private static List assertScenario(PythonBehaveHandler handler, OctaneFeature feature, String scenarioName, + int outlineIndex, Status... statuses) { + Assert.assertEquals("handler can get back scenario name", scenarioName, handler.getScenarioName(feature)); + Assert.assertEquals("handler can get back outline index", outlineIndex, handler.getOutlineIndex().orElse(0)); + List steps = feature.getScenarios(scenarioName).get(Math.max(outlineIndex - 1, 0)).getSteps(); + boolean stopped = false; + for (OctaneStep step : steps) { + if (stopped) { + step.setStatus(SKIPPED); + } else { + handler.fillStep(step); + stopped = step.getStatus() != PASSED; + } + } + Assert.assertEquals("handler can get back step statuses", Arrays.asList(statuses), + steps.stream().map(OctaneStep::getStatus).collect(Collectors.toList())); + return steps; + } + + private static String stepXml(OctaneStep step) { + StringWriter xml = new StringWriter(); + try { + XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(xml); + step.writeToXml(writer); + writer.flush(); + } catch (XMLStreamException e) { + throw new IllegalStateException(e); + } + return xml.toString(); + } + + private static String attribute(OctaneStep step, String name) { + String xml = stepXml(step); + int start = xml.indexOf(name + "=\"") + name.length() + 2; + return xml.substring(start, xml.indexOf('"', start)); + } + // @Test // public void testTwoOutlineScenarioWithSameName() { // Element element = TestUtil.getXmlElement( diff --git a/src/test/resources/python-behave/1.3.3/features/basics.feature b/src/test/resources/python-behave/1.3.3/features/basics.feature new file mode 100644 index 0000000..db9a286 --- /dev/null +++ b/src/test/resources/python-behave/1.3.3/features/basics.feature @@ -0,0 +1,57 @@ +@BSPID2001REV0.1.0 +Feature: Latest basics + + Background: + Given the background is ready + + Scenario: All steps pass + Given a passing step + When another passing step + Then a final passing step + + Scenario: Middle step fails + Given a passing step + When a step that fails with "middle step failure" + Then a final passing step + + Scenario: Step raises an error + Given a passing step + When a step that raises an error + Then a final passing step + + Scenario: Undefined step + Given a passing step + When a step without any definition + Then a final passing step + + Scenario: Pending step + Given a passing step + When a pending step + Then a final passing step + + Scenario: Skipped scenario + Given a passing step + When a step that skips the scenario + Then a final passing step + + Scenario: Repeated identical steps + Given a passing step + When the counter is incremented + And the counter is incremented + Then a final passing step + + Scenario: Data table and doc string + Given the following cucumbers: + | colour | count | + | green | 3 | + | red | 1 | + And the following note: + """ + Line one with & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step diff --git a/src/test/resources/python-behave/1.3.3/features/hooks.feature b/src/test/resources/python-behave/1.3.3/features/hooks.feature new file mode 100644 index 0000000..f072229 --- /dev/null +++ b/src/test/resources/python-behave/1.3.3/features/hooks.feature @@ -0,0 +1,11 @@ +Feature: Latest hooks + + @failing-before-hook + Scenario: Before hook fails + Given a passing step + Then a final passing step + + @failing-after-hook + Scenario: After hook fails + Given a passing step + Then a final passing step diff --git a/src/test/resources/python-behave/1.3.3/features/outlines.feature b/src/test/resources/python-behave/1.3.3/features/outlines.feature new file mode 100644 index 0000000..0d36d4c --- /dev/null +++ b/src/test/resources/python-behave/1.3.3/features/outlines.feature @@ -0,0 +1,31 @@ +Feature: Latest outlines + + Background: + Given the background is ready + + Scenario Outline: Eating of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 | diff --git a/src/test/resources/python-behave/1.3.3/features/rules.feature b/src/test/resources/python-behave/1.3.3/features/rules.feature new file mode 100644 index 0000000..2c5a8b1 --- /dev/null +++ b/src/test/resources/python-behave/1.3.3/features/rules.feature @@ -0,0 +1,17 @@ +Feature: Latest rules + + Background: + Given the background is ready + + Rule: First rule + Background: + Given a rule background step + + Scenario: Rule scenario fails + Given a passing step + Then a step that fails with "rule failure" + + Rule: Second rule + Scenario: Rule scenario passes + Given a passing step + Then a final passing step diff --git a/src/test/resources/python-behave/1.3.3/reports/TESTS-basics.xml b/src/test/resources/python-behave/1.3.3/reports/TESTS-basics.xml new file mode 100644 index 0000000..070b00c --- /dev/null +++ b/src/test/resources/python-behave/1.3.3/reports/TESTS-basics.xml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + & "quotes" + Line two + """ + Then the cucumber count is 4 ... passed in 0.000s + +@scenario.end +-------------------------------------------------------------------------------- +]]> + + + \ No newline at end of file diff --git a/src/test/resources/python-behave/1.3.3/reports/TESTS-hooks.xml b/src/test/resources/python-behave/1.3.3/reports/TESTS-hooks.xml new file mode 100644 index 0000000..c06d708 --- /dev/null +++ b/src/test/resources/python-behave/1.3.3/reports/TESTS-hooks.xml @@ -0,0 +1,47 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/python-behave/1.3.3/reports/TESTS-outlines.xml b/src/test/resources/python-behave/1.3.3/reports/TESTS-outlines.xml new file mode 100644 index 0000000..1a9cf58 --- /dev/null +++ b/src/test/resources/python-behave/1.3.3/reports/TESTS-outlines.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/python-behave/1.3.3/reports/TESTS-rules.xml b/src/test/resources/python-behave/1.3.3/reports/TESTS-rules.xml new file mode 100644 index 0000000..aa79626 --- /dev/null +++ b/src/test/resources/python-behave/1.3.3/reports/TESTS-rules.xml @@ -0,0 +1,29 @@ + + + + + + + \ No newline at end of file diff --git a/src/test/resources/standardOctaneGherkinReport/multipleDifferentResults/standard-multipleDifferent-python-behave-final.xml b/src/test/resources/standardOctaneGherkinReport/multipleDifferentResults/standard-multipleDifferent-python-behave-final.xml index 1edc66c..c068dc4 100644 --- a/src/test/resources/standardOctaneGherkinReport/multipleDifferentResults/standard-multipleDifferent-python-behave-final.xml +++ b/src/test/resources/standardOctaneGherkinReport/multipleDifferentResults/standard-multipleDifferent-python-behave-final.xml @@ -83,9 +83,9 @@ None]]> - - - + + + @@ -104,27 +104,27 @@ this is comment - + - + - + - + - + @@ -206,9 +206,9 @@ None]]> - - - + + + @@ -224,27 +224,27 @@ None]]> - + - + - + - + - + diff --git a/src/test/resources/standardOctaneGherkinReport/multipleSameResults/standard-multipleSame-python-behave-final.xml b/src/test/resources/standardOctaneGherkinReport/multipleSameResults/standard-multipleSame-python-behave-final.xml index c5c9c31..5c901c0 100644 --- a/src/test/resources/standardOctaneGherkinReport/multipleSameResults/standard-multipleSame-python-behave-final.xml +++ b/src/test/resources/standardOctaneGherkinReport/multipleSameResults/standard-multipleSame-python-behave-final.xml @@ -59,10 +59,10 @@ Feature: Some terse yet descriptive text of what is desired like bla bla - - - - + + + + @@ -72,9 +72,9 @@ Feature: Some terse yet descriptive text of what is desired like bla bla - - - + + + @@ -90,27 +90,27 @@ Feature: Some terse yet descriptive text of what is desired like bla bla - + - + - + - + - + @@ -174,8 +174,8 @@ Feature: Some terse yet descriptive text of what is desired like bla bla - - + + - - - + + + @@ -210,27 +210,27 @@ None]]> - + - + - + - + - + diff --git a/src/test/resources/standardOctaneGherkinReport/separateResults/standard-python-behave-1.3.3-final.xml b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-python-behave-1.3.3-final.xml new file mode 100644 index 0000000..70fac09 --- /dev/null +++ b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-python-behave-1.3.3-final.xml @@ -0,0 +1,373 @@ + + + + + + & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 |]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/standardOctaneGherkinReport/singleResults/standard-single-python-behave-final.xml b/src/test/resources/standardOctaneGherkinReport/singleResults/standard-single-python-behave-final.xml index 151174b..0dadb6c 100644 --- a/src/test/resources/standardOctaneGherkinReport/singleResults/standard-single-python-behave-final.xml +++ b/src/test/resources/standardOctaneGherkinReport/singleResults/standard-single-python-behave-final.xml @@ -60,9 +60,9 @@ Feature: Some terse yet descriptive text of what is desired like bla bla - - + - - - + + + @@ -99,13 +99,13 @@ None]]> - + - + @@ -113,14 +113,14 @@ None]]> - + - + - + From 3e4a455b361911fb9abeb231342a75928579c851 Mon Sep 17 00:00:00 2001 From: Noor Date: Mon, 30 Nov 2026 14:53:30 +0200 Subject: [PATCH 4/5] Support Behat 4.1.1 junit reports Converting real Behat 4.1.1 junit reports showed that the php-behat handler dropped the Examples rows, reported undefined and pending steps as skipped, and lost hook failures. The handler now: - Matches an Examples row by its name, which has the values of the row, and by its failed step. Rows with the same name are matched in report order. The "#" of the name is not used, because Behat numbers only the rows that ran, e.g. in a rerun. - Reports undefined and pending steps as failed, with "undefined: ..." and "pending: ..." messages. - Matches the failed step by its keyword and whole text, rather than by any step text that the failure message contains. Repeated steps with different keywords are told apart. - Reports the failure of a hook before the steps (BeforeScenario, BeforeFeature) on the first step, and the failure of a hook after the steps (AfterScenario, AfterFeature) on the last step. When a step also failed, the step failure is reported. If the scenario has no steps, the conversion fails with an error. Tests: Behat 4.1.1 sample features and report, an integration test with its expected result, and 16 new unit tests in TestPhpBehatHandler. The 3 existing Behat expected files are unchanged. README: Behat 4.1.1 is the tested version, with notes on the handler. --- README.md | 15 +- .../com/microfocus/bdd/PhpBehatHandler.java | 89 ++++- .../bdd/it/Bdd2OctaneHandlerITCase.java | 2 + .../bdd/ut/TestPhpBehatHandler.java | 333 ++++++++++++++++++ .../php-behat/4.1.1/features/basics.feature | 57 +++ .../php-behat/4.1.1/features/hooks.feature | 11 + .../php-behat/4.1.1/features/outlines.feature | 31 ++ .../php-behat/4.1.1/features/rules.feature | 17 + .../php-behat/4.1.1/reports/default.xml | 54 +++ .../standard-php-behat-4.1.1-final.xml | 322 +++++++++++++++++ 10 files changed, 925 insertions(+), 6 deletions(-) create mode 100644 src/test/resources/php-behat/4.1.1/features/basics.feature create mode 100644 src/test/resources/php-behat/4.1.1/features/hooks.feature create mode 100644 src/test/resources/php-behat/4.1.1/features/outlines.feature create mode 100644 src/test/resources/php-behat/4.1.1/features/rules.feature create mode 100644 src/test/resources/php-behat/4.1.1/reports/default.xml create mode 100644 src/test/resources/standardOctaneGherkinReport/separateResults/standard-php-behat-4.1.1-final.xml diff --git a/README.md b/README.md index 80183d7..fd96914 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The following frameworks are currently supported out-of-the-box: - cucumber-js > tested version: 13.3.0, with the built-in junit formatter (since bdd2octane 1.1.14) - php-behat - > verified versions: 3.8.1 + > tested version: 4.1.1, with the junit formatter (since bdd2octane 1.1.14) - python-radish > verified versions: 0.13.2, 0.13.4 - python-behave @@ -96,6 +96,19 @@ SpecFlow test result injection is supported via the use of a template file for r the conversion fails with an error. * The report does not record the failure of a before_feature or after_feature hook. +### Notes on PHP-behat handler + +* The handler reads the report of the junit formatter of Behat, for example `behat --format=junit --out=reports/junit`. +* The report has no step results or durations. The failed step is the step named in the failure message, the steps + before it are reported as passed and the steps after it as skipped, with a duration of 0. Of repeated steps with the + same keyword and text, the first one is reported as failed. +* An Examples row is identified by its name, which has the values of the row, and by its failed step. Rows with the same + name are matched in the order of the report. +* The failure of a hook before the steps, for example BeforeScenario or BeforeFeature, is reported on the first step, + and the failure of a hook after the steps on the last step. If the scenario has no steps, the conversion fails with + an error. +* The report does not record the failure of a BeforeStep or AfterStep hook. + ### Notes on Cucumber-jvm handler * If **useFileNameCompatibleName** is enabled, the space character in a feature name is replaced with underscore(_) in JUnit report, currently the handler doesn't support this configuration. diff --git a/src/main/java/com/microfocus/bdd/PhpBehatHandler.java b/src/main/java/com/microfocus/bdd/PhpBehatHandler.java index 6cd93d1..7cea898 100644 --- a/src/main/java/com/microfocus/bdd/PhpBehatHandler.java +++ b/src/main/java/com/microfocus/bdd/PhpBehatHandler.java @@ -33,13 +33,29 @@ import com.microfocus.bdd.api.*; +import java.util.Comparator; +import java.util.List; import java.util.Optional; +import java.util.OptionalInt; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; public class PhpBehatHandler implements BddFrameworkHandler { + // the name of an Examples row: the outline name with the values of the row, and the number of the row among the run rows + private static final Pattern EXAMPLE_ROW = Pattern.compile("^(.*) #\\d+$"); private Element element; private String status; + // the message of a failed, undefined or pending step starts with the step: "When a step: error" + private String failedStep; private String errorMessage; + // the failure of a hook before the steps ("setup") or after them ("teardown") + private String hookFailure; + private boolean hookFailureAfterSteps; + private int stepCount; + private int nextStep; + private int outlineIndex; @Override public String getName() { @@ -50,8 +66,20 @@ public String getName() { public void setElement(Element element) { this.element = element; this.status = element.getAttribute("status"); - if (status.equalsIgnoreCase(Status.FAILED.toString())) { - this.errorMessage = element.getChild("failure").get().getAttribute("message"); + for (Element child : element.getChildren()) { + String type = child.getAttribute("type"); + if (!child.getName().equals("failure") && !child.getName().equals("error")) { + continue; + } + if ("setup".equals(type) || "teardown".equals(type)) { + if (hookFailure == null) { + hookFailure = child.getAttribute("message"); + hookFailureAfterSteps = "teardown".equals(type); + } + } else if (failedStep == null) { + failedStep = child.getAttribute("message"); + errorMessage = child.getName().equals("error") ? type + ": " + failedStep : failedStep; + } } } @@ -67,10 +95,31 @@ public Optional getFeatureFile() { @Override public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... octaneFeatureLocator) { + String scenarioName = findScenarioName(feature); + if (scenarioName != null && hookFailure != null && failedStep == null) { + List scenarios = feature.getScenarios(scenarioName); + stepCount = scenarios.isEmpty() ? 0 : scenarios.get(0).getSteps().size(); + if (!scenarios.isEmpty() && stepCount == 0) { + throw new IllegalStateException("Scenario \"" + element.getAttribute("name") + "\" failed outside its steps (" + + hookFailure + "), and has no step to report the failure"); + } + } + return scenarioName; + } + + private String findScenarioName(OctaneFeature feature) { String elementName = element.getAttribute("name"); if (!feature.getScenarios(elementName).isEmpty()) { return elementName; } + Matcher row = EXAMPLE_ROW.matcher(elementName); + if (row.matches()) { + Optional scenario = findRow(feature, row.group(1)); + if (scenario.isPresent()) { + outlineIndex = scenario.get().getOutlineIndex(); + return scenario.get().getName(); + } + } for (OctaneScenario scenario : feature.getScenarios()) { if (elementName.startsWith(scenario.getName())) { return scenario.getName(); @@ -79,13 +128,43 @@ public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... oct return null; } + // the rows with the name are told apart by the failed step, and then by the order of the report + private Optional findRow(OctaneFeature feature, String name) { + List rows = feature.getScenarios().stream() + .filter(scenario -> scenario.getOutlineIndex() > 0 && scenario.getOutlineName().equals(name)) + .sorted(Comparator.comparingInt(OctaneScenario::getOutlineIndex)) + .collect(Collectors.toList()); + if (rows.stream().anyMatch(this::hasFailedStep)) { + rows = rows.stream().filter(this::hasFailedStep).collect(Collectors.toList()); + } + Optional unmerged = rows.stream().filter(scenario -> !scenario.isMerged()).findFirst(); + return unmerged.isPresent() ? unmerged : rows.stream().findFirst(); + } + + private boolean hasFailedStep(OctaneScenario scenario) { + return scenario.getSteps().stream().anyMatch(this::isFailedStep); + } + + private boolean isFailedStep(OctaneStep step) { + String stepName = step.getCompleteStepName(); + return failedStep != null && (failedStep.equals(stepName) || failedStep.startsWith(stepName + ": ")); + } + + @Override + public OptionalInt getOutlineIndex() { + return outlineIndex > 0 ? OptionalInt.of(outlineIndex) : OptionalInt.empty(); + } @Override public void fillStep(OctaneStep octaneStep) { - if (status.equalsIgnoreCase(Status.PASSED.toString())) { + int step = nextStep++; + if (hookFailure != null && failedStep == null && step == (hookFailureAfterSteps ? stepCount - 1 : 0)) { + octaneStep.setStatus(Status.FAILED); + octaneStep.setErrorMessage(hookFailure); + } else if (status.equalsIgnoreCase(Status.PASSED.toString())) { octaneStep.setStatus(Status.PASSED); - } else if (status.equalsIgnoreCase(Status.FAILED.toString())) { - if (errorMessage.contains(octaneStep.getName())) { + } else if (failedStep != null) { + if (isFailedStep(octaneStep)) { octaneStep.setStatus(Status.FAILED); octaneStep.setErrorMessage(errorMessage); } else { diff --git a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java index 6e1a995..72d6cb3 100644 --- a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java +++ b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java @@ -109,6 +109,8 @@ public static List data() { {Framework.CUCUMBER_RUBY, "src/test/resources/cucumber-ruby/12.0.1/reports/*.xml", "src/test/resources/cucumber-ruby/12.0.1/features/*.feature", "separateResults/cucumber-ruby-12.0.1-final.xml", "**/separateResults/standard-cucumber-ruby-12.0.1-final.xml"}, //python-behave 1.3.3 reports {Framework.PYTHON_BEHAVE, "src/test/resources/python-behave/1.3.3/reports/*.xml", "src/test/resources/python-behave/1.3.3/features/*.feature", "separateResults/python-behave-1.3.3-final.xml", "**/separateResults/standard-python-behave-1.3.3-final.xml"}, + //php-behat 4.1.1 report + {Framework.PHP_BEHAT, "src/test/resources/php-behat/4.1.1/reports/*.xml", "src/test/resources/php-behat/4.1.1/features/*.feature", "separateResults/php-behat-4.1.1-final.xml", "**/separateResults/standard-php-behat-4.1.1-final.xml"}, }); } diff --git a/src/test/java/com/microfocus/bdd/ut/TestPhpBehatHandler.java b/src/test/java/com/microfocus/bdd/ut/TestPhpBehatHandler.java index b9bb81c..ee35ef2 100644 --- a/src/test/java/com/microfocus/bdd/ut/TestPhpBehatHandler.java +++ b/src/test/java/com/microfocus/bdd/ut/TestPhpBehatHandler.java @@ -32,12 +32,38 @@ package com.microfocus.bdd.ut; import com.microfocus.bdd.api.*; +import com.microfocus.bdd.Bdd2Octane; +import com.microfocus.bdd.JunitReportReader; import com.microfocus.bdd.PhpBehatHandler; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static com.microfocus.bdd.api.Status.FAILED; +import static com.microfocus.bdd.api.Status.PASSED; +import static com.microfocus.bdd.api.Status.SKIPPED; public class TestPhpBehatHandler { + private static final String SAMPLE = "src/test/resources/php-behat/4.1.1/"; private OctaneFeature octaneFeature; @@ -82,4 +108,311 @@ public void testScenarioOutline() { Assert.assertEquals("handler can get back scenario name", "feeding a cow yum yum yum", handler.getScenarioName(octaneFeature)); } + + @Test + public void testNameAndFeature() { + PhpBehatHandler handler = getHandler("Latest basics", "Middle step fails"); + Assert.assertEquals("php-behat", handler.getName()); + Assert.assertEquals("testcase", handler.getTestCaseElementName()); + Assert.assertEquals("Latest basics", handler.getFeatureName().get()); + Assert.assertFalse(handler.getFeatureFile().isPresent()); + } + + @Test + public void testFailedSteps() { + for (String scenario : Arrays.asList("Middle step fails", "Step raises an error", "Ambiguous step")) { + List steps = assertScenario(getHandler("Latest basics", scenario), sampleFeature("basics"), scenario, 0, + PASSED, PASSED, FAILED, SKIPPED); + Assert.assertTrue(scenario, stepXml(steps.get(2)).contains(steps.get(2).getCompleteStepName() + ": ")); + } + } + + @Test + public void testUndefinedAndPendingSteps() { + List steps = assertScenario(getHandler("Latest basics", "Undefined step"), sampleFeature("basics"), "Undefined step", 0, + PASSED, PASSED, FAILED, SKIPPED); + Assert.assertTrue(stepXml(steps.get(2)).contains("undefined: When a step without any definition")); + steps = assertScenario(getHandler("Latest basics", "Pending step"), sampleFeature("basics"), "Pending step", 0, + PASSED, PASSED, FAILED, SKIPPED); + Assert.assertTrue(stepXml(steps.get(2)).contains("pending: When a pending step: TODO: write pending definition")); + } + + @Test + public void testRepeatedIdenticalSteps() { + // "And the counter is incremented: counter incremented more than once" + assertScenario(getHandler("Latest basics", "Repeated identical steps"), sampleFeature("basics"), "Repeated identical steps", 0, + PASSED, PASSED, PASSED, FAILED, SKIPPED); + } + + @Test + public void testFailedStepIsMatchedByItsWholeName() throws IOException { + // "Given a passing step" is not the failed step "Then a passing step and more" + PhpBehatHandler handler = getHandler(testcase("Prefix of a step", "failed", + "")); + assertScenario(handler, behatFeature(), "Prefix of a step", 0, PASSED, FAILED); + } + + @Test + public void testFailedStepsOfAllKinds() throws IOException { + // the messages of Behat 4.1.1: a step of a background, of a rule background, with a doc string, with * and But + assertScenario(getHandler(testcase("All steps pass", "failed", + "")), + sampleFeature("basics"), "All steps pass", 0, FAILED, SKIPPED, SKIPPED, SKIPPED); + assertScenario(getHandler(testcase("Rule scenario fails", "failed", + "")), + sampleFeature("rules"), "Rule scenario fails", 0, PASSED, FAILED, SKIPPED, SKIPPED); + assertScenario(getHandler(testcase("Data table and doc string", "failed", + "")), + sampleFeature("basics"), "Data table and doc string", 0, PASSED, PASSED, FAILED, SKIPPED); + assertScenario(getHandler(testcase("Star and but steps", "failed", + "")), + behatFeature(), "Star and but steps", 0, PASSED, FAILED, SKIPPED); + assertScenario(getHandler(testcase("Star and but steps", "failed", + "")), + behatFeature(), "Star and but steps", 0, PASSED, PASSED, FAILED); + } + + @Test + public void testSkippedScenario() { + // e.g. behat --dry-run + assertScenario(getHandler(testcase("All steps pass", "skipped", "")), sampleFeature("basics"), "All steps pass", 0, + SKIPPED, SKIPPED, SKIPPED, SKIPPED); + } + + @Test + public void testUnknownScenario() { + Assert.assertNull(getHandler(testcase("Unknown scenario", "passed", "")).getScenarioName(sampleFeature("basics"))); + } + + @Test + public void testScenarioHooksFail() { + // the failure of a hook before the steps is reported on the first step, after the steps on the last step + List steps = assertScenario(getHandler("Latest hooks", "Before hook fails"), sampleFeature("hooks"), "Before hook fails", 0, + FAILED, SKIPPED); + Assert.assertTrue(stepXml(steps.get(0)).contains("BeforeScenario: before hook failure (RuntimeException)")); + steps = assertScenario(getHandler("Latest hooks", "After hook fails"), sampleFeature("hooks"), "After hook fails", 0, + PASSED, FAILED); + Assert.assertTrue(stepXml(steps.get(1)).contains("AfterScenario: after hook failure (RuntimeException)")); + } + + @Test + public void testFeatureHooksFail() { + PhpBehatHandler handler = getHandler(testcase("Before hook fails", "skipped", + "")); + assertScenario(handler, sampleFeature("hooks"), "Before hook fails", 0, FAILED, SKIPPED); + handler = getHandler(testcase("After hook fails", "passed", + "")); + assertScenario(handler, sampleFeature("hooks"), "After hook fails", 0, PASSED, FAILED); + } + + @Test + public void testStepAndAfterHookFail() throws IOException { + // the failure of the step is reported, not the one of the hook + PhpBehatHandler handler = getHandler(testcase("Step and after hook fail", "failed", + "" + + "")); + List steps = assertScenario(handler, behatFeature(), "Step and after hook fail", 0, PASSED, FAILED); + Assert.assertTrue(stepXml(steps.get(1)).contains("step failure (RuntimeException)")); + } + + @Test + public void testHookFailsWithoutSteps() throws IOException { + PhpBehatHandler handler = getHandler(testcase("No steps and before hook fails", "passed", + "")); + try { + handler.getScenarioName(behatFeature()); + Assert.fail("the failure cannot be reported without steps"); + } catch (IllegalStateException e) { + Assert.assertEquals("Scenario \"No steps and before hook fails\" failed outside its steps (BeforeScenario: before hook " + + "failure (RuntimeException)), and has no step to report the failure", e.getMessage()); + } + } + + @Test + public void testOutlineRows() { + OctaneFeature feature = sampleFeature("outlines"); + String outline = "Eating of cucumbers"; + assertScenario(getHandler("Latest outlines", "Eating 5 of 12 cucumbers #1"), feature, outline, 1, PASSED, PASSED, PASSED, PASSED); + assertScenario(getHandler("Latest outlines", "Eating 5 of 20 cucumbers #2"), feature, outline, 2, PASSED, PASSED, PASSED, FAILED); + assertScenario(getHandler("Latest outlines", "Eating 1 of 100 cucumbers #1"), feature, outline, 3, PASSED, PASSED, PASSED, PASSED); + // the row 1 has the same name, the failed step tells them apart + assertScenario(getHandler("Latest outlines", "Eating 5 of 12 cucumbers #2"), feature, outline, 4, PASSED, PASSED, PASSED, FAILED); + assertScenario(getHandler("Latest outlines", "Counting cucumbers #1"), feature, "Counting cucumbers", 1, PASSED, PASSED, PASSED); + } + + @Test + public void testOutlineRowsWithTheSameName() throws IOException { + // the rows with the same name are merged in the order of the report + OctaneFeature feature = behatFeature(); + String outline = "Outline with a description "; + Assert.assertEquals(1, outlineIndex(feature, outline, "Outline with a description 1 #1")); + feature.findScenario(outline, 1).get().markMerged(); + Assert.assertEquals(2, outlineIndex(feature, outline, "Outline with a description 1 #1")); + Assert.assertEquals(3, outlineIndex(feature, outline, "Outline with a description 2 #2")); + feature.findScenario(outline, 2).get().markMerged(); + Assert.assertEquals("all the rows are merged", 1, outlineIndex(feature, outline, "Outline with a description 1 #1")); + Assert.assertEquals(2, outlineIndex(feature, "Outline in a rule ", "Outline in a rule y #2")); + } + + @Test + public void testScenarioWithTheNameOfARow() throws IOException { + // the scenario "Plain name", and the row of "Plain " named "Plain name #1" + OctaneFeature feature = behatFeature(); + Assert.assertEquals(1, outlineIndex(feature, "Plain ", "Plain name #1")); + PhpBehatHandler handler = getHandler(testcase("Plain name", "passed", "")); + Assert.assertEquals("Plain name", handler.getScenarioName(feature)); + Assert.assertFalse(handler.getOutlineIndex().isPresent()); + } + + @Test + public void testReportOfOneExamplesRow() throws Exception { + // "behat features/outlines.feature:19" runs the last row of "Many" only, and names it #1 + Path reportFile = Paths.get("target", "php-behat-one-examples-row.xml"); + Path resultFile = Paths.get("target", "php-behat-one-examples-row-result.xml"); + Files.write(reportFile, ("" + + "").getBytes(StandardCharsets.UTF_8)); + + new Bdd2Octane(Collections.singletonList(reportFile.toString()), + Collections.singletonList(SAMPLE + "features/outlines.feature"), resultFile.toString(), "php-behat").run(); + + Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(resultFile.toFile()); + NodeList scenarios = result.getElementsByTagName("scenario"); + Assert.assertEquals("only the reported row is in the result", 1, scenarios.getLength()); + org.w3c.dom.Element scenario = (org.w3c.dom.Element) scenarios.item(0); + Assert.assertEquals("the row is matched by its failed step, not by its number", "4", scenario.getAttribute("outlineIndex")); + NodeList steps = scenario.getElementsByTagName("step"); + Assert.assertEquals("Then I should have 8 cucumbers", ((org.w3c.dom.Element) steps.item(3)).getAttribute("name")); + Assert.assertEquals("failed", ((org.w3c.dom.Element) steps.item(3)).getAttribute("status")); + } + + private static OctaneFeature sampleFeature(String name) { + return TestUtil.parseFeatureFile(SAMPLE + "features/" + name + ".feature"); + } + + private static OctaneFeature behatFeature() throws IOException { + Path featureFile = Paths.get("target", "php-behat-cases.feature"); + Files.write(featureFile, String.join("\n", + "Feature: Behat cases", + "", + " Scenario: Step and after hook fail", + " Given a passing step", + " Then a step that fails with \"step failure\"", + "", + " Scenario: No steps and before hook fails", + "", + " Scenario: Prefix of a step", + " Given a passing step", + " Then a passing step and more", + "", + " Scenario: Star and but steps", + " Given a passing step", + " * a step that fails with \"star failure\"", + " But a final passing step", + "", + " Scenario: Plain name", + " Given a passing step", + "", + " Scenario Outline: Plain ", + " Given a step that fails with \"\"", + "", + " Examples:", + " | v |", + " | name |", + "", + " Scenario Outline: Outline with a description ", + " This is the description of the outline.", + "", + " Given a passing step", + "", + " Examples: A", + " | value |", + " | 1 |", + "", + " Examples: B", + " | value |", + " | 1 |", + " | 2 |", + "", + " Rule: A rule", + "", + " Scenario Outline: Outline in a rule ", + " Given a passing step", + "", + " Examples:", + " | value |", + " | x |", + " | y |", + "").getBytes(StandardCharsets.UTF_8)); + return TestUtil.parseFeatureFile(featureFile.toString()); + } + + private static String testcase(String name, String status, String failures) { + return "" + failures + ""; + } + + private static PhpBehatHandler getHandler(String testcaseXml) { + try (JunitReportReader reader = new JunitReportReader( + new ByteArrayInputStream(("" + testcaseXml + "").getBytes(StandardCharsets.UTF_8)), "testcase")) { + PhpBehatHandler handler = new PhpBehatHandler(); + handler.setElement(reader.iterator().next()); + return handler; + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + } + + private static PhpBehatHandler getHandler(String feature, String testcaseName) { + try (JunitReportReader reader = new JunitReportReader(new FileInputStream(SAMPLE + "reports/default.xml"), "testcase")) { + for (Element element : reader) { + if (feature.equals(element.getAttribute("classname")) && testcaseName.equals(element.getAttribute("name"))) { + PhpBehatHandler handler = new PhpBehatHandler(); + handler.setElement(element); + return handler; + } + } + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + throw new IllegalArgumentException("No testcase \"" + testcaseName + "\" of " + feature); + } + + private static int outlineIndex(OctaneFeature feature, String outline, String testcaseName) { + PhpBehatHandler handler = getHandler(testcase(testcaseName, "passed", "")); + Assert.assertEquals(outline, handler.getScenarioName(feature)); + return handler.getOutlineIndex().orElse(0); + } + + // fills the steps as Bdd2Octane does: the steps after the first step that did not pass are skipped + private static List assertScenario(PhpBehatHandler handler, OctaneFeature feature, String scenarioName, + int outlineIndex, Status... statuses) { + Assert.assertEquals("handler can get back scenario name", scenarioName, handler.getScenarioName(feature)); + Assert.assertEquals("handler can get back outline index", outlineIndex, handler.getOutlineIndex().orElse(0)); + List steps = feature.getScenarios(scenarioName).get(Math.max(outlineIndex - 1, 0)).getSteps(); + boolean stopped = false; + for (OctaneStep step : steps) { + if (stopped) { + step.setStatus(SKIPPED); + } else { + handler.fillStep(step); + stopped = step.getStatus() != PASSED; + } + } + Assert.assertEquals("handler can get back step statuses", Arrays.asList(statuses), + steps.stream().map(OctaneStep::getStatus).collect(Collectors.toList())); + return steps; + } + + private static String stepXml(OctaneStep step) { + StringWriter xml = new StringWriter(); + try { + XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(xml); + step.writeToXml(writer); + writer.flush(); + } catch (XMLStreamException e) { + throw new IllegalStateException(e); + } + return xml.toString(); + } } diff --git a/src/test/resources/php-behat/4.1.1/features/basics.feature b/src/test/resources/php-behat/4.1.1/features/basics.feature new file mode 100644 index 0000000..308b22d --- /dev/null +++ b/src/test/resources/php-behat/4.1.1/features/basics.feature @@ -0,0 +1,57 @@ +@BSPID2001REV0.1.0 +Feature: Latest basics + + Background: + Given the background is ready + + Scenario: All steps pass + Given a passing step + When another passing step + Then a final passing step + + Scenario: Middle step fails + Given a passing step + When a step that fails with "middle step failure" + Then a final passing step + + Scenario: Step raises an error + Given a passing step + When a step that raises an error + Then a final passing step + + Scenario: Undefined step + Given a passing step + When a step without any definition + Then a final passing step + + Scenario: Pending step + Given a passing step + When a pending step + Then a final passing step + + Scenario: Ambiguous step + Given a passing step + When an ambiguous step + Then a final passing step + + Scenario: Repeated identical steps + Given a passing step + When the counter is incremented + And the counter is incremented + Then a final passing step + + Scenario: Data table and doc string + Given the following cucumbers: + | colour | count | + | green | 3 | + | red | 1 | + And the following note: + """ + Line one with & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step diff --git a/src/test/resources/php-behat/4.1.1/features/hooks.feature b/src/test/resources/php-behat/4.1.1/features/hooks.feature new file mode 100644 index 0000000..f072229 --- /dev/null +++ b/src/test/resources/php-behat/4.1.1/features/hooks.feature @@ -0,0 +1,11 @@ +Feature: Latest hooks + + @failing-before-hook + Scenario: Before hook fails + Given a passing step + Then a final passing step + + @failing-after-hook + Scenario: After hook fails + Given a passing step + Then a final passing step diff --git a/src/test/resources/php-behat/4.1.1/features/outlines.feature b/src/test/resources/php-behat/4.1.1/features/outlines.feature new file mode 100644 index 0000000..0d36d4c --- /dev/null +++ b/src/test/resources/php-behat/4.1.1/features/outlines.feature @@ -0,0 +1,31 @@ +Feature: Latest outlines + + Background: + Given the background is ready + + Scenario Outline: Eating of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 | diff --git a/src/test/resources/php-behat/4.1.1/features/rules.feature b/src/test/resources/php-behat/4.1.1/features/rules.feature new file mode 100644 index 0000000..2c5a8b1 --- /dev/null +++ b/src/test/resources/php-behat/4.1.1/features/rules.feature @@ -0,0 +1,17 @@ +Feature: Latest rules + + Background: + Given the background is ready + + Rule: First rule + Background: + Given a rule background step + + Scenario: Rule scenario fails + Given a passing step + Then a step that fails with "rule failure" + + Rule: Second rule + Scenario: Rule scenario passes + Given a passing step + Then a final passing step diff --git a/src/test/resources/php-behat/4.1.1/reports/default.xml b/src/test/resources/php-behat/4.1.1/reports/default.xml new file mode 100644 index 0000000..a4d9297 --- /dev/null +++ b/src/test/resources/php-behat/4.1.1/reports/default.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/standardOctaneGherkinReport/separateResults/standard-php-behat-4.1.1-final.xml b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-php-behat-4.1.1-final.xml new file mode 100644 index 0000000..491160f --- /dev/null +++ b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-php-behat-4.1.1-final.xml @@ -0,0 +1,322 @@ + + + + + + & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 |]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a0a3e5a9dfee00dc30a3cf1f5a2495f16aeb87ce Mon Sep 17 00:00:00 2001 From: Noor Date: Tue, 1 Dec 2026 17:11:33 +0200 Subject: [PATCH 5/5] Support Cucumber-JVM 8.1.0 junit reports Converting real Cucumber-JVM 8.1.0 reports of the junit plugin and of Maven Surefire 3.6.1 with JUnit 5 and JUnit 4 showed that the cucumber-jvm handler lost or misreported scenarios: - Surefire 3.5.3 and later write the runner class as classname, so the features were not found (JUnit 5: 0 of 20 scenarios, JUnit 4: 8 of 20). - Undefined and ambiguous steps in the junit plugin report came out as skipped. With JUnit 5, an ambiguous step could come out as passed. - Examples rows were matched by report order, so reruns and partial runs put a failure on the wrong row. - Feature or Rule names with parentheses crashed the conversion. The handler now: - reads the step results that the junit plugin writes to system-out - finds the feature by the JUnit 5 long name, or by the scenario location that the JUnit 4 "pretty" plugin writes to system-out - reads the undefined and ambiguous steps of JUnit 5 and JUnit 4 - identifies an Examples row by its "#e.r" numbers in the name, or by its line in the "pretty" output - never reports a failed scenario as passed: when no failed step can be read (for example, a hook or the test setup failed), all its steps are reported as skipped, as before, and a warning is printed Tests: real 8.1.0 features and reports, 3 integration tests (junit plugin, Surefire JUnit 5, Surefire JUnit 4) and 17 unit tests. No existing test was removed or changed, except that FilesLocatorTest now counts the 2 new expected-result files whose names contain "junit". README: tested version and handler notes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 17 +- .../microfocus/bdd/CucumberJvmHandler.java | 212 +++++++-- .../bdd/it/Bdd2OctaneHandlerITCase.java | 4 + .../microfocus/bdd/ut/FilesLocatorTest.java | 2 +- .../bdd/ut/TestCucumberJvmHandler.java | 434 ++++++++++++++++++ .../8.1.0/features/basics.feature | 62 +++ .../8.1.0/features/outlines.feature | 31 ++ .../cucumber-jvm/8.1.0/features/rules.feature | 17 + .../cucumber-jvm/8.1.0/reports/cucumber.xml | 288 ++++++++++++ .../TEST-sample.RunCucumberTest.xml | 333 ++++++++++++++ .../TEST-sample.RunCucumberTest.xml | 154 +++++++ .../standard-cucumber-jvm-8.1.0-final.xml | 408 ++++++++++++++++ ...cumber-jvm-8.1.0-surefire-junit4-final.xml | 357 ++++++++++++++ ...cumber-jvm-8.1.0-surefire-junit5-final.xml | 351 ++++++++++++++ 14 files changed, 2641 insertions(+), 29 deletions(-) create mode 100644 src/test/resources/cucumber-jvm/8.1.0/features/basics.feature create mode 100644 src/test/resources/cucumber-jvm/8.1.0/features/outlines.feature create mode 100644 src/test/resources/cucumber-jvm/8.1.0/features/rules.feature create mode 100644 src/test/resources/cucumber-jvm/8.1.0/reports/cucumber.xml create mode 100644 src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit4/TEST-sample.RunCucumberTest.xml create mode 100644 src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit5/TEST-sample.RunCucumberTest.xml create mode 100644 src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-final.xml create mode 100644 src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit4-final.xml create mode 100644 src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit5-final.xml diff --git a/README.md b/README.md index fd96914..87d74d8 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,7 @@ The following frameworks are currently supported out-of-the-box: - python-behave > tested version: 1.3.3, with the JUnit reporter (since bdd2octane 1.1.14) - cucumber-jvm - > verifed versions: 2.0.0 - 7.0.0, 7.23.0 - > unsupported version: 1.2.6 + > tested version: 8.1.0, with the junit plugin, and with Maven Surefire 3.6.1 and JUnit 4 or JUnit 5 (since bdd2octane 1.1.14) - cucumber-ruby > tested version: 12.0.1, with the junit formatter (since bdd2octane 1.1.14) @@ -122,3 +121,17 @@ It is required to enable the "pretty" option of Cucumber-jvm. This tool will par currently the handler doesn't support this configuration. * When using JUnit 5.x, you must configure the system property `cucumber.junit-platform.naming-strategy=long` to ensure proper test naming. Refer to the [official documentation for integration details with Maven Surefire and Gradle](https://github.com/cucumber/cucumber-jvm/blob/main/cucumber-junit-platform-engine/README.md#maven-surefire-and-gradle). + +* The handler reads the report of the junit plugin, for example `cucumber.plugin=junit:target/cucumber.xml`, and the + Surefire reports of the JUnit 4 and JUnit 5 runners. The junit plugin report has the status of each step. With a + Surefire report, the failed step is read from the failure, and the steps before it are reported as passed. The + reports have no step durations, so steps are reported with a duration of 0. +* Surefire 3.5.3 and later write the class of the runner as classname. With JUnit 5, the feature is then found by the + name of the long naming strategy, which starts with the feature name. With JUnit 4, it is found by the location of + the scenario that the "pretty" plugin writes to \. +* An Examples row is identified by its numbers in the name, for example `#1.2`, or with JUnit 4 by its line in the + output of the "pretty" plugin. +* If a scenario failed, but no failed step can be read from the report, for example because a hook or the setup of + the test failed, all its steps are reported as skipped and a warning is printed. A failed scenario is never reported + as passed. To read the failed step from a Surefire report, keep the `trimStackTrace` option of Surefire `false`, + which is its default. diff --git a/src/main/java/com/microfocus/bdd/CucumberJvmHandler.java b/src/main/java/com/microfocus/bdd/CucumberJvmHandler.java index f5c8b12..89e7711 100644 --- a/src/main/java/com/microfocus/bdd/CucumberJvmHandler.java +++ b/src/main/java/com/microfocus/bdd/CucumberJvmHandler.java @@ -33,18 +33,35 @@ import com.microfocus.bdd.api.*; +import io.cucumber.messages.types.Examples; import io.cucumber.messages.types.FeatureChild; import io.cucumber.messages.types.Rule; import io.cucumber.messages.types.RuleChild; +import io.cucumber.messages.types.Scenario; +import io.cucumber.messages.types.TableRow; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.OptionalInt; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; public class CucumberJvmHandler implements BddFrameworkHandler { + // a step result that the junit plugin writes to system-out: "Given a step...........passed" + private static final Pattern STEP_RESULT = Pattern.compile(".+\\.\\.(passed|failed|skipped|pending|undefined|ambiguous|unknown)"); + private static final List FAILED_STATUSES = Arrays.asList("failed", "pending", "undefined", "ambiguous"); + // the location of the scenario that the pretty plugin writes to system-out: "# classpath:features/a.feature:12" + private static final Pattern SCENARIO_LOCATION = Pattern.compile("# (\\S+?\\.feature):(\\d+)"); + // the numbers of the Examples and of the row at the end of the name of an Examples row: "#1.2", "#1.2: pickle name" + private static final Pattern EXAMPLE_ROW = Pattern.compile("#(\\d+)\\.(\\d+)(?:: .*)?$"); + private static final Pattern UNDEFINED_STEP = Pattern.compile("The step [\"'](.*)[\"'] is undefined"); + private static final Pattern AMBIGUOUS_STEP = Pattern.compile("^\"(.*)\" matches more than one step definition"); + // Surefire 3.5.3 and later write the class of the runner as classname + private static final Pattern CLASS_NAME = Pattern.compile("[\\w$]+(\\.[\\w$]+)*"); private Element element; private String errorMessage; @@ -53,6 +70,12 @@ public class CucumberJvmHandler implements BddFrameworkHandler { private String failedLineNum; private boolean isSkipped = false; private String systemErrors; + private final List stepResults = new ArrayList<>(); + // the message of the failure or error element + private String failureMessage; + private long scenarioLine; + private int nextStep; + private int outlineIndex; @Override public String getName() { @@ -62,23 +85,66 @@ public String getName() { @Override public void setElement(Element element) { this.element = element; + readFailure(); + element.getChild("system-out").ifPresent(systemOut -> { + String text = systemOut.getText(); + List lines = Arrays.stream(text.split("\n")).map(String::trim).filter(line -> !line.isEmpty()) + .collect(Collectors.toList()); + if (!lines.isEmpty() && lines.stream().allMatch(line -> STEP_RESULT.matcher(line).matches())) { + stepResults.addAll(lines); + } + Matcher location = SCENARIO_LOCATION.matcher(text); + if (location.find()) { + scenarioLine = Long.parseLong(location.group(2)); + if (featureFile == null && CLASS_NAME.matcher(element.getAttribute("classname")).matches()) { + featureFile = location.group(1); + } + } + }); + Optional failure = element.getChildren().stream() + .filter(child -> child.getName().equals("failure") || child.getName().equals("error")).findFirst(); + if (failure.isPresent()) { + String text = failure.get().getText(); + String message = failure.get().getAttribute("message"); + failureMessage = text.isEmpty() && message != null ? message : text; + } + } + + private static String status(String stepResult) { + return stepResult.substring(stepResult.lastIndexOf('.') + 1); + } + + private void readFailure() { if (!element.getChildren().isEmpty()) { Element child = element.getChildren().get(0); String childName = child.getName(); if (childName.equals("error") && ("io.cucumber.junit.UndefinedThrowable".equals(child.getAttribute("type")) || - "io.cucumber.junit.UndefinedStepException".equals(child.getAttribute("type")))) { + "io.cucumber.junit.UndefinedStepException".equals(child.getAttribute("type")) || + "io.cucumber.junit.platform.engine.UndefinedStepException".equals(child.getAttribute("type")))) { /* sample error io.cucumber.junit.UndefinedThrowable: The step "nothing happened" is undefined (for version io.cucumber 7.0.0) */ errorMessage = child.getAttribute("message"); - int firstIndex = errorMessage.indexOf('\"'); - int lastIndex = errorMessage.lastIndexOf('\"'); - failedStep = errorMessage.substring(firstIndex + 1, lastIndex); + Matcher undefinedStep = UNDEFINED_STEP.matcher(errorMessage); + if (undefinedStep.find()) { + failedStep = undefinedStep.group(1); + } else { + int firstIndex = errorMessage.indexOf('\"'); + int lastIndex = errorMessage.lastIndexOf('\"'); + failedStep = errorMessage.substring(firstIndex + 1, lastIndex); + } return; } - if (childName.equals("failure") || childName.equals("error")) { + if ("io.cucumber.core.runner.AmbiguousStepDefinitionsException".equals(child.getAttribute("type"))) { + // the ambiguous step did not run, the stack trace has no location of it + errorMessage = child.getText(); + Matcher ambiguousStep = AMBIGUOUS_STEP.matcher(String.valueOf(child.getAttribute("message"))); + if (ambiguousStep.find()) { + failedStep = ambiguousStep.group(1); + } + } else if (childName.equals("failure") || childName.equals("error")) { /* sample call stack StackTrace: @@ -213,13 +279,29 @@ public Optional getFeatureName(OctaneFeatureLocator... octaneFeatureLoca int lastIndex = classnamePart.lastIndexOf("-"); classnamePart = classnamePart.substring(0, lastIndex).trim(); } else { - return Optional.of(classname); + return Optional.of(findFeatureNameInName(octaneFeatureLocator[0]).orElse(classname)); } } } return Optional.of(classname); } + // Surefire 3.5.3 and later write the class of the runner as classname, then with the long naming strategy of JUnit 5 + // the name starts with the feature name: "Feature - Scenario" + private Optional findFeatureNameInName(OctaneFeatureLocator octaneFeatureLocator) { + String name = element.getAttribute("name"); + for (int end = name.lastIndexOf(" - "); end > 0; end = name.lastIndexOf(" - ", end - 1)) { + try { + if (octaneFeatureLocator.getOctaneFeatureByName(name.substring(0, end)).isPresent()) { + return Optional.of(name.substring(0, end)); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return Optional.empty(); + } + @Override public Optional getFeatureFile() { return Optional.ofNullable(featureFile); @@ -227,6 +309,62 @@ public Optional getFeatureFile() { @Override public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... octaneFeatureLocator) { + String scenarioName = findScenarioName(feature, octaneFeatureLocator); + if (scenarioName != null) { + outlineIndex = findOutlineIndex(feature, scenarioName); + if (failureMessage != null && !reportsFailedStep(feature.getScenarios(scenarioName))) { + // e.g. a hook or the setup of the test failed: the steps are reported as skipped, never as passed + System.err.println("Scenario \"" + element.getAttribute("name") + + "\" failed outside its steps, its steps are reported as skipped"); + isSkipped = true; + stepResults.clear(); + } + } + return scenarioName; + } + + private boolean reportsFailedStep(List scenarios) { + if (!stepResults.isEmpty()) { + return stepResults.stream().anyMatch(stepResult -> FAILED_STATUSES.contains(status(stepResult))); + } + return scenarios.stream().filter(scenario -> outlineIndex == 0 || scenario.getOutlineIndex() == outlineIndex) + .anyMatch(scenario -> scenario.getSteps().stream().anyMatch(this::isFailedStep)); + } + + private int findOutlineIndex(OctaneFeature feature, String scenarioName) { + List scenarios = new ArrayList<>(); + for (FeatureChild child : feature.getGherkinDocument().getFeature().get().getChildren()) { + child.getScenario().ifPresent(scenarios::add); + child.getRule().ifPresent(rule -> rule.getChildren().forEach(ruleChild -> ruleChild.getScenario().ifPresent(scenarios::add))); + } + return scenarios.stream().filter(scenario -> scenario.getName().equals(scenarioName)).findFirst() + .map(scenario -> findOutlineIndex(scenario.getExamples())).orElse(0); + } + + // the index of the row among the rows of all the Examples, by its numbers in the name or by its line in system-out + private int findOutlineIndex(List examples) { + Matcher row = EXAMPLE_ROW.matcher(element.getAttribute("name")); + boolean hasRowNumbers = row.find(); + int index = 0; + for (int e = 0; e < examples.size(); e++) { + List rows = examples.get(e).getTableBody(); + for (int r = 0; r < rows.size(); r++) { + index++; + if (hasRowNumbers ? Integer.parseInt(row.group(1)) == e + 1 && Integer.parseInt(row.group(2)) == r + 1 + : rows.get(r).getLocation().getLine() == scenarioLine) { + return index; + } + } + } + return 0; + } + + @Override + public OptionalInt getOutlineIndex() { + return outlineIndex > 0 ? OptionalInt.of(outlineIndex) : OptionalInt.empty(); + } + + private String findScenarioName(OctaneFeature feature, OctaneFeatureLocator... octaneFeatureLocator) { String sceName = element.getAttribute("name"); if (!feature.getScenarios(sceName).isEmpty()) { return sceName; @@ -241,7 +379,7 @@ public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... oct if (featureNameOpt.isPresent()) { String featureName = featureNameOpt.get(); if (sceName.startsWith(featureName + " - ")) { - sceName = sceName.split(featureName + " - ")[1].trim(); + sceName = sceName.substring((featureName + " - ").length()).trim(); // check matching scenario after removing feature name from element for (OctaneScenario sce : feature.getScenarios()) { if (sceName.startsWith(sce.getOutlineName())) { @@ -274,7 +412,7 @@ public String getScenarioName(OctaneFeature feature, OctaneFeatureLocator... oct } //check with scenario under rule after removing rule part from element value if(sceNamePart.startsWith(rule.getName() + " - ")){ - String ruleScenarioPart = sceNamePart.split(rule.getName() + " - ")[1].trim(); + String ruleScenarioPart = sceNamePart.substring((rule.getName() + " - ").length()).trim(); for (RuleChild rChild : rule.getChildren()) { if (rChild.getScenario().isPresent() && rChild.getScenario().get().getName().equals(ruleScenarioPart)) { @@ -327,6 +465,11 @@ public TestcaseMeta getTestcaseMeta(OctaneFeature octaneFeature) { @Override public void fillStep(OctaneStep octaneStep) { + int stepIndex = nextStep++; + if (!stepResults.isEmpty() && (failureMessage != null || isSkipped)) { + fillStepFromResult(octaneStep, stepIndex); + return; + } if (isSkipped) { octaneStep.setStatus(Status.SKIPPED); return; @@ -335,29 +478,46 @@ public void fillStep(OctaneStep octaneStep) { octaneStep.setStatus(Status.PASSED); return; } - if (octaneStep.getName().equals(failedStep)) { - octaneStep.setStatus(Status.FAILED); - if(octaneStep.getAddSystemErrors() && systemErrors!= null && !systemErrors.isEmpty()){ - octaneStep.setErrorMessage(errorMessage + "\n" + - "-------------------------------\n" + - "SYSTEM-ERRORS:\n"+systemErrors); - } else { - octaneStep.setErrorMessage(errorMessage); - } - } else if((octaneStep.getKeyword() + " " + octaneStep.getName()).equals(failedStep)){ - octaneStep.setStatus(Status.FAILED); - if(octaneStep.getAddSystemErrors() && systemErrors!= null && !systemErrors.isEmpty()){ - octaneStep.setErrorMessage(errorMessage + "\n" + - "-------------------------------\n" + - "SYSTEM-ERRORS:\n"+systemErrors); - } else { - octaneStep.setErrorMessage(errorMessage); - } + if (isFailedStep(octaneStep)) { + setFailed(octaneStep, errorMessage); } else { octaneStep.setStatus(Status.PASSED); } } + private boolean isFailedStep(OctaneStep octaneStep) { + return octaneStep.getName().equals(failedStep) || (octaneStep.getKeyword() + " " + octaneStep.getName()).equals(failedStep); + } + + private void fillStepFromResult(OctaneStep octaneStep, int stepIndex) { + String stepResult = stepIndex < stepResults.size() ? stepResults.get(stepIndex) : ""; + if (!stepResult.startsWith(octaneStep.getCompleteStepName() + "..")) { + System.err.println("Step \"" + octaneStep.getCompleteStepName() + "\" of scenario \"" + element.getAttribute("name") + + "\" is not in the report, it is reported as skipped"); + octaneStep.setStatus(Status.SKIPPED); + return; + } + String status = status(stepResult); + if (status.equals("passed")) { + octaneStep.setStatus(Status.PASSED); + } else if (FAILED_STATUSES.contains(status)) { + setFailed(octaneStep, failureMessage == null || failureMessage.isEmpty() ? "The step is " + status : failureMessage); + } else { + octaneStep.setStatus(Status.SKIPPED); + } + } + + private void setFailed(OctaneStep octaneStep, String message) { + octaneStep.setStatus(Status.FAILED); + if (octaneStep.getAddSystemErrors() && systemErrors != null && !systemErrors.isEmpty()) { + octaneStep.setErrorMessage(message + "\n" + + "-------------------------------\n" + + "SYSTEM-ERRORS:\n" + systemErrors); + } else { + octaneStep.setErrorMessage(message); + } + } + @Override public String getTestCaseElementName() { return "testcase"; diff --git a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java index 72d6cb3..a3cbd44 100644 --- a/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java +++ b/src/test/java/com/microfocus/bdd/it/Bdd2OctaneHandlerITCase.java @@ -111,6 +111,10 @@ public static List data() { {Framework.PYTHON_BEHAVE, "src/test/resources/python-behave/1.3.3/reports/*.xml", "src/test/resources/python-behave/1.3.3/features/*.feature", "separateResults/python-behave-1.3.3-final.xml", "**/separateResults/standard-python-behave-1.3.3-final.xml"}, //php-behat 4.1.1 report {Framework.PHP_BEHAT, "src/test/resources/php-behat/4.1.1/reports/*.xml", "src/test/resources/php-behat/4.1.1/features/*.feature", "separateResults/php-behat-4.1.1-final.xml", "**/separateResults/standard-php-behat-4.1.1-final.xml"}, + //cucumber-jvm 8.1.0 reports of the junit plugin, and of Surefire 3.6.1 with JUnit 5 and with JUnit 4 + {Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/8.1.0/reports/cucumber.xml", "src/test/resources/cucumber-jvm/8.1.0/features/*.feature", "separateResults/cucumber-jvm-8.1.0-final.xml", "**/separateResults/standard-cucumber-jvm-8.1.0-final.xml"}, + {Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit5/*.xml", "src/test/resources/cucumber-jvm/8.1.0/features/*.feature", "separateResults/cucumber-jvm-8.1.0-surefire-junit5-final.xml", "**/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit5-final.xml"}, + {Framework.CUCUMBER_JVM, "src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit4/*.xml", "src/test/resources/cucumber-jvm/8.1.0/features/*.feature", "separateResults/cucumber-jvm-8.1.0-surefire-junit4-final.xml", "**/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit4-final.xml"}, }); } diff --git a/src/test/java/com/microfocus/bdd/ut/FilesLocatorTest.java b/src/test/java/com/microfocus/bdd/ut/FilesLocatorTest.java index d94ccd9..cfe818c 100644 --- a/src/test/java/com/microfocus/bdd/ut/FilesLocatorTest.java +++ b/src/test/java/com/microfocus/bdd/ut/FilesLocatorTest.java @@ -68,6 +68,6 @@ public void matchPatternFailTest() { public void matchPatternPassTest() { final String pattern = "src/**/*junit*.xml"; List reports = FilesLocator.getReportFiles(pattern); - Assert.assertEquals(22, reports.size()); + Assert.assertEquals(24, reports.size()); } } diff --git a/src/test/java/com/microfocus/bdd/ut/TestCucumberJvmHandler.java b/src/test/java/com/microfocus/bdd/ut/TestCucumberJvmHandler.java index 9b99faa..facb5f2 100644 --- a/src/test/java/com/microfocus/bdd/ut/TestCucumberJvmHandler.java +++ b/src/test/java/com/microfocus/bdd/ut/TestCucumberJvmHandler.java @@ -36,11 +36,30 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.StringWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +import static com.microfocus.bdd.api.Status.FAILED; +import static com.microfocus.bdd.api.Status.PASSED; +import static com.microfocus.bdd.api.Status.SKIPPED; public class TestCucumberJvmHandler { @@ -231,4 +250,419 @@ public void testSurefireEmptyFeatureName(){ !handler.getFeatureName().isPresent()); } + // reports of Cucumber-JVM 8.1.0: of the junit plugin, and of Surefire 3.6.1 with JUnit 5 and with JUnit 4 + private static final String SAMPLE = "src/test/resources/cucumber-jvm/8.1.0/"; + private static final String JUNIT_PLUGIN = "reports/cucumber.xml"; + private static final String SUREFIRE_JUNIT5 = "reports/surefire-junit5/TEST-sample.RunCucumberTest.xml"; + private static final String SUREFIRE_JUNIT4 = "reports/surefire-junit4/TEST-sample.RunCucumberTest.xml"; + + @Test + public void testJunitPluginStepResults() { + // the status of each step is in system-out + assertScenario(getHandler(JUNIT_PLUGIN, "All steps pass"), "basics", "All steps pass", 0, PASSED, PASSED, PASSED, PASSED); + for (String scenario : Arrays.asList("Middle step fails", "Step raises an error", "Pending step", "Ambiguous step")) { + assertScenario(getHandler(JUNIT_PLUGIN, scenario), "basics", scenario, 0, PASSED, PASSED, FAILED, SKIPPED); + } + List steps = assertScenario(getHandler(JUNIT_PLUGIN, "Undefined step"), "basics", "Undefined step", 0, + PASSED, PASSED, FAILED, SKIPPED); + Assert.assertTrue("an empty failure is replaced with the step status", stepXml(steps.get(2)).contains("The step is undefined")); + assertScenario(getHandler(JUNIT_PLUGIN, "Skipped scenario"), "basics", "Skipped scenario", 0, PASSED, PASSED, SKIPPED, SKIPPED); + assertScenario(getHandler(JUNIT_PLUGIN, "Repeated identical steps"), "basics", "Repeated identical steps", 0, + PASSED, PASSED, PASSED, FAILED, SKIPPED); + assertScenario(getHandler(JUNIT_PLUGIN, "First rule - Rule scenario fails"), "rules", "Rule scenario fails", 0, + PASSED, PASSED, PASSED, FAILED); + } + + @Test + public void testSurefireStepResults() { + // the failed step is read from the failure + for (String report : Arrays.asList(SUREFIRE_JUNIT5, SUREFIRE_JUNIT4)) { + String feature = report.equals(SUREFIRE_JUNIT5) ? "Latest basics - " : ""; + assertScenario(getHandler(report, feature + "All steps pass"), "basics", "All steps pass", 0, PASSED, PASSED, PASSED, PASSED); + for (String scenario : Arrays.asList("Middle step fails", "Step raises an error", "Undefined step", "Pending step", "Ambiguous step")) { + List steps = assertScenario(getHandler(report, feature + scenario), "basics", scenario, 0, + PASSED, PASSED, FAILED, SKIPPED); + Assert.assertFalse(scenario, stepXml(steps.get(2)).contains("SYSTEM-ERRORS")); + } + assertScenario(getHandler(report, feature + "Skipped scenario"), "basics", "Skipped scenario", 0, + SKIPPED, SKIPPED, SKIPPED, SKIPPED); + // the failed step is found by its name: the first of the identical steps is reported as failed + assertScenario(getHandler(report, feature + "Repeated identical steps"), "basics", "Repeated identical steps", 0, + PASSED, PASSED, FAILED, SKIPPED, SKIPPED); + } + assertScenario(getHandler(SUREFIRE_JUNIT5, "Latest rules - First rule - Rule scenario fails"), "rules", "Rule scenario fails", 0, + PASSED, PASSED, PASSED, FAILED); + assertScenario(getHandler(SUREFIRE_JUNIT4, "Rule scenario fails"), "rules", "Rule scenario fails", 0, + PASSED, PASSED, PASSED, FAILED); + } + + @Test + public void testUndefinedStepWithParameter() { + // the snippet of the undefined step has the parameter "{int}", the message has the text of the step + CucumberJvmHandler handler = getHandler(""); + assertScenario(handler, "outlines", "Eating of cucumbers", 1, PASSED, FAILED, SKIPPED, SKIPPED); + } + + @Test + public void testFailedStepNotInScenario() { + // e.g. the feature file changed after the run: the failed scenario is reported as skipped, never as passed + assertScenario(getHandler("" + + ""), + "basics", "Middle step fails", 0, SKIPPED, SKIPPED, SKIPPED, SKIPPED); + // the failed step is a step of another Examples row + assertScenario(getHandler("" + + "" + + ""), "outlines", "Eating of cucumbers", 1, SKIPPED, SKIPPED, SKIPPED, SKIPPED); + } + + @Test + public void testSurefireFeature() { + // Surefire 3.6.1 writes the class of the runner as classname + CucumberJvmHandler junit5 = getHandler(SUREFIRE_JUNIT5, "Latest basics - All steps pass"); + Assert.assertFalse(junit5.getFeatureFile().isPresent()); + Assert.assertEquals("the long naming strategy of JUnit 5 starts the name with the feature name", + "Latest basics", junit5.getFeatureName(locator()).get()); + CucumberJvmHandler junit4 = getHandler(SUREFIRE_JUNIT4, "All steps pass"); + Assert.assertEquals("the pretty plugin of JUnit 4 writes the location of the scenario to system-out", + "classpath:features/basics.feature", junit4.getFeatureFile().get()); + } + + @Test + public void testPrettyLocationOfAFeatureClassname() { + // older Surefire versions write the feature name as classname, which tells the feature + Element element = TestUtil.getXmlElement("src/test/resources/cucumber-jvm/3outlines/junit5_scenario_outline1.xml", "testcase", 1); + CucumberJvmHandler handler = new CucumberJvmHandler(); + handler.setElement(element); + Assert.assertTrue(element.getChild("system-out").get().getText().contains("# com/mytest/twoscenarios/TwoSameOutlinedScenario.feature:")); + Assert.assertFalse("the location in system-out is not used", handler.getFeatureFile().isPresent()); + } + + @Test + public void testOutlineRows() { + // by the numbers in the name of the junit plugin and of JUnit 5, by the line of the row in the pretty output of JUnit 4 + String outline = "Eating of cucumbers"; + List reports = Arrays.asList( + new String[]{JUNIT_PLUGIN, outline + " - Few - #1.2: Eating 5 of 20 cucumbers", outline + " - Many - #2.2: Eating 5 of 12 cucumbers"}, + new String[]{SUREFIRE_JUNIT5, "Latest outlines - " + outline + " - Few - Example #1.2: Eating 5 of 20 cucumbers", + "Latest outlines - " + outline + " - Many - Example #2.2: Eating 5 of 12 cucumbers"}, + new String[]{SUREFIRE_JUNIT4, "Eating 5 of 20 cucumbers", "Eating 5 of 12 cucumbers #2"}); + for (String[] report : reports) { + assertScenario(getHandler(report[0], report[1]), "outlines", outline, 2, PASSED, PASSED, PASSED, FAILED); + assertScenario(getHandler(report[0], report[2]), "outlines", outline, 4, PASSED, PASSED, PASSED, FAILED); + } + // the rows 1 and 4 have the same values + assertScenario(getHandler(SUREFIRE_JUNIT4, "Eating 5 of 12 cucumbers #1"), "outlines", outline, 1, PASSED, PASSED, PASSED, PASSED); + assertScenario(getHandler(JUNIT_PLUGIN, "Counting cucumbers - #1.1"), "outlines", "Counting cucumbers", 1, PASSED, PASSED, PASSED); + assertScenario(getHandler(SUREFIRE_JUNIT5, "Latest outlines - Counting cucumbers - Examples - Example #1.1"), "outlines", + "Counting cucumbers", 1, PASSED, PASSED, PASSED); + assertScenario(getHandler(SUREFIRE_JUNIT4, "Counting cucumbers"), "outlines", "Counting cucumbers", 1, PASSED, PASSED, PASSED); + } + + @Test + public void testFailureMessageAttribute() { + // the message attribute is used when the failure has no text + CucumberJvmHandler handler = getHandler("" + + ""); + List steps = assertScenario(handler, "basics", "Middle step fails", 0, PASSED, PASSED, FAILED, SKIPPED); + Assert.assertTrue(stepXml(steps.get(2)).contains("")); + } + + @Test + public void testStepResultOfAnotherStep() { + // e.g. the feature file changed after the run: the step that is not in the report is skipped + CucumberJvmHandler handler = getHandler("" + + ""); + assertScenario(handler, "basics", "Middle step fails", 0, PASSED, SKIPPED, SKIPPED, SKIPPED); + } + + @Test + public void testUnknownStepResult() { + CucumberJvmHandler handler = getHandler(""); + assertScenario(handler, "basics", "Skipped scenario", 0, PASSED, PASSED, SKIPPED, SKIPPED); + } + + @Test + public void testRowNotInExamples() { + // e.g. the feature file changed after the run: the rows are matched in the order of the report + OctaneFeature outlines = TestUtil.parseFeatureFile(SAMPLE + "features/outlines.feature"); + CucumberJvmHandler junitPlugin = getHandler(""); + Assert.assertEquals("Eating of cucumbers", junitPlugin.getScenarioName(outlines, locator())); + Assert.assertFalse(junitPlugin.getOutlineIndex().isPresent()); + CucumberJvmHandler junit4 = getHandler("" + + ""); + Assert.assertEquals("Eating of cucumbers", junit4.getScenarioName(outlines, locator())); + Assert.assertFalse(junit4.getOutlineIndex().isPresent()); + } + + @Test + public void testFeatureNameWithDash() throws IOException { + // the feature "Verify - with dash" of JUnit 5, not the feature "Verify" + OctaneFeature feature = writeFeature("verify_rule_outline.feature", "Feature: Verify - with dash", "", " Background:", + " Given the background is ready", "", " Rule: A rule", " Background:", " Given a rule background step", "", + " Scenario Outline: Outline in a rule ", " Given the value \"\" is accepted", "", " Examples:", + " | value |", " | x |", " | a (b) c |"); + writeFeature("verify.feature", "Feature: Verify", "", " Scenario: Another scenario", " Given a passing step"); + OctaneFeatureLocator locator = new OctaneFeatureLocator(Arrays.asList("target/cucumber-jvm/verify.feature", feature.getFeatureFile())); + CucumberJvmHandler handler = getHandler("\n \n "); + Assert.assertEquals("Verify - with dash", handler.getFeatureName(locator).get()); + assertScenario(handler, feature, locator, "Outline in a rule ", 2, PASSED, PASSED, FAILED); + } + + @Test + public void testRowsWithSpecialValues() throws IOException { + // the names of JUnit 4 have the values of the rows, the pretty output has the lines of the rows + OctaneFeature feature = writeFeature("verify_values.feature", "Feature: Verify values", "", " Scenario Outline: Special ", + " Given the value \"\" is accepted", "", " Examples:", " | value |", " | a \\| b |", " | |", + " | \u00fcn\u00ef |", " | a (b) c |", " | 1 |", " | 1 |"); + OctaneFeatureLocator locator = new OctaneFeatureLocator(Collections.singletonList(feature.getFeatureFile())); + String stepDefinition = "&#27;[39m &#27;[90m# sample.StepDefinitions.theValueIsAccepted(java.lang.String)&#27;[39m\n"; + assertScenario(getHandler("\n \n "), + feature, locator, "Special ", 2, PASSED); + assertScenario(getHandler("\n" + + " \n \n "), + feature, locator, "Special ", 4, FAILED); + assertScenario(getHandler("\n \n "), + feature, locator, "Special ", 6, PASSED); + } + + @Test + public void testNamesWithParentheses() throws IOException { + // the names of the feature and of the rule are not regular expressions + OctaneFeature feature = writeFeature("verify_special_names.feature", "Feature: Verify (special) names [x]", "", + " Scenario: Plain scenario (a)", " Given a passing step", "", " Scenario Outline: Outline (c) ", + " Given the value \"\" is accepted", "", " Examples: Values (d)", " | value |", " | x |", + " | a (b) c |", "", " Rule: A rule (with parentheses)", "", " Scenario: Rule scenario (b)", " Given a passing step", + " Then the value \"a (b) c\" is accepted"); + OctaneFeatureLocator locator = new OctaneFeatureLocator(Collections.singletonList(feature.getFeatureFile())); + String stackTrace = "\n" + + "\n" + stackTrace + "18)\n]]>\n\n\n"), + feature, locator, "Rule scenario (b)", 0, PASSED, FAILED); + // the Surefire report of JUnit 5 + assertScenario(getHandler(""), + feature, locator, "Plain scenario (a)", 0, PASSED); + assertScenario(getHandler("\n " + stackTrace + "7)\n]]>\n "), + feature, locator, "Outline (c) ", 2, FAILED); + assertScenario(getHandler("\n " + + stackTrace + "18)\n]]>\n "), + feature, locator, "Rule scenario (b)", 0, PASSED, FAILED); + } + + @Test + public void testReportOfOneExamplesRow() throws Exception { + // e.g. a rerun of the last row of "Many" + assertReportOfOneExamplesRow(JUNIT_PLUGIN, "Eating <eat> of <start> cucumbers - Many - #2.2: Eating 5 of 12 cucumbers"); + assertReportOfOneExamplesRow(SUREFIRE_JUNIT5, + "Latest outlines - Eating <eat> of <start> cucumbers - Many - Example #2.2: Eating 5 of 12 cucumbers"); + assertReportOfOneExamplesRow(SUREFIRE_JUNIT4, "Eating 5 of 12 cucumbers #2"); + } + + @Test + public void testFailureOutsideSteps() throws IOException { + // e.g. a hook failed: the steps are reported as skipped, a failed scenario is never reported as passed + OctaneFeature hooks = writeFeature("hooks.feature", "Feature: Latest hooks", "", + " @failing-before-hook", " Scenario: Before hook fails", " Given a passing step", " Then a final passing step", "", + " @failing-after-hook", " Scenario: After hook fails", " Given a passing step", " Then a final passing step"); + OctaneFeatureLocator locator = new OctaneFeatureLocator(Collections.singletonList(hooks.getFeatureFile())); + // the junit plugin report: the steps of a failed Before hook were skipped, the steps of a failed After hook passed + assertScenario(getHandler("\n" + + "\n\n\n\n"), + hooks, locator, "Before hook fails", 0, SKIPPED, SKIPPED); + assertScenario(getHandler("\n" + + "\n\n\n\n"), + hooks, locator, "After hook fails", 0, SKIPPED, SKIPPED); + // the Surefire reports have no step results + assertScenario(getHandler("\n" + + " \n "), + hooks, locator, "After hook fails", 0, SKIPPED, SKIPPED); + assertScenario(getHandler("\n" + + " \n \n "), + hooks, locator, "After hook fails", 0, SKIPPED, SKIPPED); + } + + @Test + public void testTrimmedStackTrace() { + // with the trimStackTrace option of Surefire the failure has only its first line, the location of the failed step is lost + assertScenario(getHandler("\n" + + " \n "), + "basics", "Middle step fails", 0, SKIPPED, SKIPPED, SKIPPED, SKIPPED); + // the pretty output of JUnit 4 has no location of a pending step + assertScenario(getHandler("\n" + + " \n \n "), + "basics", "Pending step", 0, SKIPPED, SKIPPED, SKIPPED, SKIPPED); + } + + private static void assertReportOfOneExamplesRow(String report, String testcaseName) throws Exception { + String xml = new String(Files.readAllBytes(Paths.get(SAMPLE + report)), StandardCharsets.UTF_8); + int start = xml.lastIndexOf("", start) + "".length()); + Path reportFile = Paths.get("target", "cucumber-jvm-one-examples-row.xml"); + Path resultFile = Paths.get("target", "cucumber-jvm-one-examples-row-result.xml"); + Files.write(reportFile, ("" + row + "").getBytes(StandardCharsets.UTF_8)); + + new Bdd2Octane(Collections.singletonList(reportFile.toString()), Collections.singletonList(SAMPLE + "features/outlines.feature"), + resultFile.toString(), "cucumber-jvm").run(); + + Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(resultFile.toFile()); + NodeList scenarios = result.getElementsByTagName("scenario"); + Assert.assertEquals(report + ": only the reported row is in the result", 1, scenarios.getLength()); + org.w3c.dom.Element scenario = (org.w3c.dom.Element) scenarios.item(0); + Assert.assertEquals(report + ": the row is not matched by its order", "4", scenario.getAttribute("outlineIndex")); + org.w3c.dom.Element failedStep = (org.w3c.dom.Element) scenario.getElementsByTagName("step").item(3); + Assert.assertEquals("Then I should have 8 cucumbers", failedStep.getAttribute("name")); + Assert.assertEquals("failed", failedStep.getAttribute("status")); + } + + private static OctaneFeatureLocator locator() { + return new OctaneFeatureLocator(Arrays.asList(SAMPLE + "features/basics.feature", SAMPLE + "features/outlines.feature", + SAMPLE + "features/rules.feature")); + } + + private static CucumberJvmHandler getHandler(String report, String testcaseName) { + try (JunitReportReader reader = new JunitReportReader(new FileInputStream(SAMPLE + report), "testcase")) { + for (Element element : reader) { + if (testcaseName.equals(element.getAttribute("name"))) { + CucumberJvmHandler handler = new CucumberJvmHandler(); + handler.setElement(element); + return handler; + } + } + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + throw new IllegalArgumentException("No testcase \"" + testcaseName + "\" in " + report); + } + + private static CucumberJvmHandler getHandler(String testcaseXml) { + try (JunitReportReader reader = new JunitReportReader( + new ByteArrayInputStream(("" + testcaseXml + "").getBytes(StandardCharsets.UTF_8)), "testcase")) { + CucumberJvmHandler handler = new CucumberJvmHandler(); + handler.setElement(reader.iterator().next()); + return handler; + } catch (IOException | XMLStreamException e) { + throw new IllegalStateException(e); + } + } + + // fills the steps as Bdd2Octane does: the steps after the first step that did not pass are skipped + private static List assertScenario(CucumberJvmHandler handler, String featureName, String scenarioName, int outlineIndex, + Status... statuses) { + OctaneFeature feature = TestUtil.parseFeatureFile(SAMPLE + "features/" + featureName + ".feature"); + return assertScenario(handler, feature, locator(), scenarioName, outlineIndex, statuses); + } + + private static List assertScenario(CucumberJvmHandler handler, OctaneFeature feature, OctaneFeatureLocator locator, + String scenarioName, int outlineIndex, Status... statuses) { + Assert.assertEquals("handler can get back scenario name", scenarioName, handler.getScenarioName(feature, locator)); + Assert.assertEquals("handler can get back outline index", outlineIndex, handler.getOutlineIndex().orElse(0)); + List steps = feature.getScenarios(scenarioName).get(Math.max(outlineIndex - 1, 0)).getSteps(); + boolean stopped = false; + for (OctaneStep step : steps) { + if (stopped) { + step.setStatus(SKIPPED); + } else { + handler.fillStep(step); + stopped = step.getStatus() != PASSED; + } + } + Assert.assertEquals("handler can get back step statuses", Arrays.asList(statuses), + steps.stream().map(OctaneStep::getStatus).collect(Collectors.toList())); + return steps; + } + + private static OctaneFeature writeFeature(String fileName, String... lines) throws IOException { + Path featureFile = Paths.get("target", "cucumber-jvm", fileName); + Files.createDirectories(featureFile.getParent()); + Files.write(featureFile, (String.join("\n", lines) + "\n").getBytes(StandardCharsets.UTF_8)); + return TestUtil.parseFeatureFile(featureFile.toString()); + } + + // a step result of the junit plugin: the step and its status separated by dots + private static String stepResult(String step, String status) { + StringBuilder line = new StringBuilder(step).append(".."); + while (line.length() < 76) { + line.append('.'); + } + return line.append(status).append('\n').toString(); + } + + private static String stepXml(OctaneStep step) { + StringWriter xml = new StringWriter(); + try { + XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(xml); + step.writeToXml(writer); + writer.flush(); + } catch (XMLStreamException e) { + throw new IllegalStateException(e); + } + return xml.toString(); + } } diff --git a/src/test/resources/cucumber-jvm/8.1.0/features/basics.feature b/src/test/resources/cucumber-jvm/8.1.0/features/basics.feature new file mode 100644 index 0000000..ff65467 --- /dev/null +++ b/src/test/resources/cucumber-jvm/8.1.0/features/basics.feature @@ -0,0 +1,62 @@ +@BSPID2001REV0.1.0 +Feature: Latest basics + + Background: + Given the background is ready + + Scenario: All steps pass + Given a passing step + When another passing step + Then a final passing step + + Scenario: Middle step fails + Given a passing step + When a step that fails with "middle step failure" + Then a final passing step + + Scenario: Step raises an error + Given a passing step + When a step that raises an error + Then a final passing step + + Scenario: Undefined step + Given a passing step + When a step without any definition + Then a final passing step + + Scenario: Pending step + Given a passing step + When a pending step + Then a final passing step + + Scenario: Ambiguous step + Given a passing step + When an ambiguous step + Then a final passing step + + Scenario: Skipped scenario + Given a passing step + When a step that skips the scenario + Then a final passing step + + Scenario: Repeated identical steps + Given a passing step + When the counter is incremented + And the counter is incremented + Then a final passing step + + Scenario: Data table and doc string + Given the following cucumbers: + | colour | count | + | green | 3 | + | red | 1 | + And the following note: + """ + Line one with & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step diff --git a/src/test/resources/cucumber-jvm/8.1.0/features/outlines.feature b/src/test/resources/cucumber-jvm/8.1.0/features/outlines.feature new file mode 100644 index 0000000..0d36d4c --- /dev/null +++ b/src/test/resources/cucumber-jvm/8.1.0/features/outlines.feature @@ -0,0 +1,31 @@ +Feature: Latest outlines + + Background: + Given the background is ready + + Scenario Outline: Eating of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 | diff --git a/src/test/resources/cucumber-jvm/8.1.0/features/rules.feature b/src/test/resources/cucumber-jvm/8.1.0/features/rules.feature new file mode 100644 index 0000000..2c5a8b1 --- /dev/null +++ b/src/test/resources/cucumber-jvm/8.1.0/features/rules.feature @@ -0,0 +1,17 @@ +Feature: Latest rules + + Background: + Given the background is ready + + Rule: First rule + Background: + Given a rule background step + + Scenario: Rule scenario fails + Given a passing step + Then a step that fails with "rule failure" + + Rule: Second rule + Scenario: Rule scenario passes + Given a passing step + Then a final passing step diff --git a/src/test/resources/cucumber-jvm/8.1.0/reports/cucumber.xml b/src/test/resources/cucumber-jvm/8.1.0/reports/cucumber.xml new file mode 100644 index 0000000..b8c00b9 --- /dev/null +++ b/src/test/resources/cucumber-jvm/8.1.0/reports/cucumber.xml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit4/TEST-sample.RunCucumberTest.xml b/src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit4/TEST-sample.RunCucumberTest.xml new file mode 100644 index 0000000..7a0de52 --- /dev/null +++ b/src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit4/TEST-sample.RunCucumberTest.xml @@ -0,0 +1,333 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + & "quotes" + Line two + """ + &#27;[32m✔&#27;[39m &#27;[32m&#27;[1mThen &#27;[22mthe cucumber count is &#27;[1m4&#27;[22m&#27;[39m &#27;[90m# sample.StepDefinitions.theCucumberCountIs(int)&#27;[39m +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit5/TEST-sample.RunCucumberTest.xml b/src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit5/TEST-sample.RunCucumberTest.xml new file mode 100644 index 0000000..9b71ea0 --- /dev/null +++ b/src/test/resources/cucumber-jvm/8.1.0/reports/surefire-junit5/TEST-sample.RunCucumberTest.xml @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-final.xml b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-final.xml new file mode 100644 index 0000000..e5ad0f3 --- /dev/null +++ b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-final.xml @@ -0,0 +1,408 @@ + + + + + + & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 |]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit4-final.xml b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit4-final.xml new file mode 100644 index 0000000..b86db0b --- /dev/null +++ b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit4-final.xml @@ -0,0 +1,357 @@ + + + + + + & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 |]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit5-final.xml b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit5-final.xml new file mode 100644 index 0000000..200901b --- /dev/null +++ b/src/test/resources/standardOctaneGherkinReport/separateResults/standard-cucumber-jvm-8.1.0-surefire-junit5-final.xml @@ -0,0 +1,351 @@ + + + + + + & "quotes" + Line two + """ + Then the cucumber count is 4 + + Scenario: Shared scenario name + Given a passing step + Then a final passing step]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + of cucumbers + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + Examples: Few + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 14 | + + Examples: Many + | start | eat | left | + | 100 | 1 | 99 | + | 12 | 5 | 8 | + + Scenario: Shared scenario name + Given a passing step + Then a step that fails with "same name in another feature" + + Scenario Outline: Counting cucumbers + Given there are cucumbers + Then the cucumber count is + + Examples: + | count | + | 3 |]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +