From bea9dd83d3607ce7db1e7554a6372cf3f7e5eeb8 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Sat, 14 Sep 2024 18:11:19 +0300 Subject: [PATCH] Fixes #32 --- .github/workflows/ci.yml | 1 + .../reportportal/karate/ReportPortalHook.java | 55 ++++++++++--------- ...lTheSameFeatureWithParametersHookTest.java | 4 +- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2e04d1..7396235 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,6 +43,7 @@ jobs: java-version: '11' - name: Build with Gradle + timeout-minutes: 30 run: ./gradlew build - name: Codecov upload diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index dc6570e..87dd831 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -162,30 +162,34 @@ protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureRuntime fr) { return rq; } + private String getFeatureNameForReport(FeatureRuntime fr) { + int callDepth = ofNullable(fr.caller).map(c -> c.depth).orElse(0); + return callDepth + ":" + fr.featureCall.feature.getNameForReport(); + } + @Override public boolean beforeFeature(FeatureRuntime fr) { StartTestItemRQ rq = buildStartFeatureRq(fr); - featureIdMap.computeIfAbsent(fr.featureCall.feature.getNameForReport(), - f -> new MemoizingSupplier<>(() -> { - if(fr.caller == null || fr.caller.depth == 0) { - return launch.get().startTestItem(rq); - } else { - Maybe scenarioId = scenarioIdMap.get(fr.caller.parentRuntime.scenario.getUniqueId()); - if (scenarioId == null) { - LOGGER.error("ERROR: Trying to post unspecified scenario."); - return launch.get().startTestItem(rq); - } - rq.setType(ItemType.STEP.name()); - rq.setHasStats(false); - rq.setName(getInnerFeatureName(rq.getName())); - Maybe itemId = launch.get().startTestItem(scenarioId, rq); - innerFeatures.add(itemId); - if (StringUtils.isNotBlank(rq.getDescription())) { - ReportPortalUtils.sendLog(itemId, rq.getDescription(), LogLevel.INFO, rq.getStartTime()); - } - return itemId; - } - })); + featureIdMap.computeIfAbsent(getFeatureNameForReport(fr), f -> new MemoizingSupplier<>(() -> { + if (ofNullable(fr.caller).map(c -> c.depth).orElse(0) == 0) { + return launch.get().startTestItem(rq); + } else { + Maybe scenarioId = scenarioIdMap.get(fr.caller.parentRuntime.scenario.getUniqueId()); + if (scenarioId == null) { + LOGGER.error("ERROR: Trying to post unspecified scenario."); + return launch.get().startTestItem(rq); + } + rq.setType(ItemType.STEP.name()); + rq.setHasStats(false); + rq.setName(getInnerFeatureName(rq.getName())); + Maybe itemId = launch.get().startTestItem(scenarioId, rq); + innerFeatures.add(itemId); + if (StringUtils.isNotBlank(rq.getDescription())) { + ReportPortalUtils.sendLog(itemId, rq.getDescription(), LogLevel.INFO, rq.getStartTime()); + } + return itemId; + } + })); return true; } @@ -202,7 +206,7 @@ protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureRuntime fr) { @Override public void afterFeature(FeatureRuntime fr) { - Optional> optionalId = ofNullable(featureIdMap.remove(fr.featureCall.feature.getNameForReport())).map(Supplier::get); + Optional> optionalId = ofNullable(featureIdMap.remove(getFeatureNameForReport(fr))).map(Supplier::get); if (optionalId.isEmpty()) { LOGGER.error("ERROR: Trying to finish unspecified feature."); } @@ -222,8 +226,7 @@ public void afterFeature(FeatureRuntime fr) { @Nonnull protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioRuntime sr) { StartTestItemRQ rq = ReportPortalUtils.buildStartScenarioRq(sr.result); - ofNullable(featureIdMap.get(sr.featureRuntime.featureCall.feature.getNameForReport())) - .map(Supplier::get) + ofNullable(featureIdMap.get(getFeatureNameForReport(sr.featureRuntime))).map(Supplier::get) .map(featureId -> innerFeatures.contains(featureId) ? featureId : null) .ifPresent(featureId -> { rq.setType(ItemType.STEP.name()); @@ -236,8 +239,8 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioRuntime sr) { @Override public boolean beforeScenario(ScenarioRuntime sr) { StartTestItemRQ rq = buildStartScenarioRq(sr); - Optional> optionalId = ofNullable(featureIdMap.get(sr.featureRuntime.featureCall.feature.getNameForReport())) - .map(Supplier::get); + Optional> optionalId = ofNullable(featureIdMap.get(getFeatureNameForReport(sr.featureRuntime))).map( + Supplier::get); if (optionalId.isEmpty()) { LOGGER.error("ERROR: Trying to post unspecified feature."); } diff --git a/src/test/java/com/epam/reportportal/karate/call/CallTheSameFeatureWithParametersHookTest.java b/src/test/java/com/epam/reportportal/karate/call/CallTheSameFeatureWithParametersHookTest.java index d3b9040..b39e48c 100644 --- a/src/test/java/com/epam/reportportal/karate/call/CallTheSameFeatureWithParametersHookTest.java +++ b/src/test/java/com/epam/reportportal/karate/call/CallTheSameFeatureWithParametersHookTest.java @@ -83,10 +83,10 @@ public void test_call_feature_with_parameters_hook_reporting() { ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture()); + verify(client, times(4)).startTestItem(same(scenarioId), stepCaptor.capture()); ArgumentCaptor innerScenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(same(innerFeatureId), innerScenarioCaptor.capture()); ArgumentCaptor innerStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(innerScenarioId), innerStepCaptor.capture()); + verify(client, times(4)).startTestItem(same(innerScenarioId), innerStepCaptor.capture()); } }