Best Serenity Cucumber code snippet using net.serenitybdd.cucumber.util.TagParser.parseFromTagFilters
Source:TagParserFromTagFiltersTest.java
...9import static org.junit.Assert.assertThat;10public class TagParserFromTagFiltersTest {11 @Test12 public void startSimpleWithASingleExlude() {13 Expression expression = TagParser.parseFromTagFilters(asList("not @wip"));14 assertThat(expression.evaluate(asList("@wip")), is(false));15 assertThat(expression.evaluate(asList("@wip", "@smoke")), is(false));16 }17 @Test18 public void shouldSupportOldSyntaxInCasePeopleStillUseThat() {19 Expression expression = TagParser.parseFromTagFilters(asList("~@wip"));20 assertThat(expression.evaluate(asList("@wip")), is(false));21 assertThat(expression.evaluate(asList("@wip", "@smoke")), is(false));22 assertThat(expression.evaluate(asList("@smoke")), is(true));23 }24 @Test25 public void shouldSupportAMixedList() {26 List<String> stringList = asList("not @wip", "@AGENT_WEB_ACC_TESTS", "@smoke", "not @dont_run_me");27 Expression expression = TagParser.parseFromTagFilters(stringList);28 assertThat(expression.evaluate(asList("@wip")), is(false));29 assertThat(expression.evaluate(asList("@wip", "@smoke")), is(false));30 assertThat(expression.evaluate(asList("@dont_run_me")), is(false));31 assertThat(expression.evaluate(asList("@dont_run_me", "@AGENT_WEB_ACC_TESTS")), is(false));32 assertThat(expression.evaluate(asList("@AGENT_WEB_ACC_TESTS", "@smoke")), is(true));33 }34 @Test35 public void whenProcessingAnEmptyArgumentEverythingIsRun() {36 Expression expression = TagParser.parseFromTagFilters(asList());37 assertThat(expression.evaluate(asList("@wip")), is(true));38 assertThat(expression.evaluate(asList("@wip", "@smoke")), is(true));39 assertThat(expression.evaluate(asList("@dont_run_me")), is(true));40 assertThat(expression.evaluate(asList("@dont_run_me", "@AGENT_WEB_ACC_TESTS")), is(true));41 assertThat(expression.evaluate(asList("@AGENT_WEB_ACC_TESTS")), is(true));42 }43 @Test44 public void eachItemInListWillBeJoinedWithAnd() {45 Expression expression = TagParser.parseFromTagFilters(asList("@this", "@AGENT_WEB_ACC_TESTS", "@smoke", "@do_run_me"));46 assertThat(expression.evaluate(asList("@wip")), is(false));47 assertThat(expression.evaluate(asList("@this", "@AGENT_WEB_ACC_TESTS", "@smoke", "@do_run_me")), is(true));48 assertThat(expression.evaluate(asList("@do_run_me", "@this", "@AGENT_WEB_ACC_TESTS", "@smoke")), is(true));49 assertThat(expression.evaluate(asList("@dont_run_me")), is(false));50 assertThat(expression.evaluate(asList("@AGENT_WEB_ACC_TESTS")), is(false));51 }52 @Test53 public void shouldSupportTagsJoinedByOrInASingleArgument() {54 Expression expression = TagParser.parseFromTagFilters(asList("@smoke or @my_health_coc or @ManageFeatureToggles"));55 assertThat(expression.evaluate(asList("@smoke")), is(true));56 assertThat(expression.evaluate(asList("@smoke", "@my_health_coc", "@ManageFeatureToggles")), is(true));57 assertThat(expression.evaluate(asList("@snot")), is(false));58 assertThat(expression.evaluate(asList("@smoke", "@snot", "@ManageFeatureToggles")), is(true));59 }60 @Test61 public void shouldSupportTagsJoinedByOrInAMultipleArgumentsAndJoinThemWithAnd() {62 Expression expression = TagParser.parseFromTagFilters(asList("@tag1 or @tag2 or @tag3", "@taga or @tagb or @tagc"));63 assertThat(expression.evaluate(asList("@tag1")), is(false));64 assertThat(expression.evaluate(asList("@tag2", "@tagb")), is(true));65 assertThat(expression.evaluate(asList("@tag1", "@tagb", "@tag2", "@taga")), is(true));66 }67}...
Source:TagParser.java
...9import io.cucumber.tagexpressions.TagExpressionParser;10import static java.util.stream.Collectors.joining;11import static java.util.stream.Collectors.toList;12public class TagParser {13 public static Expression parseFromTagFilters(List<String> stringList) {14 String combinedExpression = stringList.isEmpty() ? "" : stringList.stream()15 .filter(StringUtils::isNotEmpty)16 .map(tagExpression -> tagExpression.replace("~", "not "))17 .collect(joining(") and (", "(", ")"));18 return new TagExpressionParser().parse(combinedExpression);19 }20 public static Collection<String> additionalTagsSuppliedFrom(EnvironmentVariables environmentVariables, List<String> existingTags) {21 String tagsExpression = ThucydidesSystemProperty.TAGS.from(environmentVariables, "");22 return Stream.of(StringUtils.split(tagsExpression, ","))23 .map(TagParser::toCucumberTag)24 .filter(tag -> !existingTags.contains(tag)).collect(toList());25 }26 private static String toCucumberTag(String from) {27 String tag = from.trim().replaceAll(":", "=");...
Source:CucumberSuiteSlicer.java
...16 .filter(forSuppliedTags(tagFilters))17 .slice(batchNumber).of(batchCount).slice(forkNumber).of(forkCount);18 }19 private Predicate<WeightedCucumberScenario> forSuppliedTags(List<String> tagFilters) {20 return cucumberScenario -> TagParser.parseFromTagFilters(tagFilters).evaluate(newArrayList(cucumberScenario.tags));21 }22}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!