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

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

Run Serenity Cucumber automation tests on LambdaTest cloud grid

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

copy
1package net.serenitybdd.cucumber.suiteslicing;
2
3import org.junit.Before;
4import org.junit.Test;
5
6import java.net.URI;
7
8import static com.google.common.collect.Lists.newArrayList;
9import static org.hamcrest.Matchers.contains;
10import static org.hamcrest.Matchers.containsInAnyOrder;
11import static org.hamcrest.core.Is.is;
12import static org.junit.Assert.assertThat;
13
14public class CucumberScenarioLoaderTest {
15
16    private TestStatistics testStatistics;
17
18    @Before
19    public void setup() {
20        testStatistics = new DummyStatsOfWeightingOne();
21    }
22
23    @Test
24    public void shouldEnsureThatFeaturesWithBackgroundsDontCountThemAsScenarios() throws Exception {
25        WeightedCucumberScenarios weightedCucumberScenarios = new CucumberScenarioLoader(newArrayList(new URI("classpath:samples/simple_table_based_scenario.feature")), testStatistics).load();
26        assertThat(weightedCucumberScenarios.scenarios, containsInAnyOrder(MatchingCucumberScenario.with()
27                                                                               .featurePath("simple_table_based_scenario.feature")
28                                                                               .feature("Buying things - with tables")
29                                                                               .scenario("Buying lots of widgets"),
30                                                                           MatchingCucumberScenario.with()
31                                                                               .featurePath("simple_table_based_scenario.feature")
32                                                                               .feature("Buying things - with tables")
33                                                                               .scenario("Buying more widgets")));
34    }
35
36    @Test
37    public void shouldLoadFeatureAndScenarioTagsOntoCorrectScenarios() throws Exception {
38        WeightedCucumberScenarios weightedCucumberScenarios = new CucumberScenarioLoader(newArrayList(new URI("classpath:samples/simple_table_based_scenario.feature")), testStatistics).load();
39
40        assertThat(weightedCucumberScenarios.scenarios, contains(MatchingCucumberScenario.with()
41                                                                     .featurePath("simple_table_based_scenario.feature")
42                                                                     .feature("Buying things - with tables")
43                                                                     .scenario("Buying lots of widgets")
44                                                                     .tags("@shouldPass"),
45                                                                 MatchingCucumberScenario.with()
46                                                                     .featurePath("simple_table_based_scenario.feature")
47                                                                     .feature("Buying things - with tables")
48                                                                     .scenario("Buying more widgets")
49                                                                     .tags()));
50    }
51
52
53}
54
Full Screen
copy
1package net.serenitybdd.cucumber.suiteslicing;
2
3import net.serenitybdd.cucumber.util.TagParser;
4
5import java.net.URI;
6import java.util.List;
7import java.util.function.Predicate;
8
9import static com.google.common.collect.Lists.newArrayList;
10
11public class CucumberSuiteSlicer {
12
13    private final List<URI> featurePaths;
14    private final TestStatistics statistics;
15
16    public CucumberSuiteSlicer(List<URI> featurePaths, TestStatistics statistics) {
17        this.featurePaths = featurePaths;
18        this.statistics = statistics;
19    }
20
21    public WeightedCucumberScenarios scenarios(int batchNumber, int batchCount, int forkNumber, int forkCount, List<String> tagFilters) {
22        return new CucumberScenarioLoader(featurePaths, statistics).load()
23            .filter(forSuppliedTags(tagFilters))
24            .slice(batchNumber).of(batchCount).slice(forkNumber).of(forkCount);
25    }
26
27    private Predicate<WeightedCucumberScenario> forSuppliedTags(List<String> tagFilters) {
28        return cucumberScenario -> TagParser.parseFromTagFilters(tagFilters).evaluate(newArrayList(cucumberScenario.tags));
29    }
30
31}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on CucumberScenarioLoader

    No relevant questions found for this class 😞

Most used methods in CucumberScenarioLoader

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)