Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Fixed
- Step name generation for some cases, by @HardNorth

## [5.5.0]
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class ReportPortalUtils {
private static final String PARAMETER_ITEMS_DELIMITER = ";";
private static final String KEY_VALUE_SEPARATOR = ":";
private static final Pattern CONSOLE_COLORS_PATTERN = Pattern.compile("\\u001B\\[[0-?]*[ -/]*[@-~]");
private static final String STEP_NAME_PART_SEPARATOR = " ";

private static final List<String> CODE_REF_PREFIXES_TO_REMOVE = List.of(
"build/resources/test/",
Expand Down Expand Up @@ -453,6 +454,25 @@ public static StartTestItemRQ buildStartBackgroundRq(Instant startTime, @Nonnull
return rq;
}

private static String getStepName(@Nonnull Step step) {
StringBuilder builder = new StringBuilder();
String prefix = step.getPrefix();
if (prefix != null && !prefix.isBlank()) {
builder.append(prefix);
}
String keyword = step.getKeyword();
if (keyword != null && !keyword.isBlank()) {
builder.append(STEP_NAME_PART_SEPARATOR);
builder.append(keyword);
}
String text = step.getText();
if (text != null && !text.isBlank()) {
builder.append(STEP_NAME_PART_SEPARATOR);
builder.append(text);
}
return builder.toString();
}

/**
* Customize start step test item event/request
*
Expand All @@ -462,7 +482,7 @@ public static StartTestItemRQ buildStartBackgroundRq(Instant startTime, @Nonnull
*/
@Nonnull
public static StartTestItemRQ buildStartStepRq(@Nonnull Step step, @Nonnull Scenario scenario) {
String stepName = step.getPrefix() + " " + step.getText();
String stepName = getStepName(step);
StartTestItemRQ rq = buildStartTestItemRq(stepName, Instant.now(), ItemType.STEP);
rq.setHasStats(false);
if (step.isOutline()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ public void test_background_steps(boolean report) {
Set<String> nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet());

assertThat(nestedStepNames, hasSize(1));
assertThat(nestedStepNames, hasItem("Given varb = 2"));
assertThat(nestedStepNames, hasItem("Given def varb = 2"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void test_background_steps(boolean report) {
List<StartTestItemRQ> nestedSteps = nestedStepCaptor.getAllValues();
assertThat(nestedSteps, hasSize(1));
StartTestItemRQ nestedStep = nestedSteps.getFirst();
assertThat(nestedStep.getName(), equalTo("Given four = 4"));
assertThat(nestedStep.getName(), equalTo("Given def four = 4"));
assertThat(nestedStep.isHasStats(), equalTo(Boolean.FALSE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ public void test_background_steps(boolean report) {
nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE)));
Set<String> nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet());

assertThat(nestedStepNames, allOf(hasItem("Given vara = 2"), hasItem("And varb = 2")));
assertThat(nestedStepNames, allOf(hasItem("Given def vara = 2"), hasItem("And def varb = 2")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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 com.epam.ta.reportportal.ws.model.log.SaveLogRQ;
import io.karatelabs.core.SuiteResult;
import okhttp3.MultipartBody;
Expand All @@ -35,6 +36,7 @@
import static com.epam.reportportal.karate.utils.TestUtils.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.contains;
import static org.mockito.Mockito.*;

public class HttpRequestLoggingTest {
Expand All @@ -49,6 +51,9 @@ public class HttpRequestLoggingTest {
grant_type: 'password'
}
```""";
public static final String[] STEP_NAMES = { "Given url 'https://example.com'", "And header Content-Type = 'application/json'",
"And path 'api/test'", "And request", "When method post", "Then status 404" };

private final String launchUuid = CommonUtils.namedId("launch_");
private final String featureId = CommonUtils.namedId("feature_");
private final String scenarioId = CommonUtils.namedId("scenario_");
Expand All @@ -74,7 +79,18 @@ private List<String> extractMessages() {
.collect(Collectors.toList());

assertThat(logs, hasSize(greaterThanOrEqualTo(2)));
return logs.stream().map(SaveLogRQ::getMessage).collect(Collectors.toList());
return logs.stream().map(SaveLogRQ::getMessage).toList();
}

@SuppressWarnings({ "unchecked", "rawtypes" })
private List<String> extractStepNames() {
ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client, times(6)).startTestItem(same(scenarioId), stepCaptor.capture());
List<StartTestItemRQ> steps = stepCaptor.getAllValues();
return steps.stream()
.sorted((a, b) -> ((Comparable) a.getStartTime()).compareTo(b.getStartTime()))
.map(StartTestItemRQ::getName)
.toList();
}

@Test
Expand All @@ -84,6 +100,9 @@ public void test_http_request_logging_result_listener() {
List<String> messages = extractMessages();
assertThat(messages, hasItem(equalTo(DOCSTRING_LOG_ENTRY)));
assertThat(messages, hasItem(containsString("{\"username\":\"user\",\"password\":\"password\",\"grant_type\":\"password\"}")));

List<String> stepNames = extractStepNames();
assertThat(stepNames, contains(STEP_NAMES));
}

@Test
Expand All @@ -95,5 +114,8 @@ public void test_http_request_logging_run_listener() {
assertThat(messages, hasItem(containsString("**>>> REQUEST**")));
assertThat(messages, hasItem(containsString("**<<< RESPONSE**")));
assertThat(messages, hasItem(containsString("\"username\" : \"user\"")));

List<String> stepNames = extractStepNames();
assertThat(stepNames, contains(STEP_NAMES));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class SimpleItemNameTest {
private static final String TEST_FEATURE = "classpath:feature/simple.feature";
private static final String[] STEP_NAMES = new String[] { "Given four = 4", "When actualFour = 2 * 2", "Then actualFour == four" };
private static final String[] STEP_NAMES = new String[] { "Given def four = 4", "When def actualFour = 2 * 2", "Then assert actualFour == four" };
private final String featureId = CommonUtils.namedId("feature_");
private final String scenarioId = CommonUtils.namedId("scenario_");
private final List<String> stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public void test_each_item_has_correct_start_date(boolean report, boolean useMic
);

List<StartTestItemRQ> steps = stepCaptor.getAllValues();
StartTestItemRQ firstStep = steps.stream().filter(s -> "Given four = 4".equals(s.getName())).findAny().orElseThrow();
StartTestItemRQ secondStep = steps.stream().filter(s -> "When actualFour = 2 * 2".equals(s.getName())).findAny().orElseThrow();
StartTestItemRQ firstStep = steps.stream().filter(s -> "Given def four = 4".equals(s.getName())).findAny().orElseThrow();
StartTestItemRQ secondStep = steps.stream().filter(s -> "When def actualFour = 2 * 2".equals(s.getName())).findAny().orElseThrow();
StartTestItemRQ thirdStep = steps.stream()
.filter(s -> "Then actualFour == four".equals(s.getName()))
.filter(s -> "Then assert actualFour == four".equals(s.getName()))
.findAny()
.orElseThrow();

Expand Down
Loading