Skip to content

Commit

Permalink
add multiple example tables support for cucumber-jvm (fixes allure-fr…
Browse files Browse the repository at this point in the history
  • Loading branch information
ervuks authored and baev committed Apr 3, 2019
1 parent b445557 commit e0f45e7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,6 @@
import gherkin.ast.Feature;
import gherkin.ast.ScenarioDefinition;
import gherkin.ast.ScenarioOutline;
import gherkin.ast.TableRow;
import gherkin.pickles.PickleCell;
import gherkin.pickles.PickleRow;
import gherkin.pickles.PickleTable;
Expand All @@ -50,6 49,7 @@

import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
Expand All @@ -60,7 60,6 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.getStatus;
import static io.qameta.allure.util.ResultsUtils.getStatusDetails;
import static io.qameta.allure.util.ResultsUtils.md5;
Expand Down Expand Up @@ -266,15 265,21 @@ private Status translateTestCaseStatus(final Result testCaseResult) {
}

private List<Parameter> getExamplesAsParameters(final ScenarioOutline scenarioOutline) {
final Examples examples = scenarioOutline.getExamples().get(0);
final TableRow row = examples.getTableBody().stream()
.filter(example -> example.getLocation().getLine() == currentTestCase.getLine())
.findFirst().get();
return IntStream.range(0, examples.getTableHeader().getCells().size()).mapToObj(index -> {
final String name = examples.getTableHeader().getCells().get(index).getValue();
final String value = row.getCells().get(index).getValue();
return createParameter(name, value);
}).collect(Collectors.toList());
final List<Parameter> parameterList = new ArrayList<>();
final List<Examples> scenarioOutlineList = scenarioOutline.getExamples().stream()
.filter(examples -> examples.getLocation().getLine() 2 == currentTestCase.getLine())
.collect(Collectors.toList());

scenarioOutlineList.forEach(examples -> examples.getTableBody()
.forEach(tableRow -> {
IntStream.range(0, examples.getTableHeader().getCells().size())
.forEach(consumer -> {
final String name = examples.getTableHeader().getCells().get(consumer).getValue();
final String value = tableRow.getCells().get(consumer).getValue();
parameterList.add(new Parameter().setName(name).setValue(value));
});
}));
return parameterList;
}

private void createDataTableAttachment(final PickleTable pickleTable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 263,17 @@ void shouldAddParametersFromExamples() {

}

@AllureFeatures.Parameters
@Test
void shouldHandleMultipleExampleTables() {
final AllureResults results = runFeature("features/multipleExamples.feature");

final List<TestResult> testResults = results.getTestResults();

assertThat(testResults)
.hasSize(2);
}

@AllureFeatures.MarkerAnnotations
@Test
void shouldAddTags() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,15 @@
Feature: Test Scenarios with multiple examples

Scenario Outline: Scenario with Positive Examples
Given a is <a>
And b is <b>
When I add a to b
Then result is <result>

Examples:
| a | b | result |
| 1 | 3 | 4 |

Examples:
| a | b | result |
| 2 | 8 | 10 |

0 comments on commit e0f45e7

Please sign in to comment.