diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 7b1a7d5..9b561f8 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -56,6 +56,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalPublisher { + public static final String BACKGROUND_PREFIX = "BACKGROUND: "; public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; public static final String VARIABLE_PATTERN = @@ -349,6 +350,9 @@ public void finishScenario(ScenarioResult scenarioResult) { protected StartTestItemRQ buildStartStepRq(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { Step step = stepResult.getStep(); String stepName = step.getPrefix() + " " + step.getText(); + if (step.isBackground()) { + stepName = BACKGROUND_PREFIX + stepName; + } StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP); rq.setHasStats(false); if (step.isOutline()) { diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java new file mode 100644 index 0000000..6978600 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -0,0 +1,57 @@ +package com.epam.reportportal.karate.background; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.service.ReportPortal; +import com.epam.reportportal.service.ReportPortalClient; +import com.epam.reportportal.util.test.CommonUtils; +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class BackgroundTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_background_steps() { + var results = TestUtils.runAsReport(rp, "classpath:feature/background.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); + List steps = stepCaptor.getAllValues(); + assertThat(steps, hasSize(3)); + + assertThat(steps.get(0).getName(), equalTo("BACKGROUND: Given def four = 4")); + } +} diff --git a/src/test/resources/feature/background.feature b/src/test/resources/feature/background.feature new file mode 100644 index 0000000..90069cd --- /dev/null +++ b/src/test/resources/feature/background.feature @@ -0,0 +1,8 @@ +Feature: the test to show item description reporting + + Background: Set variable + Given def four = 4 + + Scenario: Verify math + When def acualFour = 2 * 2 + Then assert acualFour == four