How to use sliceInto method of net.serenitybdd.cucumber.suiteslicing.WeightedCucumberScenarios class

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

copy

Full Screen

...57 new URI("classpath:samples/​scenario_with_table_in_background_steps.feature"),58 new URI("classpath:samples/​tagged_example_tables.feature"));59 int sliceCount = 5;60 List<WeightedCucumberScenarios> jvm1Slices = new CucumberScenarioLoader(featurePaths, new DummyStatsOfWeightingOne()).load()61 .sliceInto(sliceCount);62 List<WeightedCucumberScenarios> jvm2Slices = new CucumberScenarioLoader(featurePaths, new DummyStatsOfWeightingOne()).load()63 .sliceInto(sliceCount);64 for (int i = 0; i < jvm1Slices.size(); i++) {65 assertThat(jvm1Slices.get(i).scenarios, contains(buildMatchingCucumberScenario(jvm2Slices.get(i))));66 }67 }68 private MatchingCucumberScenario[] buildMatchingCucumberScenario(WeightedCucumberScenarios weightedCucumberScenarios) {69 List<MatchingCucumberScenario> list = new ArrayList<>();70 weightedCucumberScenarios.scenarios.forEach(s -> {71 MatchingCucumberScenario match = MatchingCucumberScenario.with()72 .feature(s.feature)73 .featurePath(s.featurePath)74 .scenario(s.scenario);75 list.add(match);76 });77 return list.toArray(new MatchingCucumberScenario[list.size()]);...

Full Screen

Full Screen
copy

Full Screen

...31 }32 public SliceBuilder slice(int sliceNumber) {33 return new SliceBuilder(sliceNumber, this);34 }35 public List<WeightedCucumberScenarios> sliceInto(int sliceCount) {36 BigDecimal totalWeight = scenarios.stream().map(WeightedCucumberScenario::weighting).reduce(ZERO, BigDecimal::add);37 BigDecimal averageWeightPerSlice = totalWeight.divide(new BigDecimal(sliceCount), 2, RoundingMode.HALF_UP);38 LOGGER.debug("Total weighting for {} scenarios is {}, split across {} slices provides average weighting per slice of {}", scenarios.size(), totalWeight, sliceCount, averageWeightPerSlice);39 List<List<WeightedCucumberScenario>> allScenarios = IntStream.rangeClosed(1, sliceCount).mapToObj(initialiseAs -> new ArrayList<WeightedCucumberScenario>()).collect(toList());40 scenarios.stream()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);...

Full Screen

Full Screen
copy

Full Screen

...20 }21 private String outputDirectory() {22 return environmentVariables.getProperty(SERENITY_OUTPUT_DIRECTORY, "target/​site/​serenity");23 }24 public static List<VisualisableCucumberScenarios> sliceIntoForks(int forkCount, List<WeightedCucumberScenarios> slices) {25 return slices.stream()26 .map(slice -> IntStream.rangeClosed(1, forkCount).mapToObj(forkNumber -> VisualisableCucumberScenarios.create(slices.indexOf(slice) + 1, forkNumber, slice.slice(forkNumber).of(forkCount)))27 .collect(toList())).flatMap(List::stream).collect(toList());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
copy

Full Screen

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

Full Screen

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

sliceInto

Using AI Code Generation

copy

Full Screen

1import cucumber.api.junit.Cucumber;2import net.serenitybdd.cucumber.CucumberWithSerenity;3import net.serenitybdd.cucumber.suiteslicing.WeightedCucumberScenarios;4import org.junit.runner.RunWith;5import java.util.List;6@RunWith(Cucumber.class)7public class RunCucumberTest {8 public static void main(String[] args) {9 List<String> scenarios = WeightedCucumberScenarios.sliceInto(5, "src/​test/​resources/​features", "classpath:features");10 for (String scenario : scenarios) {11 System.out.println(scenario);12 }13 }14}

Full Screen

Full Screen

sliceInto

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.cucumber.suiteslicing.WeightedCucumberScenarios;2import net.serenitybdd.cucumber.suiteslicing.TestScenario;3import net.serenitybdd.cucumber.suiteslicing.ScenarioWeightCalculator;4import net.serenitybdd.cucumber.suiteslicing.ScenarioWeight;5import net.serenitybdd.cucumber.suiteslicing.CucumberScenario;6import java.util.List;7import java.util.ArrayList;8import java.util.Arrays;9import java.util.stream.Collectors;10import static net.serenitybdd.cucumber.suiteslicing.ScenarioWeight.*;11public class ScenarioWeightCalculatorImpl implements ScenarioWeightCalculator {12 private final List<String> tagsToInclude = Arrays.asList("@smoke", "@regression");13 private final List<String> tagsToExclude = Arrays.asList("@wip", "@manual", "@manual-qa", "@manual-automation");14 public ScenarioWeight calculateWeightFor(CucumberScenario scenario) {15 if (scenario.hasTags(tagsToInclude) && !scenario.hasTags(tagsToExclude)) {16 return Important;17 }18 if (scenario.hasTags(tagsToExclude)) {19 return Excluded;20 }21 return Unimportant;22 }23 public static void main(String[] args) {24 String[] scenarios = new String[]{"@smoke", "@regression", "@wip", "@manual", "@manual-qa", "@manual-automation"};25 List<TestScenario> testScenarios = new ArrayList<>();26 for (String scenario : scenarios) {27 testScenarios.add(new TestScenario(scenario));28 }29 WeightedCucumberScenarios weightedCucumberScenarios = new WeightedCucumberScenarios();30 List<TestScenario> slicedScenarios = weightedCucumberScenarios.sliceInto(testScenarios, 3, new ScenarioWeightCalculatorImpl());31 System.out.println(slicedScenarios.stream().map(TestScenario::getTags).collect(Collectors.toList()));32 }33}

Full Screen

Full Screen

sliceInto

Using AI Code Generation

copy

Full Screen

1 private List<CucumberScenario> sliceInto(int numberOfSlices, int sliceNumber) {2 List<CucumberScenario> scenarios = new ArrayList<>();3 for (CucumberScenario scenario : allScenarios) {4 if (scenario.isIncludedInSlice(numberOfSlices, sliceNumber)) {5 scenarios.add(scenario);6 }7 }8 return scenarios;9 }10}11 private List<CucumberScenario> sliceInto(int numberOfSlices, int sliceNumber) {12 List<CucumberScenario> scenarios = new ArrayList<>();13 for (CucumberScenario scenario : allScenarios) {14 if (scenario.isIncludedInSlice(numberOfSlices, sliceNumber)) {15 scenarios.add(scenario);16 }17 }18 return scenarios;19 }20package com.testrunner;21import cucumber.api.CucumberOptions;22import cucumber.api.junit.Cucumber;23import net.serenitybdd.cucumber.CucumberWithSerenity;24import org.junit.runner.RunWith;25@RunWith(CucumberWithSerenity.class)26@CucumberOptions(27 features = {"classpath:features/​"},28 glue = {"com.stepdefinitions"},29 plugin = {"pretty", "json:target/​cucumber.json"})30public class TestRunner {31}32package com.testrunner;33import cucumber.api.CucumberOptions;34import cucumber.api.junit.Cucumber;35import net.serenitybdd.cucumber.CucumberWithSerenity;36import org.junit.runner.RunWith;37@RunWith(CucumberWithSerenity.class)38@CucumberOptions(39 features = {"classpath:features/​Feature1.feature:1"},40 glue = {"com.stepdefinitions"},41 plugin = {"pretty", "json:target/​cucumber.json"})42public class TestRunner1 {43}44package com.testrunner;45import cucumber.api.CucumberOptions;46import cucumber.api.junit.Cucumber;47import net.serenitybdd.cucumber.CucumberWithSerenity;48import org.junit.runner.RunWith;49@RunWith(CucumberWithS

Full Screen

Full Screen

sliceInto

Using AI Code Generation

copy

Full Screen

1import cucumber.api.CucumberOptions2import cucumber.api.junit.Cucumber3import org.junit.runner.RunWith4import net.serenitybdd.cucumber.suiteslicing.WeightedCucumberScenarios5import net.serenitybdd.cucumber.suiteslicing.WeightedCucumberScenario6import java.io.File7import java.nio.file.Paths8@RunWith(Cucumber::class)9@CucumberOptions(10class SliceIntoTest {11 def "test slicing into multiple feature files"() {12 def featureFile = new File("src/​test/​resources/​features/​sliceInto.feature")13 def scenarios = WeightedCucumberScenarios.fromFeatureFile(featureFile)14 def targetDirectory = Paths.get("target", "cucumber").toFile()15 WeightedCucumberScenarios.sliceInto(scenarios, numberOfScenariosPerFile, targetDirectory)16 def slicedFiles = targetDirectory.listFiles()17 slicedFiles.size() == 218 slicedFiles[0].text.contains("Scenario: scenario 1")19 slicedFiles[0].text.contains("Scenario: scenario 2")20 slicedFiles[1].text.contains("Scenario: scenario 3")21 slicedFiles[1].text.contains("Scenario: scenario 4")22 }23}

Full Screen

Full Screen

StackOverFlow community discussions

Questions
Discussion

Configuring @RunWith to use CucumberWithSerenity.class instead of Cucumber.class in IntelliJ runners

How to set up a maven debug profile for a maven java project

@RunWith(CucumberWithSerenity.class) throws NoClassDefFound cucumber/runtime/junit/Assertions

Serenity/Cucumber test are not running because of a java.lang.ClassNotFoundException: cucumber.runner.TimeServiceEventBus

Running multiple tests features with cucumber for java selenium serenity tests

Serenity Report not showing all the scenarios outline mentioned in feature file though taking all screenshot for all scenario outline

Cucumber+Serenity &quot;You can implement missing steps with the snippets below &quot;

Serenity Headless Chrome crashes occasionally while Non-headless Chrome never crash

Serenity BDD fun features by groups

Getting error &quot;org/openqa/selenium/interactions/HasInputDevices&quot;

Below are the steps from John Ferguson Smart' blog, author of Serenity-BDD (considering that you have installed Cucumber for Java plugin).

Running Cucumber with Serenity feature files directly from IntelliJ:

IntelliJ provides excellent integrated support for Cucumber feature files. You can even run features simply by right-clicking on the feature file. But this won’t work when you are using Cucumber with Serenity, as Serenity needs to instrument the feature file before execution. Fortunately, this is easy to fix. Here’s how:

  • Click on the feature file you want to run
  • In the Run menu Select Run…
  • In the contextual menu, select the feature, then “Edit…”
  • You should now see the ‘Edit Configuration Settings’ window. Set the main class to ‘net.serenitybdd.cucumber.cli.Main’
  • Change the Glue field to the root package of your project (or of your step definitions)
  • Click Apply

Now you can run your feature directly by right-clicking on the feature file.

P.S. Not all versions of Cucumber for Java plugin works correctly, especially when you have just updated IntelliJ IDEA to the latest version. I can confirm that next setup works correctly:

  • IntelliJ IDEA 2018.2.3 (Community version);
  • Cucumber for Java plugion version 182.3934;
  • net.serenity-bdd:serenity-core:2.0.6;
  • net.serenity-bdd:serenity-cucumber:1.9.18
https://stackoverflow.com/questions/52893323/configuring-runwith-to-use-cucumberwithserenity-class-instead-of-cucumber-class

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Create Custom Menus with CSS Select

When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.

Difference Between Web And Mobile Application Testing

Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.

Unveiling Samsung Galaxy Z Fold4 For Mobile App Testing

Hey LambdaTesters! We’ve got something special for you this week. ????

20 Best VS Code Extensions For 2023

With the change in technology trends, there has been a drastic change in the way we build and develop applications. It is essential to simplify your programming requirements to achieve the desired outcomes in the long run. Visual Studio Code is regarded as one of the best IDEs for web development used by developers.

27 Best Website Testing Tools In 2022

Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful