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

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

Source:CucumberSerenityRunner.java Github

copy

Full Screen

...16import io.cucumber.tagexpressions.Expression;17import net.serenitybdd.cucumber.suiteslicing.CucumberSuiteSlicer;18import net.serenitybdd.cucumber.suiteslicing.ScenarioFilter;19import net.serenitybdd.cucumber.suiteslicing.TestStatistics;20import net.serenitybdd.cucumber.suiteslicing.WeightedCucumberScenarios;21import net.serenitybdd.cucumber.util.PathUtils;22import net.serenitybdd.cucumber.util.Splitter;23import net.thucydides.core.ThucydidesSystemProperty;24import net.thucydides.core.guice.Injectors;25import net.thucydides.core.util.EnvironmentVariables;26import net.thucydides.core.webdriver.Configuration;27import org.junit.runner.Description;28import org.junit.runner.manipulation.NoTestsRemainException;29import org.junit.runner.notification.RunNotifier;30import org.junit.runners.ParentRunner;31import org.junit.runners.model.InitializationError;32import org.junit.runners.model.RunnerScheduler;33import org.junit.runners.model.Statement;34import org.slf4j.Logger;35import org.slf4j.LoggerFactory;36import java.io.File;37import java.net.URI;38import java.time.Clock;39import java.util.*;40import java.util.concurrent.atomic.AtomicInteger;41import java.util.function.Function;42import java.util.function.Predicate;43import java.util.function.Supplier;44import static io.cucumber.junit.FileNameCompatibleNames.uniqueSuffix;45import static java.util.stream.Collectors.groupingBy;46import static java.util.stream.Collectors.toList;47import static net.thucydides.core.ThucydidesSystemProperty.*;48/**49 * Glue code for running Cucumber via Serenity.50 * Sets up Serenity reporting and instrumentation.51 */52public class CucumberSerenityRunner extends ParentRunner<ParentRunner<?>> {53 private static final Logger LOGGER = LoggerFactory.getLogger(CucumberSerenityRunner.class);54 private List<ParentRunner<?>> children = new ArrayList<ParentRunner<?>>();55 private final EventBus bus;56 private static ThreadLocal<RuntimeOptions> RUNTIME_OPTIONS = new ThreadLocal<>();57 private final List<Feature> features;58 private final Plugins plugins;59 private final CucumberExecutionContext context;60 private boolean multiThreadingAssumed = false;61 /**62 * Constructor called by JUnit.63 *64 * @param clazz the class with the @RunWith annotation.65 * @throws InitializationError if there is another problem66 */67 public CucumberSerenityRunner(Class clazz) throws InitializationError {68 super(clazz);69 Assertions.assertNoCucumberAnnotatedMethods(clazz);70 // Parse the options early to provide fast feedback about invalid options71 RuntimeOptions propertiesFileOptions = new CucumberPropertiesParser()72 .parse(CucumberProperties.fromPropertiesFile())73 .build();74 RuntimeOptions annotationOptions = new CucumberOptionsAnnotationParser()75 .withOptionsProvider(new JUnitCucumberOptionsProvider())76 .parse(clazz)77 .build(propertiesFileOptions);78 RuntimeOptions environmentOptions = new CucumberPropertiesParser()79 .parse(CucumberProperties.fromEnvironment())80 .build(annotationOptions);81 RuntimeOptions runtimeOptions = new CucumberPropertiesParser()82 .parse(CucumberProperties.fromSystemProperties())83 .addDefaultSummaryPrinterIfAbsent()84 .build(environmentOptions);85 RuntimeOptionsBuilder runtimeOptionsBuilder = new RuntimeOptionsBuilder();86 Collection<String> tagFilters = environmentSpecifiedTags(runtimeOptions.getTagExpressions());87 for(String tagFilter : tagFilters ) {88 runtimeOptionsBuilder.addTagFilter(new LiteralExpression(tagFilter));89 }90 runtimeOptionsBuilder.build(runtimeOptions);91 // Next parse the junit options92 JUnitOptions junitPropertiesFileOptions = new JUnitOptionsParser()93 .parse(CucumberProperties.fromPropertiesFile())94 .build();95 JUnitOptions junitAnnotationOptions = new JUnitOptionsParser()96 .parse(clazz)97 .build(junitPropertiesFileOptions);98 JUnitOptions junitEnvironmentOptions = new JUnitOptionsParser()99 .parse(CucumberProperties.fromEnvironment())100 .build(junitAnnotationOptions);101 JUnitOptions junitOptions = new JUnitOptionsParser()102 .parse(CucumberProperties.fromSystemProperties())103 //.setStrict(runtimeOptions.isStrict())104 .build(junitEnvironmentOptions);105 this.bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);106 setRuntimeOptions(runtimeOptions);107 // Parse the features early. Don't proceed when there are lexer errors108 FeatureParser parser = new FeatureParser(bus::generateId);109 Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;110 FeaturePathFeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(classLoader, runtimeOptions, parser);111 this.features = featureSupplier.get();112 // Create plugins after feature parsing to avoid the creation of empty files on lexer errors.113 this.plugins = new Plugins(new PluginFactory(), runtimeOptions);114 ExitStatus exitStatus = new ExitStatus(runtimeOptions);115 this.plugins.addPlugin(exitStatus);116 Configuration systemConfiguration = Injectors.getInjector().getInstance(Configuration.class);117 // customer change on 20201023118 systemConfiguration.setOutputDirectory(new File(System.getProperty(SerenityCucumberMain.REPORT_PROPERTY_NAME)));119 SerenityReporter reporter = new SerenityReporter(systemConfiguration);120 addSerenityReporterPlugin(plugins,reporter);121 ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(runtimeOptions);122 ObjectFactorySupplier objectFactorySupplier = new ThreadLocalObjectFactorySupplier(objectFactoryServiceLoader);123 BackendSupplier backendSupplier = new BackendServiceLoader(clazz::getClassLoader, objectFactorySupplier);124 TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier = new ScanningTypeRegistryConfigurerSupplier(classLoader, runtimeOptions);125 ThreadLocalRunnerSupplier runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, bus, backendSupplier, objectFactorySupplier, typeRegistryConfigurerSupplier);126 this.context = new CucumberExecutionContext(bus, exitStatus, runnerSupplier);127 Predicate<Pickle> filters = new Filters(runtimeOptions);128 Map<Optional<String>, List<Feature>> groupedByName = features.stream()129 .collect(groupingBy(Feature::getName));130 children = features.stream()131 .map(feature -> {132 Integer uniqueSuffix = uniqueSuffix(groupedByName, feature, Feature::getName);133 return FeatureRunner.create(feature, uniqueSuffix,filters, runnerSupplier, junitOptions);134 })135 .filter(runner -> !runner.isEmpty())136 .collect(toList());137 }138 private static RuntimeOptions DEFAULT_RUNTIME_OPTIONS;139 public static void setRuntimeOptions(RuntimeOptions runtimeOptions) {140 RUNTIME_OPTIONS.set(runtimeOptions);141 DEFAULT_RUNTIME_OPTIONS = runtimeOptions;142 }143 public static RuntimeOptions currentRuntimeOptions() {144 return (RUNTIME_OPTIONS.get() != null) ? RUNTIME_OPTIONS.get() : DEFAULT_RUNTIME_OPTIONS;145 }146 private static Collection<String> environmentSpecifiedTags(List<?> existingTags) {147 EnvironmentVariables environmentVariables = Injectors.getInjector().getInstance(EnvironmentVariables.class);148 String tagsExpression = ThucydidesSystemProperty.TAGS.from(environmentVariables,"");149 List<String> existingTagsValues = existingTags.stream().map(Object::toString).collect(toList());150 return Splitter.on(",").trimResults().omitEmptyStrings().splitToList(tagsExpression).stream()151 .map(CucumberSerenityRunner::toCucumberTag).filter(t -> !existingTagsValues.contains(t)).collect(toList());152 }153 private static String toCucumberTag(String from) {154 String tag = from.replaceAll(":","=");155 if (tag.startsWith("~@") || tag.startsWith("@")) { return tag; }156 if (tag.startsWith("~")) { return "~@" + tag.substring(1); }157 return "@" + tag;158 }159 public static Runtime createSerenityEnabledRuntime(/*ResourceLoader resourceLoader,*/160 Supplier<ClassLoader> classLoaderSupplier,161 RuntimeOptions runtimeOptions,162 Configuration systemConfiguration) {163 RuntimeOptionsBuilder runtimeOptionsBuilder = new RuntimeOptionsBuilder();164 Collection<String> allTagFilters = environmentSpecifiedTags(runtimeOptions.getTagExpressions());165 for(String tagFilter : allTagFilters) {166 runtimeOptionsBuilder.addTagFilter(new LiteralExpression(tagFilter));167 }168 runtimeOptionsBuilder.build(runtimeOptions);169 setRuntimeOptions(runtimeOptions);170 EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);171 FeatureParser parser = new FeatureParser(bus::generateId);172 FeaturePathFeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(classLoaderSupplier, runtimeOptions, parser);173 SerenityReporter serenityReporter = new SerenityReporter(systemConfiguration);174 Runtime runtime = Runtime.builder().withClassLoader(classLoaderSupplier).withRuntimeOptions(runtimeOptions).175 withAdditionalPlugins(serenityReporter).176 withEventBus(bus).withFeatureSupplier(featureSupplier).177 build();178 return runtime;179 }180 private static void addSerenityReporterPlugin(Plugins plugins, SerenityReporter plugin)181 {182 for(Plugin currentPlugin : plugins.getPlugins()){183 if (currentPlugin instanceof SerenityReporter) {184 return;185 }186 }187 plugins.addPlugin(plugin);188 }189 @Override190 protected Description describeChild(ParentRunner<?> child) {191 return child.getDescription();192 }193 @Override194 protected void runChild(ParentRunner<?> child, RunNotifier notifier) {195 child.run(notifier);196 }197 @Override198 protected Statement childrenInvoker(RunNotifier notifier) {199 Statement runFeatures = super.childrenInvoker(notifier);200 return new RunCucumber(runFeatures);201 }202 class RunCucumber extends Statement {203 private final Statement runFeatures;204 RunCucumber(Statement runFeatures) {205 this.runFeatures = runFeatures;206 }207 @Override208 public void evaluate() throws Throwable {209 if (multiThreadingAssumed) {210 plugins.setSerialEventBusOnEventListenerPlugins(bus);211 } else {212 plugins.setEventBusOnEventListenerPlugins(bus);213 }214 context.startTestRun();215 features.forEach(context::beforeFeature);216 try {217 runFeatures.evaluate();218 } finally {219 context.finishTestRun();220 }221 }222 }223 @Override224 public void setScheduler(RunnerScheduler scheduler) {225 super.setScheduler(scheduler);226 multiThreadingAssumed = true;227 }228 @Override229 public List<ParentRunner<?>> getChildren() {230 try {231 EnvironmentVariables environmentVariables = Injectors.getInjector().getInstance(EnvironmentVariables.class);232 RuntimeOptions runtimeOptions = currentRuntimeOptions();233 List<Expression> tagFilters = runtimeOptions.getTagExpressions();234 List<URI> featurePaths = runtimeOptions.getFeaturePaths();235 int batchNumber = environmentVariables.getPropertyAsInteger(SERENITY_BATCH_NUMBER, 1);236 int batchCount = environmentVariables.getPropertyAsInteger(SERENITY_BATCH_COUNT, 1);237 int forkNumber = environmentVariables.getPropertyAsInteger(SERENITY_FORK_NUMBER, 1);238 int forkCount = environmentVariables.getPropertyAsInteger(SERENITY_FORK_COUNT, 1);239 if ((batchCount == 1) && (forkCount == 1)) {240 return children;241 } else {242 LOGGER.info("Running slice {} of {} using fork {} of {} from feature paths {}", batchNumber, batchCount, forkNumber, forkCount, featurePaths);243 List<String> tagFiltersAsString = tagFilters.stream().map(Expression::toString).collect(toList());244 WeightedCucumberScenarios weightedCucumberScenarios = new CucumberSuiteSlicer(featurePaths, TestStatistics.from(environmentVariables, featurePaths))245 .scenarios(batchNumber, batchCount, forkNumber, forkCount, tagFiltersAsString);246 List<ParentRunner<?>> unfilteredChildren = children;247 AtomicInteger filteredInScenarioCount = new AtomicInteger();248 List<ParentRunner<?>> filteredChildren = unfilteredChildren.stream()249 .filter(forIncludedFeatures(weightedCucumberScenarios))250 .map(toPossibleFeatureRunner(weightedCucumberScenarios, filteredInScenarioCount))251 .filter(Optional::isPresent)252 .map(Optional::get)253 .collect(toList());254 if (filteredInScenarioCount.get() != weightedCucumberScenarios.totalScenarioCount()) {255 LOGGER.warn(256 "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",257 filteredInScenarioCount.get(),258 weightedCucumberScenarios.scenarios.size());259 }260 LOGGER.info("Running {} of {} features", filteredChildren.size(), unfilteredChildren.size());261 return filteredChildren;262 }263 } catch (Exception e) {264 LOGGER.error("Test failed to start", e);265 throw e;266 }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: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);134 } catch (NoTestsRemainException e) {135 LOGGER.info("Filtered out all {} scenarios for feature '{}'", initialScenarioCount, featureName);136 return Optional.empty();137 }138 };139 }140 private Predicate<FeatureRunner> forIncludedFeatures(WeightedCucumberScenarios weightedCucumberScenarios) {141 return featureRunner -> {142 String featureName = FeatureRunnerExtractors.extractFeatureName(featureRunner);143 String featurePath = Paths.get(FeatureRunnerExtractors.featurePathFor(featureRunner)).getFileName().toString();144 boolean matches = weightedCucumberScenarios.scenarios.stream().anyMatch(scenario -> featurePath.equals(scenario.featurePath));145 LOGGER.debug("{} in filtering '{}' in {}", matches ? "Including" : "Not including", featureName, featurePath);146 return matches;147 };148 }149}...

Full Screen

Full Screen

Source:CucumberScenarioLoaderTest.java Github

copy

Full Screen

...14 testStatistics = new DummyStatsOfWeightingOne();15 }16 @Test17 public void shouldEnsureThatFeaturesWithBackgroundsDontCountThemAsScenarios() throws Exception {18 WeightedCucumberScenarios weightedCucumberScenarios = new CucumberScenarioLoader(newArrayList(new URI("classpath:samples/simple_table_based_scenario.feature")), testStatistics).load();19 assertThat(weightedCucumberScenarios.scenarios, containsInAnyOrder(MatchingCucumberScenario.with()20 .featurePath("simple_table_based_scenario.feature")21 .feature("Buying things - with tables")22 .scenario("Buying lots of widgets"),23 MatchingCucumberScenario.with()24 .featurePath("simple_table_based_scenario.feature")25 .feature("Buying things - with tables")26 .scenario("Buying more widgets")));27 }28 @Test29 public void shouldLoadFeatureAndScenarioTagsOntoCorrectScenarios() throws Exception {30 WeightedCucumberScenarios weightedCucumberScenarios = new CucumberScenarioLoader(newArrayList(new URI("classpath:samples/simple_table_based_scenario.feature")), testStatistics).load();31 assertThat(weightedCucumberScenarios.scenarios, contains(MatchingCucumberScenario.with()32 .featurePath("simple_table_based_scenario.feature")33 .feature("Buying things - with tables")34 .scenario("Buying lots of widgets")35 .tags("@shouldPass"),36 MatchingCucumberScenario.with()37 .featurePath("simple_table_based_scenario.feature")38 .feature("Buying things - with tables")39 .scenario("Buying more widgets")40 .tags()));41 }42}...

Full Screen

Full Screen

Source:WeightedCucumberScenariosTest.java Github

copy

Full Screen

...7import static org.hamcrest.collection.IsCollectionWithSize.hasSize;8import static org.hamcrest.core.Is.is;9import static org.junit.Assert.assertThat;10import static org.junit.Assert.fail;11public class WeightedCucumberScenariosTest {12 @Test13 public void slicingMoreThinlyThanTheNumberOfScenariosShouldResultInSomeEmptySlices() {14 WeightedCucumberScenario weightedCucumberScenario = new WeightedCucumberScenario("test.feature", "featurename", "scenarioname", BigDecimal.ONE, emptySet(), 0);15 List<WeightedCucumberScenario> scenarios = Collections.singletonList(weightedCucumberScenario);16 WeightedCucumberScenarios oneScenario = new WeightedCucumberScenarios(scenarios);17 List<WeightedCucumberScenarios> weightedCucumberScenarios = oneScenario.sliceInto(100);18 assertThat(weightedCucumberScenarios, hasSize(100));19 assertThat(weightedCucumberScenarios.get(0).scenarios, hasSize(1));20 assertThat(weightedCucumberScenarios.get(0).scenarios.get(0), is(weightedCucumberScenario));21 assertThat(weightedCucumberScenarios.get(1).scenarios, hasSize(0));22 assertThat(weightedCucumberScenarios.get(99).scenarios, hasSize(0));23 }24 @Test25 public void slicingASliceIntoOneSliceOfOneShouldBeTheSameAsAllScenarios() {26 List<WeightedCucumberScenario> scenarios = Collections.singletonList(new WeightedCucumberScenario("test.feature", "featurename", "scenarioname", BigDecimal.ONE, emptySet(), 0));27 WeightedCucumberScenarios oneScenario = new WeightedCucumberScenarios(scenarios);28 WeightedCucumberScenarios fork1 = oneScenario.slice(1).of(1);29 assertThat(oneScenario, is(fork1));30 }31}...

Full Screen

Full Screen

Source:VisualisableCucumberScenarios.java Github

copy

Full Screen

1package net.serenitybdd.cucumber.suiteslicing;2import org.apache.commons.lang3.builder.HashCodeBuilder;3import org.apache.commons.lang3.builder.ToStringBuilder;4import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals;5public class VisualisableCucumberScenarios extends WeightedCucumberScenarios {6 public final Integer slice;7 public final Integer forkNumber;8 private VisualisableCucumberScenarios(Integer slice, Integer forkNumber, WeightedCucumberScenarios WeightedCucumberScenarios) {9 super(WeightedCucumberScenarios.scenarios);10 this.forkNumber = forkNumber;11 this.slice = slice;12 }13 public static VisualisableCucumberScenarios create(Integer slice, Integer forkNumber, WeightedCucumberScenarios WeightedCucumberScenarios) {14 return new VisualisableCucumberScenarios(slice, forkNumber, WeightedCucumberScenarios);15 }16 @Override17 public int hashCode() {18 return HashCodeBuilder.reflectionHashCode(this);19 }20 @Override21 public boolean equals(Object obj) {22 return reflectionEquals(this, obj);23 }24 @Override25 public String toString() {26 return ToStringBuilder.reflectionToString(this);27 }28}...

Full Screen

Full Screen

Source:SliceBuilder.java Github

copy

Full Screen

1package net.serenitybdd.cucumber.suiteslicing;2public class SliceBuilder {3 private int sliceNumber;4 private WeightedCucumberScenarios weightedCucumberScenarios;5 public SliceBuilder(int sliceNumber, WeightedCucumberScenarios weightedCucumberScenarios) {6 this.sliceNumber = sliceNumber;7 this.weightedCucumberScenarios = weightedCucumberScenarios;8 }9 public WeightedCucumberScenarios of(int sliceCount) {10 return weightedCucumberScenarios.sliceInto(sliceCount).get(sliceNumber - 1);11 }12}...

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