How to use ScenarioFilter class of net.serenitybdd.cucumber.suiteslicing package

Best Serenity Cucumber code snippet using net.serenitybdd.cucumber.suiteslicing.ScenarioFilter

Source:CucumberSerenityRunner.java Github

copy

Full Screen

...22import cucumber.runtime.model.CucumberFeature;23import cucumber.runtime.model.FeatureLoader;24import io.cucumber.core.options.RuntimeOptionsBuilder;25import net.serenitybdd.cucumber.suiteslicing.CucumberSuiteSlicer;26import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;27import net.serenitybdd.cucumber.suiteslicing.TestStatistics;28import net.serenitybdd.cucumber.suiteslicing.WeightedCucumberScenarios;29import net.serenitybdd.cucumber.util.PathUtils;30import net.serenitybdd.cucumber.util.Splitter;31import net.thucydides.core.ThucydidesSystemProperty;32import net.thucydides.core.guice.Injectors;33import net.thucydides.core.util.EnvironmentVariables;34import net.thucydides.core.webdriver.Configuration;35import org.junit.runner.Description;36import org.junit.runner.manipulation.NoTestsRemainException;37import org.junit.runner.notification.RunNotifier;38import org.junit.runners.ParentRunner;39import org.junit.runners.model.InitializationError;40import org.junit.runners.model.RunnerScheduler;41import org.junit.runners.model.Statement;42import org.slf4j.Logger;43import org.slf4j.LoggerFactory;44import java.net.URI;45import java.nio.file.Paths;46import java.util.ArrayList;47import java.util.Collection;48import java.util.List;49import java.util.Optional;50import java.util.concurrent.atomic.AtomicInteger;51import java.util.function.Function;52import java.util.function.Predicate;53import static java.util.stream.Collectors.toList;54import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_BATCH_COUNT;55import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_BATCH_NUMBER;56import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_FORK_COUNT;57import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_FORK_NUMBER;58/**59 * Glue code for running Cucumber via Serenity.60 * Sets up Serenity reporting and instrumentation.61 */62public class CucumberSerenityRunner extends ParentRunner<FeatureRunner> {63 private static final Logger LOGGER = LoggerFactory.getLogger(CucumberSerenityRunner.class);64 private final List<FeatureRunner> children = new ArrayList<FeatureRunner>();65 private final EventBus bus;66 private final ThreadLocalRunnerSupplier runnerSupplier;67 private static ThreadLocal<RuntimeOptions> RUNTIME_OPTIONS = new ThreadLocal<>();68 private final List<CucumberFeature> features;69 private final Plugins plugins;70 private boolean multiThreadingAssumed = false;71 /**72 * Constructor called by JUnit.73 *74 * @param clazz the class with the @RunWith annotation.75 * @throws InitializationError if there is another problem76 */77 public CucumberSerenityRunner(Class clazz) throws InitializationError {78 super(clazz);79 ClassLoader classLoader = clazz.getClassLoader();80 ResourceLoader resourceLoader = new MultiLoader(classLoader);81 Assertions.assertNoCucumberAnnotatedMethods(clazz);82 83 // Parse the options early to provide fast feedback about invalid options84 RuntimeOptions annotationOptions = new CucumberOptionsAnnotationParser(resourceLoader)85 .withOptionsProvider(new JUnitCucumberOptionsProvider())86 .parse(clazz)87 .build();88 RuntimeOptions runtimeOptions = new EnvironmentOptionsParser(resourceLoader)89 .parse(Env.INSTANCE)90 .build(annotationOptions);91 runtimeOptions.addUndefinedStepsPrinterIfSummaryNotDefined();92 JUnitOptions junitAnnotationOptions = new JUnitOptionsParser()93 .parse(clazz)94 .build();95 JUnitOptions junitOptions = new JUnitOptionsParser()96 .parse(runtimeOptions.getJunitOptions())97 .setStrict(runtimeOptions.isStrict())98 .build(junitAnnotationOptions);99 setRuntimeOptions(runtimeOptions);100 FeatureLoader featureLoader = new FeatureLoader(resourceLoader);101 FeaturePathFeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(featureLoader, runtimeOptions);102 // Parse the features early. Don't proceed when there are lexer errors103 this.features = featureSupplier.get();104 ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);105 this.plugins = new Plugins(classLoader, new PluginFactory(),runtimeOptions);106 this.bus = new TimeServiceEventBus(TimeService.SYSTEM);107 Configuration systemConfiguration = Injectors.getInjector().getInstance(Configuration.class);108 SerenityReporter reporter = new SerenityReporter(systemConfiguration, resourceLoader);109 addSerenityReporterPlugin(plugins,reporter);110 BackendSupplier backendSupplier = new BackendModuleBackendSupplier(resourceLoader, classFinder, runtimeOptions);111 this.runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, bus, backendSupplier);112 Filters filters = new Filters(runtimeOptions);113 for (CucumberFeature cucumberFeature : features) {114 FeatureRunner featureRunner = new FeatureRunner(cucumberFeature, filters, runnerSupplier, junitOptions);115 if (!featureRunner.isEmpty()) {116 children.add(featureRunner);117 }118 }119 }120 private static RuntimeOptions DEFAULT_RUNTIME_OPTIONS;121 public static void setRuntimeOptions(RuntimeOptions runtimeOptions) {122 RUNTIME_OPTIONS.set(runtimeOptions);123 DEFAULT_RUNTIME_OPTIONS = runtimeOptions;124 }125 public static RuntimeOptions currentRuntimeOptions() {126 return (RUNTIME_OPTIONS.get() != null) ? RUNTIME_OPTIONS.get() : DEFAULT_RUNTIME_OPTIONS;127 }128 private static Collection<String> environmentSpecifiedTags(List<?> existingTags) {129 EnvironmentVariables environmentVariables = Injectors.getInjector().getInstance(EnvironmentVariables.class);130 String tagsExpression = ThucydidesSystemProperty.TAGS.from(environmentVariables,"");131 List<String> existingTagsValues = existingTags.stream().map(Object::toString).collect(toList());132 return Splitter.on(",").trimResults().omitEmptyStrings().splitToList(tagsExpression).stream()133 .map(CucumberSerenityRunner::toCucumberTag).filter(t -> !existingTagsValues.contains(t)).collect(toList());134 }135 private static String toCucumberTag(String from) {136 String tag = from.replaceAll(":","=");137 if (tag.startsWith("~@") || tag.startsWith("@")) { return tag; }138 if (tag.startsWith("~")) { return "~@" + tag.substring(1); }139 return "@" + tag;140 }141 public static Runtime createSerenityEnabledRuntime(ResourceLoader resourceLoader,142 ClassLoader classLoader,143 RuntimeOptions runtimeOptions,144 Configuration systemConfiguration) {145 ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);146 setRuntimeOptions(runtimeOptions);147 FeatureLoader featureLoader = new FeatureLoader(resourceLoader);148 FeaturePathFeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(featureLoader, runtimeOptions);149 // Parse the features early. Don't proceed when there are lexer errors150 final List<CucumberFeature> features = featureSupplier.get();151 EventBus bus = new TimeServiceEventBus(TimeService.SYSTEM);152 153 SerenityReporter serenityReporter = new SerenityReporter(systemConfiguration, resourceLoader);154 Runtime runtime = Runtime.builder().withResourceLoader(resourceLoader).withClassFinder(classFinder).155 withClassLoader(classLoader).withRuntimeOptions(runtimeOptions).156 withAdditionalPlugins(serenityReporter).157 withEventBus(bus).withFeatureSupplier(featureSupplier).158 build();159 return runtime;160 }161 private static void addSerenityReporterPlugin(Plugins plugins, SerenityReporter plugin)162 {163 for(Plugin currentPlugin : plugins.getPlugins()){164 if (currentPlugin instanceof SerenityReporter) {165 return;166 }167 }168 plugins.addPlugin(plugin);169 }170 @Override171 protected Description describeChild(FeatureRunner child) {172 return child.getDescription();173 }174 @Override175 protected void runChild(FeatureRunner child, RunNotifier notifier) {176 child.run(notifier);177 }178 @Override179 protected Statement childrenInvoker(RunNotifier notifier) {180 Statement runFeatures = super.childrenInvoker(notifier);181 return new RunCucumber(runFeatures);182 }183 class RunCucumber extends Statement {184 private final Statement runFeatures;185 RunCucumber(Statement runFeatures) {186 this.runFeatures = runFeatures;187 }188 @Override189 public void evaluate() throws Throwable {190 if (multiThreadingAssumed) {191 plugins.setSerialEventBusOnEventListenerPlugins(bus);192 } else {193 plugins.setEventBusOnEventListenerPlugins(bus);194 }195 bus.send(new TestRunStarted(bus.getTime(), bus.getTimeMillis()));196 for (CucumberFeature feature : features) {197 feature.sendTestSourceRead(bus);198 }199 StepDefinitionReporter stepDefinitionReporter = plugins.stepDefinitionReporter();200 runnerSupplier.get().reportStepDefinitions(stepDefinitionReporter);201 runFeatures.evaluate();202 bus.send(new TestRunFinished(bus.getTime(), bus.getTimeMillis()));203 }204 }205 @Override206 public void setScheduler(RunnerScheduler scheduler) {207 super.setScheduler(scheduler);208 multiThreadingAssumed = true;209 }210 @Override211 public List<FeatureRunner> getChildren() {212 try {213 EnvironmentVariables environmentVariables = Injectors.getInjector().getInstance(EnvironmentVariables.class);214 RuntimeOptions runtimeOptions = currentRuntimeOptions();215 List<String> tagFilters = runtimeOptions.getTagFilters();216 List<URI> featurePaths = runtimeOptions.getFeaturePaths();217 int batchNumber = environmentVariables.getPropertyAsInteger(SERENITY_BATCH_NUMBER, 1);218 int batchCount = environmentVariables.getPropertyAsInteger(SERENITY_BATCH_COUNT, 1);219 int forkNumber = environmentVariables.getPropertyAsInteger(SERENITY_FORK_NUMBER, 1);220 int forkCount = environmentVariables.getPropertyAsInteger(SERENITY_FORK_COUNT, 1);221 if ((batchCount == 1) && (forkCount == 1)) {222 return children;223 } else {224 LOGGER.info("Running slice {} of {} using fork {} of {} from feature paths {}", batchNumber, batchCount, forkNumber, forkCount, featurePaths);225 WeightedCucumberScenarios weightedCucumberScenarios = new CucumberSuiteSlicer(featurePaths, TestStatistics.from(environmentVariables, featurePaths))226 .scenarios(batchNumber, batchCount, forkNumber, forkCount, tagFilters);227 List<FeatureRunner> unfilteredChildren = children;228 AtomicInteger filteredInScenarioCount = new AtomicInteger();229 List<FeatureRunner> filteredChildren = unfilteredChildren.stream()230 .filter(forIncludedFeatures(weightedCucumberScenarios))231 .map(toPossibleFeatureRunner(weightedCucumberScenarios, filteredInScenarioCount))232 .filter(Optional::isPresent)233 .map(Optional::get)234 .collect(toList());235 if (filteredInScenarioCount.get() != weightedCucumberScenarios.totalScenarioCount()) {236 LOGGER.warn(237 "There is a mismatch between the number of scenarios included in this test run ({}) and the expected number of scenarios loaded ({}). This suggests that the scenario filtering is not working correctly or feature file(s) of an unexpected structure are being run",238 filteredInScenarioCount.get(),239 weightedCucumberScenarios.scenarios.size());240 }241 LOGGER.info("Running {} of {} features", filteredChildren.size(), unfilteredChildren.size());242 return filteredChildren;243 }244 } catch (Exception e) {245 LOGGER.error("Test failed to start", e);246 throw e;247 }248 }249 private Function<FeatureRunner, Optional<FeatureRunner>> toPossibleFeatureRunner(WeightedCucumberScenarios weightedCucumberScenarios, AtomicInteger filteredInScenarioCount) {250 return featureRunner -> {251 int initialScenarioCount = featureRunner.getDescription().getChildren().size();252 String featureName = FeatureRunnerExtractors.extractFeatureName(featureRunner);253 try {254 ScenarioFilter filter = weightedCucumberScenarios.createFilterContainingScenariosIn(featureName);255 String featurePath = FeatureRunnerExtractors.featurePathFor(featureRunner);256 featureRunner.filter(filter);257 if (!filter.scenariosIncluded().isEmpty()) {258 LOGGER.info("{} scenario(s) included for '{}' in {}", filter.scenariosIncluded().size(), featureName, featurePath);259 filter.scenariosIncluded().forEach(scenario -> {260 LOGGER.info("Included scenario '{}'", scenario);261 filteredInScenarioCount.getAndIncrement();262 });263 }264 if (!filter.scenariosExcluded().isEmpty()) {265 LOGGER.debug("{} scenario(s) excluded for '{}' in {}", filter.scenariosExcluded().size(), featureName, featurePath);266 filter.scenariosExcluded().forEach(scenario -> LOGGER.debug("Excluded scenario '{}'", scenario));267 }268 return Optional.of(featureRunner);...

Full Screen

Full Screen

Source:CucumberWithSerenity.java Github

copy

Full Screen

1package net.serenitybdd.cucumber;2import net.serenitybdd.cucumber.suiteslicing.CucumberSuiteSlicer;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;74 }75 @Override76 public List<FeatureRunner> getChildren() {77 try {78 EnvironmentVariables environmentVariables = Injectors.getInjector().getInstance(EnvironmentVariables.class);79 RuntimeOptions runtimeOptions = currentRuntimeOptions();80 List<String> tagFilters = runtimeOptions.getTagFilters();81 List<String> featurePaths = runtimeOptions.getFeaturePaths();82 int batchNumber = environmentVariables.getPropertyAsInteger(SERENITY_BATCH_NUMBER, 1);83 int batchCount = environmentVariables.getPropertyAsInteger(SERENITY_BATCH_COUNT, 1);84 int forkNumber = environmentVariables.getPropertyAsInteger(SERENITY_FORK_NUMBER, 1);85 int forkCount = environmentVariables.getPropertyAsInteger(SERENITY_FORK_COUNT, 1);86 if ((batchCount == 1) && (forkCount == 1)) {87 return super.getChildren();88 } else {89 LOGGER.info("Running slice {} of {} using fork {} of {} from feature paths {}", batchNumber, batchCount, forkNumber, forkCount, featurePaths);90 WeightedCucumberScenarios weightedCucumberScenarios = new CucumberSuiteSlicer(featurePaths, TestStatistics.from(environmentVariables, featurePaths))91 .scenarios(batchNumber, batchCount, forkNumber, forkCount, tagFilters);92 List<FeatureRunner> unfilteredChildren = super.getChildren();93 AtomicInteger filteredInScenarioCount = new AtomicInteger();94 List<FeatureRunner> filteredChildren = unfilteredChildren.stream()95 .filter(forIncludedFeatures(weightedCucumberScenarios))96 .map(toPossibleFeatureRunner(weightedCucumberScenarios, filteredInScenarioCount))97 .filter(Optional::isPresent)98 .map(Optional::get)99 .collect(toList());100 if (filteredInScenarioCount.get() != weightedCucumberScenarios.totalScenarioCount()) {101 LOGGER.warn(102 "There is a mismatch between the number of scenarios included in this test run ({}) and the expected number of scenarios loaded ({}). This suggests that the scenario filtering is not working correctly or feature file(s) of an unexpected structure are being run",103 filteredInScenarioCount.get(),104 weightedCucumberScenarios.scenarios.size());105 }106 LOGGER.info("Running {} of {} features", filteredChildren.size(), unfilteredChildren.size());107 return filteredChildren;108 }109 } catch (Exception e) {110 LOGGER.error("Test failed to start", e);111 throw e;112 }113 }114 private Function<FeatureRunner, Optional<FeatureRunner>> toPossibleFeatureRunner(WeightedCucumberScenarios weightedCucumberScenarios, AtomicInteger filteredInScenarioCount) {115 return featureRunner -> {116 int initialScenarioCount = featureRunner.getDescription().getChildren().size();117 String featureName = FeatureRunnerExtractors.extractFeatureName(featureRunner);118 try {119 ScenarioFilter filter = weightedCucumberScenarios.createFilterContainingScenariosIn(featureName);120 String featurePath = FeatureRunnerExtractors.featurePathFor(featureRunner);121 featureRunner.filter(filter);122 if (!filter.scenariosIncluded().isEmpty()) {123 LOGGER.info("{} scenario(s) included for '{}' in {}", filter.scenariosIncluded().size(), featureName, featurePath);124 filter.scenariosIncluded().forEach(scenario -> {125 LOGGER.info("Included scenario '{}'", scenario);126 filteredInScenarioCount.getAndIncrement();127 });128 }129 if (!filter.scenariosExcluded().isEmpty()) {130 LOGGER.debug("{} scenario(s) excluded for '{}' in {}", filter.scenariosExcluded().size(), featureName, featurePath);131 filter.scenariosExcluded().forEach(scenario -> LOGGER.debug("Excluded scenario '{}'", scenario));132 }133 return Optional.of(featureRunner);...

Full Screen

Full Screen

Source:WeightedCucumberScenarios.java Github

copy

Full Screen

...41 .sorted(bySlowestFirst())42 .forEach(scenario -> allScenarios.stream().min(byLowestSumOfDurationFirst()).get().add(scenario));43 return allScenarios.stream().map(WeightedCucumberScenarios::new).collect(toList());44 }45 public ScenarioFilter createFilterContainingScenariosIn(String featureName) {46 LOGGER.debug("Filtering for scenarios in feature {}", featureName);47 List<String> scenarios = this.scenarios.stream()48 .filter(scenario -> {49 boolean matches = scenario.feature.equals(featureName);50 LOGGER.debug("Scenario {} matches {} -> {}", scenario.feature, featureName, matches);51 return matches;52 })53 .map(scenario -> scenario.scenario)54 .collect(toList());55 if (scenarios.isEmpty()) {56 throw new IllegalArgumentException("Can't find feature '" + featureName + "' in this slice");57 }58 return ScenarioFilter.onScenarios(scenarios);59 }60 public WeightedCucumberScenarios filter(Predicate<WeightedCucumberScenario> predicate) {61 return new WeightedCucumberScenarios(scenarios.stream().filter(predicate).collect(toList()));62 }63 @Override64 public int hashCode() {65 return HashCodeBuilder.reflectionHashCode(this);66 }67 @Override68 public boolean equals(Object obj) {69 return reflectionEquals(this, obj);70 }71 @Override72 public String toString() {...

Full Screen

Full Screen

Source:ScenarioFilter.java Github

copy

Full Screen

...4import org.slf4j.Logger;5import org.slf4j.LoggerFactory;6import java.util.List;7import static com.google.common.collect.Lists.newArrayList;8public class ScenarioFilter extends Filter {9 private static final Logger LOGGER = LoggerFactory.getLogger(ScenarioFilter.class);10 private List<String> scenarios;11 private List<String> scenariosIncluded = newArrayList();12 private List<String> scenariosExcluded = newArrayList();13 private ScenarioFilter(List<String> scenarios) {14 this.scenarios = scenarios;15 }16 public static ScenarioFilter onScenarios(List<String> scenarios) {17 return new ScenarioFilter(scenarios);18 }19 @Override20 public String describe() {21 return String.format("Filters out all test steps except those in the list of scenarios: %s", scenarios);22 }23 @Override24 public boolean shouldRun(Description description) {25 String displayName = description.getDisplayName();26 String methodName = description.getMethodName();27 boolean shouldRun = scenarios.stream().anyMatch(methodName::equals) || displayName.startsWith("Examples") || displayName.contains("|");28 LOGGER.debug("Test should run: {} step: {}", shouldRun, description.getDisplayName());29 if (shouldRun) {30 scenariosIncluded.add(displayName);31 } else {...

Full Screen

Full Screen

ScenarioFilter

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;2import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;3import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;4import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;5import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;6import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;7import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;8import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;9import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;10import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;11import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;12import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;13import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;

Full Screen

Full Screen

ScenarioFilter

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.filter.ScenarioFilter;2import net.serenitybdd.cucumber.filter.model.Scenario;3import net.serenitybdd.cucumber.filter.model.Feature;4public class ScenarioFilterExample {5 public static void main(String[] args) {6 String[] features = new String[]{7 };8 ScenarioFilter scenarioFilter = new ScenarioFilter(features);9 List<Scenario> scenarios = scenarioFilter.findScenariosByName(".*scenario1.*");10 for (Scenario scenario : scenarios) {11 System.out.println(scenario.getName());12 System.out.println(scenario.getFeature().getName());13 System.out.println(scenario.getFeature().getPath());14 System.out.println(scenario.getFeature().getTags());15 System.out.println(scenario.getFeature().getLines());16 System.out.println(scenario.getFeature().getElements());17 }18 }19}20[Scenario{name='Scenario 1', tags=[@tag1], steps=[Step{keyword='Given', name='Step 1', line=3}, Step{keyword='When', name='Step 2', line=4}, Step{keyword='Then', name='Step 3', line=5}], lines=[3, 4, 5]}]21[Scenario{name='Scenario 1', tags=[@tag1, @tag2], steps=[Step{keyword='Given', name='Step 1', line=3}, Step{keyword='When', name='

Full Screen

Full Screen

ScenarioFilter

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.featureslicing.ScenarioFilter;2import cucumber.api.CucumberOptions;3@CucumberOptions(features = "src/test/resources/features",4 plugin = {"pretty", "html:target/cucumber-html-report", "json:target/cucumber.json"},5 tags = {"@tag1"}6public class RunCukesTest extends ScenarioFilter {}

Full Screen

Full Screen

ScenarioFilter

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.filter.ScenarioFilter;2import net.serenitybdd.cucumber.filter.ScenarioFilterOptions;3import net.serenitybdd.cucumber.filter.ScenarioFilterOptions;4import net.serenitybdd.cucumber.filter.ScenarioFilter;5import net.serenitybdd.cucumber.filter.ScenarioFilter;6import net.serenitybdd.cucumber.filter.ScenarioFilter;7import net.serenitybdd.cucumber.filter.ScenarioFilter;

Full Screen

Full Screen

ScenarioFilter

Using AI Code Generation

copy

Full Screen

1ScenarioFilter.filterScenariosByTag("tag1", "tag2");2ScenarioFilter.filterScenariosByTag("tag1", "tag2");3ScenarioFilter.filterScenariosByTag("tag1", "tag2");4ScenarioFilter.filterScenariosByTag("tag1", "tag2");5ScenarioFilter.filterScenariosByTag("tag1", "tag2");6ScenarioFilter.filterScenariosByTag("tag1", "tag2");7ScenarioFilter.filterScenariosByTag("tag1", "tag2");8ScenarioFilter.filterScenariosByTag("tag1", "tag2");9ScenarioFilter.filterScenariosByTag("tag1", "tag2");10ScenarioFilter.filterScenariosByTag("tag1", "tag2");11ScenarioFilter.filterScenariosByTag("tag1", "tag2");12ScenarioFilter.filterScenariosByTag("tag1", "tag2");13ScenarioFilter.filterScenariosByTag("tag1", "tag2");14ScenarioFilter.filterScenariosByTag("tag1", "tag2");

Full Screen

Full Screen

ScenarioFilter

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;2import net.serenitybdd.cucumber.suiteslicing.ScenarioFilterTest;3import java.io.File;4import java.io.IOException;5import java.util.ArrayList;6import java.util.List;7public class ScenarioFilterTest {8 public static void main(String[] args) throws IOException {9 List<String> tagsToFilter = new ArrayList<String>();10 tagsToFilter.add("@tag1");11 tagsToFilter.add("@tag2");12 tagsToFilter.add("@tag3");13 ScenarioFilter scenarioFilter = new ScenarioFilter();14 scenarioFilter.filterScenarios(new File("src/test/resources/features"), tagsToFilter);15 }16}

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.

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