Skip to content

Commit

Permalink
Merge pull request #39 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Sep 25, 2024
2 parents 69d9953 + 916c2dc commit 6eed5b1
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.2.15](https://github.com/reportportal/client-java/releases/tag/5.2.15), by @HardNorth
### Fixed
- Issue [#38](https://github.com/reportportal/agent-java-karate/issues/38): Rerun failed scenarios, by @HardNorth

## [5.1.1]
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ karate_version=1.4.1
junit_version=5.10.1
mockito_version=5.4.0
test_utils_version=0.0.3
client_version=5.2.14
client_version=5.2.15
slf4j_api_version=2.0.7
logger_version=5.2.2
hamcrest_version=2.2
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/epam/reportportal/karate/ReportPortalHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureRuntime fr) {

@Override
public void afterFeature(FeatureRuntime fr) {
Optional<Maybe<String>> optionalId = ofNullable(featureIdMap.remove(getFeatureNameForReport(fr))).map(Supplier::get);
Optional<Maybe<String>> optionalId = ofNullable(featureIdMap.get(getFeatureNameForReport(fr))).map(Supplier::get);
if (optionalId.isEmpty()) {
LOGGER.error("ERROR: Trying to finish unspecified feature.");
}
Expand Down Expand Up @@ -239,11 +239,14 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioRuntime sr) {
@Override
public boolean beforeScenario(ScenarioRuntime sr) {
StartTestItemRQ rq = buildStartScenarioRq(sr);
Optional<Maybe<String>> optionalId = ofNullable(featureIdMap.get(getFeatureNameForReport(sr.featureRuntime))).map(
Supplier::get);
Optional<Maybe<String>> optionalId = ofNullable(featureIdMap.get(getFeatureNameForReport(sr.featureRuntime))).map(Supplier::get);
if (optionalId.isEmpty()) {
LOGGER.error("ERROR: Trying to post unspecified feature.");
}
ofNullable(scenarioIdMap.get(sr.scenario.getUniqueId())).map(Maybe::blockingGet).ifPresent(id -> {
rq.setRetry(true);
rq.setRetryOf(id);
});
optionalId.ifPresent(featureId -> {
Maybe<String> scenarioId = launch.get().startTestItem(featureId, rq);
if (innerFeatures.contains(featureId) && StringUtils.isNotBlank(rq.getDescription())) {
Expand Down Expand Up @@ -323,7 +326,7 @@ public void finishBackground(@Nullable StepResult stepResult, @Nonnull ScenarioR

@Override
public void afterScenario(ScenarioRuntime sr) {
Maybe<String> scenarioId = scenarioIdMap.remove(sr.scenario.getUniqueId());
Maybe<String> scenarioId = scenarioIdMap.get(sr.scenario.getUniqueId());
if (scenarioId == null) {
LOGGER.error("ERROR: Trying to finish unspecified scenario.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.karate.retry;

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.FinishTestItemRQ;
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
import com.intuit.karate.Results;
import com.intuit.karate.core.ScenarioResult;
import org.apache.commons.lang3.tuple.Pair;
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.*;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.*;

public class RetryFailedTest {
private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature";
private final String launchUuid = CommonUtils.namedId("launch_");
private final String featureId = CommonUtils.namedId("feature_");
private final List<String> scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(2).collect(Collectors.toList());
private final List<String> stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(6).collect(Collectors.toList());

private final List<Pair<String, List<String>>> scenarioSteps = Stream.of(Pair.of(scenarioIds.get(0), stepIds.subList(0, 3)),
Pair.of(scenarioIds.get(1), stepIds.subList(3, 6))
)
.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, launchUuid, featureId, scenarioSteps);
mockBatchLogging(client);
}

@Test
public void test_simple_one_step_failed_retry() {
Results results = TestUtils.runAsHook(rp, TEST_FEATURE);
assertThat(results.getFailCount(), equalTo(1));

List<ScenarioResult> failedResults = results.getScenarioResults().filter(ScenarioResult::isFailed).collect(Collectors.toList());
assertThat(failedResults, hasSize(1));

results.getSuite().retryScenario(failedResults.get(0).getScenario());

verify(client).startTestItem(any(StartTestItemRQ.class));
ArgumentCaptor<StartTestItemRQ> scenarioStartCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client, times(2)).startTestItem(same(featureId), scenarioStartCaptor.capture());

verify(client).finishTestItem(same(featureId), any(FinishTestItemRQ.class));
ArgumentCaptor<FinishTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
verify(client).finishTestItem(same(scenarioIds.get(0)), scenarioCaptor.capture());
verify(client).finishTestItem(same(scenarioIds.get(1)), scenarioCaptor.capture());

assertThat(scenarioStartCaptor.getAllValues().get(0).isRetry(), anyOf(equalTo(false), nullValue()));
assertThat(scenarioStartCaptor.getAllValues().get(1).isRetry(), equalTo(true));
assertThat(scenarioStartCaptor.getAllValues().get(1).getRetryOf(), equalTo(scenarioIds.get(0)));
}
}

0 comments on commit 6eed5b1

Please sign in to comment.