How to use load method of net.serenitybdd.cucumber.suiteslicing.CucumberScenarioLoader class

Best Serenity Cucumber code snippet using net.serenitybdd.cucumber.suiteslicing.CucumberScenarioLoader.load

Source:CucumberScenarioLoader.java Github

copy

Full Screen

...30 public CucumberScenarioLoader(List<URI> featurePaths, TestStatistics statistics) {31 this.featurePaths = featurePaths;32 this.statistics = statistics;33 }34 public WeightedCucumberScenarios load() {35 LOGGER.debug("Feature paths are {}", featurePaths);36 ResourceLoader resourceLoader = new MultiLoader(CucumberSuiteSlicer.class.getClassLoader());37 List<WeightedCucumberScenario> weightedCucumberScenarios = new FeatureLoader(resourceLoader).load(featurePaths).stream()38 .map(getScenarios())39 .flatMap(List::stream)40 .collect(toList());41 return new WeightedCucumberScenarios(weightedCucumberScenarios);42 }43 private Function<CucumberFeature, List<WeightedCucumberScenario>> getScenarios() {44 return cucumberFeature -> {45 try {46 return (cucumberFeature.getGherkinFeature().getFeature() == null) ? Collections.emptyList() : cucumberFeature.getGherkinFeature().getFeature().getChildren()47 .stream()48 .filter(child -> asList(ScenarioOutline.class, Scenario.class).contains(child.getClass()))49 .map(scenarioDefinition -> new WeightedCucumberScenario(50 PathUtils.getAsFile(cucumberFeature.getUri()).getName(),51 cucumberFeature.getGherkinFeature().getFeature().getName(),...

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:CucumberScenarioVisualiser.java Github

copy

Full Screen

...28 }29 public void visualise(URI rootFolderURI, int sliceCount, int forkCount, TestStatistics testStatistics) {30 try {31 Files.createDirectories(Paths.get(outputDirectory()));32 List<WeightedCucumberScenarios> slices = new CucumberScenarioLoader(newArrayList(rootFolderURI), testStatistics).load().sliceInto(sliceCount);33 List<VisualisableCucumberScenarios> visualisedSlices = CucumberScenarioVisualiser.sliceIntoForks(forkCount, slices);34 String jsonFile = String.format("%s/%s-slice-config-%s-forks-in-each-of-%s-slices-using-%s.json", outputDirectory(), PathUtils35 .getAsFile(rootFolderURI).getPath().replaceAll("[:/]", "-"), forkCount, sliceCount, testStatistics);36 Files.write(Paths.get(jsonFile), new GsonBuilder().setPrettyPrinting().create().toJson(visualisedSlices).getBytes());37 LOGGER.info("Wrote visualisation as JSON for {} slices -> {}", visualisedSlices.size(), jsonFile);38 } catch (Exception e) {39 throw new RuntimeException("failed to visualise scenarios", e);40 }41 }42}...

Full Screen

Full Screen

Source:CucumberSuiteSlicer.java Github

copy

Full Screen

...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

load

Using AI Code Generation

copy

Full Screen

1package net.serenitybdd.cucumber.suiteslicing;2import java.io.File;3import java.io.IOException;4import java.util.ArrayList;5import java.util.List;6import org.apache.commons.io.FileUtils;7import org.apache.commons.lang3.StringUtils;8import gherkin.formatter.model.Feature;9public class CucumberScenarioLoader {10 public static List<Feature> load(String path) throws IOException {11 List<Feature> features = new ArrayList<Feature>();12 File file = new File(path);13 if(file.isDirectory()) {14 for(File f: file.listFiles()) {15 if(f.getName().endsWith(".feature")) {16 features.addAll(load(f.getAbsolutePath()));17 }18 }19 } else {20 features.addAll(loadFeature(file));21 }22 return features;23 }24 private static List<Feature> loadFeature(File file) throws IOException {25 List<Feature> features = new ArrayList<Feature>();26 String content = FileUtils.readFileToString(file);27 String[] scenarios = StringUtils.substringsBetween(content, "Scenario:", "@");28 if(scenarios == null) {29 scenarios = new String[] {content};30 }31 for(String scenario: scenarios) {32 features.add(new Feature(null, null, null, null, null, null, null, null, null, null));33 }34 return features;35 }36}37import java.io.File;38import java.io.IOException;39import java.util.List;40import org.junit.Test;41import gherkin.formatter.model.Feature;42public class CucumberScenarioLoaderTest {43 public void test() throws IOException {44 List<Feature> features = CucumberScenarioLoader.load("src/test/resources/features");45 System.out.println(features.size());46 }47}48import java.io.File;49import java.io.IOException;50import java.util.List;51import org.junit.Test;52import gherkin.formatter.model.Feature;53public class CucumberScenarioLoaderTest {54 public void test() throws IOException {55 List<Feature> features = CucumberScenarioLoader.load("src/test/resources/features");56 System.out.println(features.size());57 }58}

Full Screen

Full Screen

load

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.suiteslicing.CucumberScenarioLoader;2import net.thucydides.core.util.EnvironmentVariables;3import java.util.List;4public class CucumberScenarioLoader {5 private final EnvironmentVariables environmentVariables;6 public CucumberScenarioLoader(EnvironmentVariables environmentVariables) {7 this.environmentVariables = environmentVariables;8 }9 public List<String> loadScenarios() {10 String scenarioList = environmentVariables.getProperty("cucumber.scenarios");11 return Splitter.on(",").omitEmptyStrings().trimResults().splitToList(scenarioList);12 }13}14import net.serenitybdd.cucumber.suiteslicing.CucumberScenarioLoader;15import net.thucydides.core.util.EnvironmentVariables;16import net.thucydides.core.util.SystemEnvironmentVariables;17import java.util.List;18public class CucumberScenarioLoader {19 private final EnvironmentVariables environmentVariables;20 public CucumberScenarioLoader(EnvironmentVariables environmentVariables) {21 this.environmentVariables = environmentVariables;22 }23 public List<String> loadScenarios() {24 String scenarioList = environmentVariables.getProperty("cucumber.scenarios");25 return Splitter.on(",").omitEmptyStrings().trimResults().splitToList(scenarioList);26 }27}28EnvironmentVariables environmentVariables = new SystemEnvironmentVariables();29CucumberScenarioLoader scenarioLoader = new CucumberScenarioLoader(environmentVariables);30List<String> scenarios = scenarioLoader.loadScenarios();31for (String scenario : scenarios) {32 features.add(CucumberFeature.withFeaturePath(scenario).load());33}34runner.runCucumber(features);35runner.generateReportsView();36runner.generateReportsView();

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 method in CucumberScenarioLoader

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful