Skip to content

Commit 43d4d87

Browse files
authored
Merge pull request serenity-bdd#2016 from cliviu/master
support for cucumber.filter.tags
2 parents 65f9228 + 3f4bb3d commit 43d4d87

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

serenity-model/src/main/java/net/thucydides/core/reports/html/CucumberCompatibleFilter.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,28 @@ protected Expression cucumberTagExpressionUsing(ThucydidesSystemProperty tagProp
3434
}
3535

3636
protected Optional<String> cucumberTagOptions() {
37+
String cucumberFilterTags = environmentVariables.getProperty("cucumber.filter.tags");
38+
if (StringUtils.isNotEmpty(cucumberFilterTags)) {
39+
return Optional.of(StringUtils.strip(cucumberFilterTags, "'"));
40+
}
3741
String cucumberOptions = environmentVariables.getProperty("cucumber.options");
3842
if (StringUtils.isNotEmpty(cucumberOptions) && (cucumberOptions.contains("--tags "))) {
39-
int tagsFlag = cucumberOptions.indexOf("--tags ");
40-
int tagsOptionStart = tagsFlag + 7;
41-
int nextTagOptionStart = cucumberOptions.indexOf("--", tagsOptionStart);
42-
String tagOption = (nextTagOptionStart > 0) ?
43-
cucumberOptions.substring(tagsOptionStart, nextTagOptionStart) : cucumberOptions.substring(tagsOptionStart);
44-
45-
String tagOptionsWithoutAtSigns = StringUtils.strip(tagOption, "'");
46-
return Optional.of(tagOptionsWithoutAtSigns);
43+
return getTagsFromCucumberOptions(cucumberOptions);
4744
}
4845
return Optional.empty();
4946
}
5047

48+
private Optional<String> getTagsFromCucumberOptions(String cucumberOptions) {
49+
int tagsFlag = cucumberOptions.indexOf("--tags ");
50+
int tagsOptionStart = tagsFlag + 7;
51+
int nextTagOptionStart = cucumberOptions.indexOf("--", tagsOptionStart);
52+
String tagOption = (nextTagOptionStart > 0) ?
53+
cucumberOptions.substring(tagsOptionStart, nextTagOptionStart) : cucumberOptions.substring(tagsOptionStart);
54+
55+
String tagOptionsWithoutAtSigns = StringUtils.strip(tagOption, "'");
56+
return Optional.of(tagOptionsWithoutAtSigns);
57+
}
58+
5159
public boolean matchesTags(List<TestTag> testTags) {
5260
Expression expectedTags = cucumberTagExpressionUsing(TAGS);
5361

serenity-model/src/main/java/net/thucydides/core/reports/html/RequirementsFilter.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package net.thucydides.core.reports.html;
22

33
import io.cucumber.tagexpressions.Expression;
4-
import io.cucumber.tagexpressions.TagExpressionParser;
5-
import net.thucydides.core.ThucydidesSystemProperty;
6-
import net.thucydides.core.model.TestTag;
74
import net.thucydides.core.requirements.model.Requirement;
85
import net.thucydides.core.util.EnvironmentVariables;
96

107
import java.util.List;
8+
import java.util.function.Predicate;
119
import java.util.stream.Collectors;
1210

1311
import static net.thucydides.core.ThucydidesSystemProperty.TAGS;
@@ -25,12 +23,9 @@ public boolean inDisplayOnlyTags(Requirement requirement) {
2523

2624

2725
private boolean requirementMatchesAnyTagIn(Requirement requirement, Expression expectedTags) {
28-
List<String> requirementTags = CucumberTagConverter.toStrings(requirement.getTags());
29-
30-
if (expectedTags.evaluate(requirementTags) || (matchExistsInScenarios(expectedTags, requirement))) {
26+
if (new RequirementTagMatcher(expectedTags).test(requirement)) {
3127
return true;
3228
}
33-
3429
return hasChildWithMatchingTag(requirement, expectedTags);
3530
}
3631

@@ -44,12 +39,25 @@ private boolean hasChildWithMatchingTag(Requirement requirement, Expression expe
4439
if (!requirement.hasChildren()) {
4540
return false;
4641
}
47-
return requirement.getNestedChildren().stream().anyMatch(
48-
child -> expectedTags.evaluate(CucumberTagConverter.toStrings(child.getTags()))
49-
);
42+
return requirement.getNestedChildren().stream().anyMatch(new RequirementTagMatcher(expectedTags));
43+
}
44+
45+
private class RequirementTagMatcher implements Predicate<Requirement> {
46+
47+
private Expression expectedTags;
48+
49+
public RequirementTagMatcher(Expression expectedTags) {
50+
this.expectedTags = expectedTags;
51+
}
52+
53+
@Override
54+
public boolean test(Requirement requirement) {
55+
return expectedTags.evaluate(CucumberTagConverter.toStrings(requirement.getTags())) || matchExistsInScenarios(expectedTags, requirement);
56+
}
5057
}
5158

5259

60+
5361
public List<Requirement> filteredByDisplayTag(List<Requirement> requirements) {
5462
return requirements.stream()
5563
.filter(this::inDisplayOnlyTags)

0 commit comments

Comments
 (0)