How to use FeatureRunnerExtractors class of io.cucumber.junit package

Best Serenity Cucumber code snippet using io.cucumber.junit.FeatureRunnerExtractors

Source:CucumberSerenityRunner.java Github

copy

Full Screen

...267 }268 private Function<ParentRunner<?>, Optional<ParentRunner<?>>> toPossibleFeatureRunner(WeightedCucumberScenarios weightedCucumberScenarios, AtomicInteger filteredInScenarioCount) {269 return featureRunner -> {270 int initialScenarioCount = featureRunner.getDescription().getChildren().size();271 String featureName = FeatureRunnerExtractors.extractFeatureName(featureRunner);272 try {273 ScenarioFilter filter = weightedCucumberScenarios.createFilterContainingScenariosIn(featureName);274 String featurePath = FeatureRunnerExtractors.featurePathFor(featureRunner);275 featureRunner.filter(filter);276 if (!filter.scenariosIncluded().isEmpty()) {277 LOGGER.info("{} scenario(s) included for '{}' in {}", filter.scenariosIncluded().size(), featureName, featurePath);278 filter.scenariosIncluded().forEach(scenario -> {279 LOGGER.info("Included scenario '{}'", scenario);280 filteredInScenarioCount.getAndIncrement();281 });282 }283 if (!filter.scenariosExcluded().isEmpty()) {284 LOGGER.debug("{} scenario(s) excluded for '{}' in {}", filter.scenariosExcluded().size(), featureName, featurePath);285 filter.scenariosExcluded().forEach(scenario -> LOGGER.debug("Excluded scenario '{}'", scenario));286 }287 return Optional.of(featureRunner);288 } catch (NoTestsRemainException e) {289 LOGGER.info("Filtered out all {} scenarios for feature '{}'", initialScenarioCount, featureName);290 return Optional.empty();291 }292 };293 }294 private Predicate<ParentRunner<?>> forIncludedFeatures(WeightedCucumberScenarios weightedCucumberScenarios) {295 return featureRunner -> {296 String featureName = FeatureRunnerExtractors.extractFeatureName(featureRunner);297 String featurePath = PathUtils.getAsFile(FeatureRunnerExtractors.featurePathFor(featureRunner)).getName();298 boolean matches = weightedCucumberScenarios.scenarios.stream().anyMatch(scenario -> featurePath.equals(scenario.featurePath));299 LOGGER.debug("{} in filtering '{}' in {}", matches ? "Including" : "Not including", featureName, featurePath);300 return matches;301 };302 }303}...

Full Screen

Full Screen

Source:FeatureRunnerExtractorsTest.java Github

copy

Full Screen

1package io.cucumber.junit;2import io.cucumber.junit.FeatureRunnerExtractors;3import org.junit.Test;4import org.junit.runner.Description;5import static org.hamcrest.core.Is.is;6import static org.junit.Assert.*;7import static org.mockito.Mockito.mock;8import static org.mockito.Mockito.when;9public class FeatureRunnerExtractorsTest {10 @Test11 public void extractFeatureNameShouldReturnTheNameOfTheFeatureWithSloppyNamingConvention() {12 performExpectationsWith("Feature : my super feature", "my super feature");13 }14 @Test15 public void extractFeatureNameShouldReturnTheNameOfANormallyNamedFeature() {16 performExpectationsWith("Feature: my super feature", "my super feature");17 }18 @Test19 public void extractFeatureNameShouldReturnTheNameOfTheFeatureThatHasAColon() {20 performExpectationsWith("Feature: my super feature: is with colon", "my super feature: is with colon");21 }22 private void performExpectationsWith(String displayName, String expectation) {23 FeatureRunner runner = mock(FeatureRunner.class);24 Description description = mock(Description.class);25 when(description.getDisplayName()).thenReturn(displayName);26 when(runner.getDescription()).thenReturn(description);27 String name = FeatureRunnerExtractors.extractFeatureName(runner);28 assertThat(name, is(expectation));29 }30}

Full Screen

Full Screen

Source:FeatureRunnerExtractors.java Github

copy

Full Screen

1package io.cucumber.junit;2import java.lang.reflect.Field;3import io.cucumber.junit.FeatureRunner;4public class FeatureRunnerExtractors {5 public static String extractFeatureName(FeatureRunner runner) {6 String displayName = runner.getDescription().getDisplayName();7 return displayName.substring(displayName.indexOf(":") + 1).trim();8 }9 public static String featurePathFor(FeatureRunner featureRunner) {10 try {11 Field field = featureRunner.getDescription().getClass().getDeclaredField("fUniqueId");12 field.setAccessible(true);13 return field.get(featureRunner.getDescription()).toString();14 } catch (Exception e) {15 throw new RuntimeException(e);16 }17 }18}...

Full Screen

Full Screen

FeatureRunnerExtractors

Using AI Code Generation

copy

Full Screen

1import io.cucumber.junit.FeatureRunnerExtractors;2import java.util.List;3import org.junit.runner.Description;4import org.junit.runner.Runner;5import org.junit.runner.manipulation.Filter;6import org.junit.runner.manipulation.NoTestsRemainException;7import org.junit.runner.manipulation.Sorter;8import org.junit.runner.notification.RunNotifier;9public class FeatureRunner extends Runner {10 private final List<Runner> children;11 public FeatureRunner(Class<?> testClass) {12 FeatureRunnerExtractors extractors = new FeatureRunnerExtractors(testClass);13 children = extractors.getFeatureRunners();14 }15 public Description getDescription() {16 Description description = Description.createSuiteDescription("Feature Suite");17 for (Runner child : children) {18 description.addChild(child.getDescription());19 }20 return description;21 }22 public void run(RunNotifier notifier) {23 for (Runner child : children) {24 child.run(notifier);25 }26 }27 public void filter(Filter filter) throws NoTestsRemainException {28 for (Runner child : children) {29 child.filter(filter);30 }31 }32 public void sort(Sorter sorter) {33 for (Runner child : children) {34 child.sort(sorter);35 }36 }37}

Full Screen

Full Screen

FeatureRunnerExtractors

Using AI Code Generation

copy

Full Screen

1import io.cucumber.junit.FeatureRunnerExtractors;2import org.junit.runner.Description;3import org.junit.runner.notification.Failure;4import org.junit.runner.notification.RunListener;5public class FeatureRunnerListener extends RunListener {6 public void testStarted(Description description) throws Exception {7 super.testStarted(description);8 System.out.println("Test started: " + description.getDisplayName());9 }10 public void testFinished(Description description) throws Exception {11 super.testFinished(description);12 System.out.println("Test finished: " + description.getDisplayName());13 }14 public void testFailure(Failure failure) throws Exception {15 super.testFailure(failure);16 System.out.println("Test failed: " + failure.getDescription().getDisplayName());17 }18 public void testIgnored(Description description) throws Exception {19 super.testIgnored(description);20 System.out.println("Test ignored: " + description.getDisplayName());21 }22 public void testRunStarted(Description description) throws Exception {23 super.testRunStarted(description);24 System.out.println("Test run started: " + description.getDisplayName());25 }26 public void testRunFinished(Result result) throws Exception {27 super.testRunFinished(result);28 System.out.println("Test run finished: " + result.getRunCount());29 }30}31@RunWith(Cucumber.class)32@CucumberOptions(33 plugin = {"pretty", "html:target/cucumber.html", "json:target/cucumber.json", "junit:target/cucumber.xml"}34public class CucumberRunner {35}

Full Screen

Full Screen

FeatureRunnerExtractors

Using AI Code Generation

copy

Full Screen

1package io.cucumber.junit;2import io.cucumber.core.feature.FeatureWithLines;3import io.cucumber.core.feature.GluePath;4import io.cucumber.core.gherkin.Feature;5import io.cucumber.core.options.RuntimeOptions;6import io.cucumber.core.runtime.Runtime;7import io.cucumber.core.runtime.RuntimeOptionsFactory;8import io.cucumber.core.runtime.TimeServiceEventBus;9import io.cucumber.plugin.event.EventPublisher;10import io.cucumber.plugin.event.TestSourceRead;11import io.cucumber.plugin.event.TestSourceReadEvent;12import io.cucumber.plugin.event.TestSourceReadEventPublisher;13import io.cucumber.plugin.event.TimeServiceEventBus;14import io.cucumber.plugin.event.TimeServiceEventBus.TimeService;15import io.cucumber.plugin.event.TimeServiceEventBus.TimeServiceEventBus;16import io.cucumber.plugin.event.TimeServiceEventBus.TimeServiceEventBus.TimeServiceEventBusFactory;17import org.junit.runner.Description;18import org.junit.runner.notification.RunNotifier;19import org.junit.runners.ParentRunner;20import org.junit.runners.model.InitializationError;21import org.junit.runners.model.RunnerScheduler;22import org.junit.runners.model.Statement;23import org.opentest4j.TestAbortedException;24import org.slf4j.Logger;25import org.slf4j.LoggerFactory;26import org.slf4j.event.Level;27import org.slf4j.event.LoggingEvent;28import org.slf4j.event.SubstituteLoggingEvent;29import org.slf4j.helpers.FormattingTuple;30import org.slf4j.helpers.MessageFormatter;31import org.slf4j.helpers.SubstituteLogger;32import org.slf4j.helpers.SubstituteLoggerFactory;33import org.slf4j.spi.LocationAwareLogger;34import org.slf4j.spi.LoggingEventBuilder;35import org.slf4j.spi.LoggerFactoryBinder;36import org.slf4j.spi.SubstituteLoggerFactoryBinder;37import org.slf4j.spi.SubstituteLoggingEventFactory;38import org.slf4j.spi.SubstituteLoggingEventFactoryBinder;39import org.slf4j.spi.SubstituteServiceProvider;40import org.slf4j.spi.SubstituteServiceProviderBinder;41import org.slf4j.spi.SubstituteServiceProviderFactory;42import org.slf4j.spi.SubstituteServiceProviderFactoryBinder;43import org.slf4j.spi.SubstituteServiceProviderFactoryBinder.SubstituteServiceProviderFactoryBinding;44import org.slf4j.spi.SubstituteServiceProviderFactoryBinding;45import org.slf4j.spi.SubstituteServiceProviderFactoryBinding.SubstituteServiceProviderFactoryBindingBuilder;46import org.slf4j.spi.SubstituteServiceProviderFactoryBindingBuilder;47import org.slf4j.spi.SubstituteServiceProviderFactoryBindingBuilder

Full Screen

Full Screen

FeatureRunnerExtractors

Using AI Code Generation

copy

Full Screen

1import io.cucumber.junit.FeatureRunnerExtractors;2import io.cucumber.junit.FeatureRunner;3import io.cucumber.junit.Cucumber;4import org.junit.runner.Description;5import org.junit.runner.notification.RunNotifier;6import org.junit.runners.model.InitializationError;7public class FeatureRunner extends Cucumber {8 public FeatureRunner(Class clazz) throws InitializationError {9 super(clazz);10 }11 public void run(RunNotifier notifier) {12 Description description = Description.createSuiteDescription(getTestClass().getJavaClass());13 for (Object child : getChildren()) {14 Description childDescription = FeatureRunnerExtractors.getDescription(child);15 notifier.fireTestStarted(childDescription);16 notifier.fireTestFinished(childDescription);17 }18 notifier.fireTestRunFinished(description);19 }20}21package com.cucumber.runner;22import org.junit.runner.RunWith;23import com.cucumber.junit.FeatureRunner;24@RunWith(FeatureRunner.class)25public class GoogleSearchRunner {26}27Description getDescription(Object child)28Description createTestDescription(Object child)

Full Screen

Full Screen

FeatureRunnerExtractors

Using AI Code Generation

copy

Full Screen

1package io.cucumber.junit;2import org.junit.runner.Description;3import org.junit.runner.Runner;4import org.junit.runner.notification.RunNotifier;5import org.junit.runners.model.InitializationError;6import java.util.List;7public class FeatureRunner extends Runner {8 private final FeatureRunnerExtractors extractors;9 private final List<Runner> children;10 public FeatureRunner(Class<?> clazz) throws InitializationError {11 extractors = new FeatureRunnerExtractors(clazz);12 children = extractors.children();13 }14 public Description getDescription() {15 return extractors.description();16 }17 public void run(RunNotifier notifier) {18 Cucumber.runChildren(extractors, children, notifier);19 }20}21package io.cucumber.junit;22import org.junit.runner.RunWith;23import cucumber.api.CucumberOptions;24import cucumber.api.junit.Cucumber;25@RunWith(Cucumber.class)26@CucumberOptions(27 glue = {"stepDefinitions"},28 tags = {"@SmokeTest"}29public class TestRunner {30}

Full Screen

Full Screen

FeatureRunnerExtractors

Using AI Code Generation

copy

Full Screen

1@CucumberOptions(2 plugin = { "pretty",3 "rerun:target/cucumber-reports/rerun.txt" },4 tags = { "@smoke" },5public class TestRunner extends AbstractTestNGCucumberTests {6 @DataProvider(parallel = true)7 public Object[][] scenarios() {8 return super.scenarios();9 }10 public void runScenario(Scenario scenario) {11 super.runScenario(scenario);12 }13}14public class FeatureRunnerExtractors implements IRunnerFactory {15 public Runner createRunner(Class<?> clazz) throws InitializationError {16 return new FeatureRunner(clazz, FeatureRunnerExtractors::extractFeatureName, FeatureRunnerExtractors::extractScenarioName);17 }18 private static String extractFeatureName(Class<?> clazz) {19 return Optional.ofNullable(clazz.getAnnotation(Feature.class))20 .map(Feature::value)21 .map(FeatureRunnerExtractors::normalize)22 .orElse(clazz.getSimpleName());23 }24 private static String extractScenarioName(Scenario scenario) {25 return Optional.ofNullable(scenario.getName())26 .map(FeatureRunnerExtractors::normalize)27 .orElse(scenario.getId());28 }29 private static String normalize(String name) {30 return name.replaceAll("[^a-zA-Z0-9]", "-");31 }32}33@CucumberOptions(34 plugin = { "pretty",35 "rerun:target/cucumber-reports/rerun.txt" },36 tags = { "@smoke" },

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 FeatureRunnerExtractors

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