Skip to content

Commit

Permalink
Update dependency cucumber.version to v7.2.2 (#86)
Browse files Browse the repository at this point in the history
* Update cucumber.version to v7.3.0
* Updated scripts to support cucumber 7.3
* Updated CHANGELOG.md
  • Loading branch information
RameshBabuPrudhvi authored Apr 20, 2022
1 parent 6c99fed commit 42ee87b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 56 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* [Excel Runner] Support excel driven test runner ([#84](https://github.com/selcukes/selcukes-java/pull/84))

### Changed
* Update dependency org.projectlombok:lombok to v1.18.24
* Update dependency org.projectlombok:lombok to v1.18.24 ([#85](https://github.com/selcukes/selcukes-java/pull/85))
* Update dependency cucumber.version to v7.2.2 ([#86](https://github.com/selcukes/selcukes-java/pull/86))

### Removed
* [Webdriver Binaries] Removed Selenium server binary support. Alternatively use selenium grid maven dependency to run grid programmatically
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<poi.version>5.2.2</poi.version>
<slfj4.version>2.17.2</slfj4.version>

<cucumber.version>7.2.3</cucumber.version>
<cucumber.version>7.3.0</cucumber.version>
<selenium.version>4.1.3</selenium.version>
<appium.version>8.0.0</appium.version>
<testng.version>7.5</testng.version>
Expand Down
1 change: 1 addition & 0 deletions selcukes-extent-reports/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<sonar.exclusions>**/TestSourcesModel.java</sonar.exclusions>
</properties>
<dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private synchronized void createScenarioOutline(Scenario scenarioOutline) {

private void createExamples(Examples examples) {
List<TableRow> rows = new ArrayList<>();
rows.add(examples.getTableHeader());
examples.getTableHeader().ifPresent(rows::add);
rows.addAll(examples.getTableBody());
String[][] data = getTable(rows);
String markup = MarkupHelper.createTable(data).getMarkup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@

package io.github.selcukes.extent.report;

import io.cucumber.gherkin.Gherkin;
import io.cucumber.gherkin.GherkinParser;
import io.cucumber.messages.types.*;
import io.cucumber.plugin.event.TestSourceRead;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;

import static io.cucumber.gherkin.Gherkin.makeSourceEnvelope;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

public final class TestSourcesModel {

Expand Down Expand Up @@ -91,22 +90,6 @@ static URI relativize(URI uri) {
}
}

static Optional<Background> getBackgroundForTestCase(AstNode astNode) {
Feature feature = getFeatureForTestCase(astNode);
return feature.getChildren()
.stream()
.map(FeatureChild::getBackground)
.filter(Objects::nonNull)
.findFirst();
}

private static Feature getFeatureForTestCase(AstNode astNode) {
while (astNode.parent != null) {
astNode = astNode.parent;
}
return (Feature) astNode.node;
}

public void addTestSourceReadEvent(URI path, TestSourceRead event) {
pathToReadEventMap.put(path, event);
}
Expand All @@ -116,7 +99,7 @@ Feature getFeature(URI path) {
parseGherkinSource(path);
}
if (pathToAstMap.containsKey(path)) {
return pathToAstMap.get(path).getFeature();
return pathToAstMap.get(path).getFeature().orElse(null);
}
return null;
}
Expand All @@ -127,44 +110,40 @@ private void parseGherkinSource(URI path) {
}
String source = pathToReadEventMap.get(path).getSource();

List<Envelope> sources = singletonList(
makeSourceEnvelope(source, path.toString()));
GherkinParser parser = GherkinParser.builder()
.build();

List<Envelope> envelopes = Gherkin.fromSources(
sources,
true,
true,
true,
() -> String.valueOf(UUID.randomUUID())).collect(toList());
Stream<Envelope> envelopes = parser.parse(
Envelope.of(new Source(path.toString(), source, SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN)));

GherkinDocument gherkinDocument = envelopes.stream()
// TODO: What about empty gherkin docs?
GherkinDocument gherkinDocument = envelopes
.map(Envelope::getGherkinDocument)
.filter(Objects::nonNull)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElse(null);

pathToAstMap.put(path, gherkinDocument);
Map<Long, AstNode> nodeMap = new HashMap<>();
AstNode currentParent = new AstNode(Objects.requireNonNull(gherkinDocument).getFeature(), null);
for (FeatureChild child : gherkinDocument.getFeature().getChildren()) {
// TODO: What about gherkin docs with no features?
Feature feature = gherkinDocument.getFeature().get();
AstNode currentParent = new AstNode(feature, null);
for (FeatureChild child : feature.getChildren()) {
processFeatureDefinition(nodeMap, child, currentParent);
}
pathToNodeMap.put(path, nodeMap);

}

private void processFeatureDefinition(Map<Long, AstNode> nodeMap, FeatureChild child, AstNode currentParent) {
if (child.getBackground() != null) {
processBackgroundDefinition(nodeMap, child.getBackground(), currentParent);
} else if (child.getScenario() != null) {
processScenarioDefinition(nodeMap, child.getScenario(), currentParent);
} else if (child.getRule() != null) {
AstNode childNode = new AstNode(child.getRule(), currentParent);
nodeMap.put(child.getRule().getLocation().getLine(), childNode);
for (RuleChild ruleChild : child.getRule().getChildren()) {
processRuleDefinition(nodeMap, ruleChild, childNode);
}
}
child.getBackground().ifPresent(background -> processBackgroundDefinition(nodeMap, background, currentParent));
child.getScenario().ifPresent(scenario -> processScenarioDefinition(nodeMap, scenario, currentParent));
child.getRule().ifPresent(rule -> {
AstNode childNode = new AstNode(rule, currentParent);
nodeMap.put(rule.getLocation().getLine(), childNode);
rule.getChildren().forEach(ruleChild -> processRuleDefinition(nodeMap, ruleChild, childNode));
});
}

private void processBackgroundDefinition(
Expand All @@ -189,19 +168,17 @@ private void processScenarioDefinition(Map<Long, AstNode> nodeMap, Scenario chil
}

private void processRuleDefinition(Map<Long, AstNode> nodeMap, RuleChild child, AstNode currentParent) {
if (child.getBackground() != null) {
processBackgroundDefinition(nodeMap, child.getBackground(), currentParent);
} else if (child.getScenario() != null) {
processScenarioDefinition(nodeMap, child.getScenario(), currentParent);
}
child.getBackground().ifPresent(background -> processBackgroundDefinition(nodeMap, background, currentParent));
child.getScenario().ifPresent(scenario -> processScenarioDefinition(nodeMap, scenario, currentParent));
}

private void processScenarioOutlineExamples(
Map<Long, AstNode> nodeMap, Scenario scenarioOutline, AstNode parent
) {
for (Examples examples : scenarioOutline.getExamples()) {
AstNode examplesNode = new AstNode(examples, parent);
TableRow headerRow = examples.getTableHeader();
// TODO: Can tables without headers even exist?
TableRow headerRow = examples.getTableHeader().get();
AstNode headerNode = new AstNode(headerRow, examplesNode);
nodeMap.put(headerRow.getLocation().getLine(), headerNode);
for (int i = 0; i < examples.getTableBody().size(); ++i) {
Expand Down Expand Up @@ -234,6 +211,23 @@ boolean hasBackground(URI path, int line) {
return false;
}

static Optional<Background> getBackgroundForTestCase(AstNode astNode) {
Feature feature = getFeatureForTestCase(astNode);
return feature.getChildren()
.stream()
.map(FeatureChild::getBackground)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
}

private static Feature getFeatureForTestCase(AstNode astNode) {
while (astNode.parent != null) {
astNode = astNode.parent;
}
return (Feature) astNode.node;
}

static class ExamplesRowWrapperNode {

final int bodyRowIndex;
Expand Down
2 changes: 1 addition & 1 deletion selcukes-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<artifactId>selcukes-junit</artifactId>
<properties>
<junit.jupiter.version>5.8.2</junit.jupiter.version>
<cucumber.version>7.2.3</cucumber.version>
<cucumber.version>7.3.0</cucumber.version>
<junit-platform-suite.version>1.8.2</junit-platform-suite.version>
</properties>
<dependencies>
Expand Down

0 comments on commit 42ee87b

Please sign in to comment.