How to use TagParser class of net.serenitybdd.cucumber.util package

Best Serenity Cucumber code snippet using net.serenitybdd.cucumber.util.TagParser

Source:CucumberWithSerenity.java Github

copy

Full Screen

...3import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;4import net.serenitybdd.cucumber.suiteslicing.TestStatistics;5import net.serenitybdd.cucumber.suiteslicing.WeightedCucumberScenarios;6import net.serenitybdd.cucumber.util.FeatureRunnerExtractors;7import net.serenitybdd.cucumber.util.TagParser;8import net.thucydides.core.guice.Injectors;9import net.thucydides.core.util.EnvironmentVariables;10import net.thucydides.core.webdriver.Configuration;11import org.junit.runner.manipulation.NoTestsRemainException;12import org.junit.runners.model.InitializationError;13import org.slf4j.Logger;14import org.slf4j.LoggerFactory;15import java.io.IOException;16import java.nio.file.Paths;17import java.util.List;18import java.util.Optional;19import java.util.concurrent.atomic.AtomicInteger;20import java.util.function.Function;21import java.util.function.Predicate;22import cucumber.api.junit.Cucumber;23import cucumber.runtime.ClassFinder;24import cucumber.runtime.Runtime;25import cucumber.runtime.RuntimeOptions;26import cucumber.runtime.formatter.SerenityReporter;27import cucumber.runtime.io.ResourceLoader;28import cucumber.runtime.io.ResourceLoaderClassFinder;29import cucumber.runtime.junit.FeatureRunner;30import static java.util.stream.Collectors.toList;31import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_BATCH_COUNT;32import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_BATCH_NUMBER;33import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_FORK_COUNT;34import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_FORK_NUMBER;35/**36 * Glue code for running Cucumber via Serenity.37 * Sets up Serenity reporting and instrumentation.38 */39public class CucumberWithSerenity extends Cucumber {40 private static final Logger LOGGER = LoggerFactory.getLogger(CucumberWithSerenity.class);41 private static ThreadLocal<RuntimeOptions> RUNTIME_OPTIONS = new ThreadLocal<>();42 public static void setRuntimeOptions(RuntimeOptions runtimeOptions) {43 RUNTIME_OPTIONS.set(runtimeOptions);44 }45 public CucumberWithSerenity(Class clazz) throws InitializationError, IOException {46 super(clazz);47 }48 public static RuntimeOptions currentRuntimeOptions() {49 return RUNTIME_OPTIONS.get();50 }51 /**52 * Create the Runtime. Sets the Serenity runtime.53 */54 @Override55 protected Runtime createRuntime(ResourceLoader resourceLoader,56 ClassLoader classLoader,57 RuntimeOptions runtimeOptions) {58 EnvironmentVariables environmentVariables = Injectors.getInjector().getInstance(EnvironmentVariables.class);59 runtimeOptions.getTagFilters().addAll(TagParser.additionalTagsSuppliedFrom(environmentVariables, runtimeOptions.getTagFilters()));60 setRuntimeOptions(runtimeOptions);61 return CucumberWithSerenityRuntime.using(resourceLoader, classLoader, runtimeOptions);62 }63 public static Runtime createSerenityEnabledRuntime(ResourceLoader resourceLoader,64 ClassLoader classLoader,65 RuntimeOptions runtimeOptions,66 Configuration systemConfiguration) {67 ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);68 setRuntimeOptions(runtimeOptions);69 Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);70 //the order here is important, add plugin after the runtime is created71 SerenityReporter reporter = new SerenityReporter(systemConfiguration, resourceLoader);72 runtimeOptions.addPlugin(reporter);73 return runtime;...

Full Screen

Full Screen

Source:TagParserFromTagFiltersTest.java Github

copy

Full Screen

1package net.serenitybdd.cucumber.util;2import net.serenitybdd.cucumber.util.TagParser;3import org.junit.Test;4import java.util.List;5import io.cucumber.tagexpressions.Expression;6import static java.util.Arrays.asList;7import static java.util.stream.Collectors.joining;8import static org.hamcrest.core.Is.is;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}...

Full Screen

Full Screen

Source:TagParser.java Github

copy

Full Screen

...8import io.cucumber.tagexpressions.Expression;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(":", "=");28 if (tag.startsWith("~@") || tag.startsWith("@")) {29 return tag;30 }31 if (tag.startsWith("~")) {32 return "~@" + tag.substring(1);33 }34 return "@" + tag;35 }36}...

Full Screen

Full Screen

Source:TagParserFromEnvironmentVariablesTest.java Github

copy

Full Screen

...5import static java.util.Arrays.asList;6import static org.hamcrest.Matchers.containsInAnyOrder;7import static org.hamcrest.Matchers.hasSize;8import static org.junit.Assert.assertThat;9public class TagParserFromEnvironmentVariablesTest {10 @Test11 public void commandLineTagsNotInRunTimeTags() {12 EnvironmentVariables environmentVariables = new MockEnvironmentVariables();13 environmentVariables.setProperty("tags", "@my_tag_from_command_line, @my_health_coc,@another_tag_from_command_line");14 assertThat(TagParser.additionalTagsSuppliedFrom(environmentVariables, asList("@smoke", "@my_health_coc", "@ManageFeatureToggles")),15 containsInAnyOrder("@my_tag_from_command_line", "@another_tag_from_command_line"));16 }17 @Test18 public void commandLineTagsAllInRunTimeTags() {19 EnvironmentVariables environmentVariables = new MockEnvironmentVariables();20 environmentVariables.setProperty("tags", "@my_health_coc");21 assertThat(TagParser.additionalTagsSuppliedFrom(environmentVariables, asList("@smoke", "@my_health_coc", "@ManageFeatureToggles")),22 hasSize(0));23 }24 @Test25 public void noCommandLineTagsProvided() {26 EnvironmentVariables environmentVariables = new MockEnvironmentVariables();27 assertThat(TagParser.additionalTagsSuppliedFrom(environmentVariables, asList("@smoke", "@my_health_coc", "@ManageFeatureToggles")),28 hasSize(0));29 }30}...

Full Screen

Full Screen

Source:CucumberSuiteSlicer.java Github

copy

Full Screen

1package net.serenitybdd.cucumber.suiteslicing;2import net.serenitybdd.cucumber.util.TagParser;3import java.net.URI;4import java.util.List;5import java.util.function.Predicate;6import static com.google.common.collect.Lists.newArrayList;7public class CucumberSuiteSlicer {8 private final List<URI> featurePaths;9 private final TestStatistics statistics;10 public CucumberSuiteSlicer(List<URI> featurePaths, TestStatistics statistics) {11 this.featurePaths = featurePaths;12 this.statistics = statistics;13 }14 public WeightedCucumberScenarios scenarios(int batchNumber, int batchCount, int forkNumber, int forkCount, List<String> tagFilters) {15 return new CucumberScenarioLoader(featurePaths, statistics).load()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}...

Full Screen

Full Screen

TagParser

Using AI Code Generation

copy

Full Screen

1package net.serenitybdd.cucumber.util;2import java.util.ArrayList;3import java.util.Arrays;4import java.util.List;5import java.util.regex.Matcher;6import java.util.regex.Pattern;7public class TagParser {8 private static final String TAG_EXPRESSION = "(@[^@\\s]+)";9 private static final Pattern TAG_PATTERN = Pattern.compile(TAG_EXPRESSION);10 public static List<String> parseTags(String tagExpression) {11 List<String> tags = new ArrayList<>();12 Matcher matcher = TAG_PATTERN.matcher(tagExpression);13 while (matcher.find()) {14 tags.add(matcher.group(1));15 }16 return tags;17 }18 public static boolean isTagExpression(String tagExpression) {19 return Arrays.stream(tagExpression.split("\\s+")).anyMatch(tag -> tag.startsWith("@"));20 }21}22package net.serenitybdd.cucumber.util;23import java.util.ArrayList;24import java.util.List;25import org.junit.Test;26import static org.assertj.core.api.Assertions.assertThat;27public class TagParserTest {28 public void shouldParseTags() {29 String tagExpression = "@tag1 @tag2 @tag3";30 List<String> expectedTags = new ArrayList<>();31 expectedTags.add("@tag1");32 expectedTags.add("@tag2");33 expectedTags.add("@tag3");34 assertThat(TagParser.parseTags(tagExpression)).isEqualTo(expectedTags);35 }36 public void shouldReturnEmptyList() {37 String tagExpression = "tag1 tag2 tag3";38 List<String> expectedTags = new ArrayList<>();39 assertThat(TagParser.parseTags(tagExpression)).isEqualTo(expectedTags);40 }41 public void shouldReturnTrue() {42 String tagExpression = "@tag1 tag2 tag3";43 assertThat(TagParser.isTagExpression(tagExpression)).isTrue();44 }45 public void shouldReturnFalse() {46 String tagExpression = "tag1 tag2 tag3";47 assertThat(TagParser.isTagExpression(tagExpression)).isFalse();48 }49}

Full Screen

Full Screen

TagParser

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.util.TagParser;2import net.thucydides.core.requirements.model.Tags;3import cucumber.api.Scenario;4import cucumber.api.java.After;5import cucumber.api.java.Before;6public class Hooks {7 public void beforeScenario(Scenario scenario) {8 Tags tags = TagParser.parseTagsFrom(scenario.getSourceTagNames());9 String featureName = scenario.getId().split(";")[0];10 String scenarioName = scenario.getName();11 String featureFileName = scenario.getId().split(";")[0].split(":")[1];12 String lineNumber = scenario.getId().split(";")[1].split(":")[1];13 }14 public void afterScenario(Scenario scenario) {15 String status = scenario.getStatus();16 long duration = scenario.getDuration();17 Tags tags = TagParser.parseTagsFrom(scenario.getSourceTagNames());18 String featureName = scenario.getId().split(";")[0];19 String scenarioName = scenario.getName();20 String featureFileName = scenario.getId().split(";")[0].split(":")[1];21 String lineNumber = scenario.getId().split(";")[1].split(":")[1];22 }23}24Tags tags = TagParser.parseTagsFrom(scenario.getSourceTagNames());25String featureName = scenario.getId().split(";")[0];26String scenarioName = scenario.getName();

Full Screen

Full Screen

TagParser

Using AI Code Generation

copy

Full Screen

1package net.serenitybdd.cucumber.util;2import java.util.regex.Matcher;3import java.util.regex.Pattern;4public class TagParser {5 private static final Pattern TAG_PATTERN = Pattern.compile("\\s*(@[^\\s]*)");6 public static String[] parseTags(String tagExpression) {7 Matcher matcher = TAG_PATTERN.matcher(tagExpression);8 List<String> tags = new ArrayList<String>();9 while (matcher.find()) {10 tags.add(matcher.group(1));11 }12 return tags.toArray(new String[tags.size()]);13 }14}15package net.serenitybdd.cucumber.util;16import cucumber.api.java.en.Then;17import cucumber.api.java.en.When;18public class TagParserTest {19 @When("^I do something$")20 public void i_do_something() throws Throwable {21 throw new PendingException();22 }23 @Then("^I should see something$")24 public void i_should_see_something() throws Throwable {25 throw new PendingException();26 }27 @Then("^I should see something else$")28 public void i_should_see_something_else() throws Throwable {29 throw new PendingException();30 }31}32package net.serenitybdd.cucumber.util;33import cucumber.api.CucumberOptions;34import cucumber.api.junit.Cucumber;35import org.junit.runner.RunWith;36@RunWith(Cucumber.class)37@CucumberOptions(38public class TagParserTestRunner {39}40package net.serenitybdd.cucumber.util;41import cucumber.api.CucumberOptions;42import cucumber.api.junit.Cucumber;43import org.junit.runner.RunWith;44@RunWith(Cucumber.class)45@CucumberOptions(46public class TagParserTestRunner {47}48package net.serenitybdd.cucumber.util;49import cucumber.api.CucumberOptions;50import cucumber.api.junit.Cucumber;51import org.junit.runner.RunWith;

Full Screen

Full Screen

TagParser

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.util.TagParser;2import java.util.List;3public class TagParserTest {4 public static void main(String[] args) {5 List<String> tagList = TagParser.parseTags("@tag1,@tag2,@tag3");6 System.out.println(tagList);7 }8}

Full Screen

Full Screen

TagParser

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.util.TagParser;2import java.util.List;3public class MyStepdefs {4 @Given("^I have a list of tags$")5 public void iHaveAListOfTags(List<String> tags) {6 TagParser tagParser = new TagParser(tags);7 tagParser.getTags().forEach(tag -> System.out.println(tag));8 }9}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Serenity Cucumber automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in TagParser

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful