diff --git a/allure-karate/src/main/java/io/qameta/allure/karate/AllureKarate.java b/allure-karate/src/main/java/io/qameta/allure/karate/AllureKarate.java index a300f0ec..79be5e9b 100644 --- a/allure-karate/src/main/java/io/qameta/allure/karate/AllureKarate.java +++ b/allure-karate/src/main/java/io/qameta/allure/karate/AllureKarate.java @@ -57,6 +57,7 @@ import static io.qameta.allure.util.ResultsUtils.createLabel; import static io.qameta.allure.util.ResultsUtils.createLink; import static io.qameta.allure.util.ResultsUtils.createParameter; +import static io.qameta.allure.util.ResultsUtils.md5; /** * @author charlie (Dmitry Baev). @@ -89,19 +90,22 @@ public AllureKarate(final AllureLifecycle lifecycle) { public boolean beforeScenario(final ScenarioRuntime sr) { final Feature feature = sr.featureRuntime.result.getFeature(); final String featureName = feature.getName(); - final String featureNameQualified = feature.getPackageQualifiedName(); + final String featureNameQualified = feature.getResource().getRelativePath(); final Scenario scenario = sr.scenario; - final String scenarioName = scenario.getName(); final String uuid = UUID.randomUUID().toString(); sr.magicVariables.put(ALLURE_UUID, uuid); + final String nameOrLine = getName(scenario, String.valueOf(scenario.getLine())); + final String testCaseId = md5(String.format("%s:%s", featureNameQualified, nameOrLine)); + final String fullName = String.format("%s:%d", featureNameQualified, scenario.getLine()); final TestResult result = new TestResult() .setUuid(uuid) - .setFullName(String.format("%s | %s", featureNameQualified, scenarioName)) - .setName(scenarioName) + .setFullName(fullName) + .setName(getName(scenario, fullName)) .setDescription(scenario.getDescription()) - .setTestCaseId(scenario.getUniqueId()) + .setTestCaseId(testCaseId) + .setHistoryId(md5(scenario.getUniqueId())) .setStage(Stage.RUNNING); final List labels = sr.tags.getTags(); @@ -119,6 +123,12 @@ public boolean beforeScenario(final ScenarioRuntime sr) { return true; } + private static String getName(final Scenario scenario, final String defaultValue) { + return Objects.isNull(scenario.getName()) || scenario.getName().trim().isEmpty() + ? defaultValue + : scenario.getName().trim(); + } + @Override public void afterScenario(final ScenarioRuntime sr) { final String uuid = (String) sr.magicVariables.get(ALLURE_UUID); @@ -131,9 +141,9 @@ public void afterScenario(final ScenarioRuntime sr) { final Status status = !sr.isFailed() ? Status.PASSED : maybeResult - .map(ScenarioResult::getError) - .flatMap(ResultsUtils::getStatus) - .orElse(null); + .map(ScenarioResult::getError) + .flatMap(ResultsUtils::getStatus) + .orElse(null); final StatusDetails statusDetails = maybeResult .map(ScenarioResult::getError) @@ -193,9 +203,9 @@ public void afterStep(final StepResult result, final Status status = !stepResult.isFailed() ? Status.PASSED : Optional.of(stepResult) - .map(Result::getError) - .flatMap(ResultsUtils::getStatus) - .orElse(null); + .map(Result::getError) + .flatMap(ResultsUtils::getStatus) + .orElse(null); final StatusDetails statusDetails = Optional.of(stepResult) .map(Result::getError) @@ -209,8 +219,8 @@ public void afterStep(final StepResult result, lifecycle.stopStep(uuid); if (stepResult.isFailed() - && sr.engine.getConfig().getDriverOptions() != null - && (Boolean) sr.engine.getConfig().getDriverOptions().get("screenshotOnFailure") + && sr.engine.getConfig().getDriverOptions() != null + && (Boolean) sr.engine.getConfig().getDriverOptions().get("screenshotOnFailure") ) { addToStepsAndTcUuids(uuid, lifecycle.getCurrentTestCase().get()); addToStepAndUuids(uuid, step); diff --git a/allure-karate/src/test/java/io/qameta/allure/karate/AllureKarateTest.java b/allure-karate/src/test/java/io/qameta/allure/karate/AllureKarateTest.java index 21fba0ec..a1cf77b3 100644 --- a/allure-karate/src/test/java/io/qameta/allure/karate/AllureKarateTest.java +++ b/allure-karate/src/test/java/io/qameta/allure/karate/AllureKarateTest.java @@ -28,6 +28,7 @@ import static io.qameta.allure.model.Status.BROKEN; import static io.qameta.allure.model.Status.PASSED; +import static io.qameta.allure.util.ResultsUtils.md5; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; @@ -46,11 +47,11 @@ void shouldCreateNameAndFullName() { .containsExactlyInAnyOrder( tuple( "Some api* request # comment 1", - "testdata.description-and-name | Some api* request # comment 1" + "testdata/description-and-name.feature:3" ), tuple( - "", - "testdata.description-and-name | " + "testdata/description-and-name.feature:8", + "testdata/description-and-name.feature:8" ) ); } @@ -135,8 +136,8 @@ void shouldCreateTestCaseIdAndName() { assertThat(results.getTestResults()) .extracting(TestResult::getTestCaseId, TestResult::getTestCaseName) .containsExactlyInAnyOrder( - tuple("testdata.description-and-name_1", null), - tuple("testdata.description-and-name_2", null) + tuple(md5("testdata/description-and-name.feature:Some api* request # comment 1"), null), + tuple(md5("testdata/description-and-name.feature:8"), null) ); } @@ -147,9 +148,9 @@ void shouldCreateTestCaseIdAndNamesOfParametrizedTest() { assertThat(results.getTestResults()) .extracting(TestResult::getName, TestResult::getTestCaseId) .containsExactlyInAnyOrder( - tuple("/login should return 200", "testdata.parametrized-test_1_1"), - tuple("/user should return 301", "testdata.parametrized-test_1_2"), - tuple("/pages should return 404", "testdata.parametrized-test_1_3") + tuple("/login should return 200", md5("testdata/parametrized-test.feature:/login should return 200")), + tuple("/user should return 301", md5("testdata/parametrized-test.feature:/user should return 301")), + tuple("/pages should return 404", md5("testdata/parametrized-test.feature:/pages should return 404")) ); } @@ -164,7 +165,20 @@ void shouldCreateParamsForParametrizedTest() { .containsExactlyInAnyOrder( tuple("path", "login"), tuple("status", "200") - ); + ); + } + + @Test + void shouldCreateHistoryIdAndNamesOfParametrizedTest() { + final AllureResults results = runApi("classpath:testdata/parametrized-test.feature"); + + assertThat(results.getTestResults()) + .extracting(TestResult::getName, TestResult::getHistoryId) + .containsExactlyInAnyOrder( + tuple("/login should return 200", md5("testdata.parametrized-test_1_1")), + tuple("/user should return 301", md5("testdata.parametrized-test_1_2")), + tuple("/pages should return 404", md5("testdata.parametrized-test_1_3")) + ); } @Test