Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for scenario descriptions for CucumberJVM #404

Merged
merged 1 commit into from
Dec 1, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.getStatus;
Expand Down Expand Up @@ -140,10 +141,11 @@ private void handleTestCaseStarted(final TestCaseStarted event) {

final Deque<PickleTag> tags = new LinkedList<>(currentTestCase.get().getTags());

final LabelBuilder labelBuilder = new LabelBuilder(currentFeature.get(), currentTestCase.get(), tags);
final Feature feature = currentFeature.get();
final LabelBuilder labelBuilder = new LabelBuilder(feature, currentTestCase.get(), tags);

final String name = currentTestCase.get().getName();
final String featureName = currentFeature.get().getName();
final String featureName = feature.getName();

final TestResult result = new TestResult()
.setUuid(getTestCaseUuid(currentTestCase.get()))
Expand All @@ -161,8 +163,13 @@ private void handleTestCaseStarted(final TestCaseStarted event) {
);
}

if (currentFeature.get().getDescription() != null && !currentFeature.get().getDescription().isEmpty()) {
result.setDescription(currentFeature.get().getDescription());
final String description = Stream.of(feature.getDescription(), scenarioDefinition.getDescription())
.filter(Objects::nonNull)
.filter(s -> !s.isEmpty())
.collect(Collectors.joining("\n"));

if (!description.isEmpty()) {
result.setDescription(description);
}

final TestResultContainer resultContainer = new TestResultContainer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ void shouldSetDescription() {
);
}

@AllureFeatures.Descriptions
@Test
void shouldSetScenarioDescription() {
final AllureResultsWriterStub writer = new AllureResultsWriterStub();
runFeature(writer, "features/scenario_description.feature");

final String expected = "This is description for current feature.\n"
+ "It should appear on each scenario in report";

final List<TestResult> testResults = writer.getTestResults();
assertThat(testResults)
.extracting(TestResult::getDescription)
.containsExactlyInAnyOrder(
expected + "\n scenario description 1",
expected + "\n scenario description 2"
);
}

@AllureFeatures.Attachments
@Test
void shouldAddDataTableAttachment() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Descriptions feature

This is description for current feature.
It should appear on each scenario in report

Scenario: Add a to b (1)
scenario description 1
Given a is 5
And b is 10
When I add a to b
Then result is 15

Scenario: Add a to b (2)
scenario description 2
Given a is 1
And b is 2
When I add a to b
Then result is 3