How to use currentRuntimeOptions method of io.cucumber.junit.CucumberSerenityRunner class

Best Serenity Cucumber code snippet using io.cucumber.junit.CucumberSerenityRunner.currentRuntimeOptions

Source:CucumberSerenityRunner.java Github

copy

Full Screen

...121 public static void setRuntimeOptions(RuntimeOptions runtimeOptions) {122 RUNTIME_OPTIONS.set(runtimeOptions);123 DEFAULT_RUNTIME_OPTIONS = runtimeOptions;124 }125 public static RuntimeOptions currentRuntimeOptions() {126 return (RUNTIME_OPTIONS.get() != null) ? RUNTIME_OPTIONS.get() : DEFAULT_RUNTIME_OPTIONS;127 }128 private static Collection<String> environmentSpecifiedTags(List<?> existingTags) {129 EnvironmentVariables environmentVariables = Injectors.getInjector().getInstance(EnvironmentVariables.class);130 String tagsExpression = ThucydidesSystemProperty.TAGS.from(environmentVariables,"");131 List<String> existingTagsValues = existingTags.stream().map(Object::toString).collect(toList());132 return Splitter.on(",").trimResults().omitEmptyStrings().splitToList(tagsExpression).stream()133 .map(CucumberSerenityRunner::toCucumberTag).filter(t -> !existingTagsValues.contains(t)).collect(toList());134 }135 private static String toCucumberTag(String from) {136 String tag = from.replaceAll(":","=");137 if (tag.startsWith("~@") || tag.startsWith("@")) { return tag; }138 if (tag.startsWith("~")) { return "~@" + tag.substring(1); }139 return "@" + tag;140 }141 public static Runtime createSerenityEnabledRuntime(ResourceLoader resourceLoader,142 ClassLoader classLoader,143 RuntimeOptions runtimeOptions,144 Configuration systemConfiguration) {145 ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);146 setRuntimeOptions(runtimeOptions);147 FeatureLoader featureLoader = new FeatureLoader(resourceLoader);148 FeaturePathFeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(featureLoader, runtimeOptions);149 // Parse the features early. Don't proceed when there are lexer errors150 final List<CucumberFeature> features = featureSupplier.get();151 EventBus bus = new TimeServiceEventBus(TimeService.SYSTEM);152 153 SerenityReporter serenityReporter = new SerenityReporter(systemConfiguration, resourceLoader);154 Runtime runtime = Runtime.builder().withResourceLoader(resourceLoader).withClassFinder(classFinder).155 withClassLoader(classLoader).withRuntimeOptions(runtimeOptions).156 withAdditionalPlugins(serenityReporter).157 withEventBus(bus).withFeatureSupplier(featureSupplier).158 build();159 return runtime;160 }161 private static void addSerenityReporterPlugin(Plugins plugins, SerenityReporter plugin)162 {163 for(Plugin currentPlugin : plugins.getPlugins()){164 if (currentPlugin instanceof SerenityReporter) {165 return;166 }167 }168 plugins.addPlugin(plugin);169 }170 @Override171 protected Description describeChild(FeatureRunner child) {172 return child.getDescription();173 }174 @Override175 protected void runChild(FeatureRunner child, RunNotifier notifier) {176 child.run(notifier);177 }178 @Override179 protected Statement childrenInvoker(RunNotifier notifier) {180 Statement runFeatures = super.childrenInvoker(notifier);181 return new RunCucumber(runFeatures);182 }183 class RunCucumber extends Statement {184 private final Statement runFeatures;185 RunCucumber(Statement runFeatures) {186 this.runFeatures = runFeatures;187 }188 @Override189 public void evaluate() throws Throwable {190 if (multiThreadingAssumed) {191 plugins.setSerialEventBusOnEventListenerPlugins(bus);192 } else {193 plugins.setEventBusOnEventListenerPlugins(bus);194 }195 bus.send(new TestRunStarted(bus.getTime(), bus.getTimeMillis()));196 for (CucumberFeature feature : features) {197 feature.sendTestSourceRead(bus);198 }199 StepDefinitionReporter stepDefinitionReporter = plugins.stepDefinitionReporter();200 runnerSupplier.get().reportStepDefinitions(stepDefinitionReporter);201 runFeatures.evaluate();202 bus.send(new TestRunFinished(bus.getTime(), bus.getTimeMillis()));203 }204 }205 @Override206 public void setScheduler(RunnerScheduler scheduler) {207 super.setScheduler(scheduler);208 multiThreadingAssumed = true;209 }210 @Override211 public List<FeatureRunner> getChildren() {212 try {213 EnvironmentVariables environmentVariables = Injectors.getInjector().getInstance(EnvironmentVariables.class);214 RuntimeOptions runtimeOptions = currentRuntimeOptions();215 List<String> tagFilters = runtimeOptions.getTagFilters();216 List<URI> featurePaths = runtimeOptions.getFeaturePaths();217 int batchNumber = environmentVariables.getPropertyAsInteger(SERENITY_BATCH_NUMBER, 1);218 int batchCount = environmentVariables.getPropertyAsInteger(SERENITY_BATCH_COUNT, 1);219 int forkNumber = environmentVariables.getPropertyAsInteger(SERENITY_FORK_NUMBER, 1);220 int forkCount = environmentVariables.getPropertyAsInteger(SERENITY_FORK_COUNT, 1);221 if ((batchCount == 1) && (forkCount == 1)) {222 return children;223 } else {224 LOGGER.info("Running slice {} of {} using fork {} of {} from feature paths {}", batchNumber, batchCount, forkNumber, forkCount, featurePaths);225 WeightedCucumberScenarios weightedCucumberScenarios = new CucumberSuiteSlicer(featurePaths, TestStatistics.from(environmentVariables, featurePaths))226 .scenarios(batchNumber, batchCount, forkNumber, forkCount, tagFilters);227 List<FeatureRunner> unfilteredChildren = children;228 AtomicInteger filteredInScenarioCount = new AtomicInteger();...

Full Screen

Full Screen

currentRuntimeOptions

Using AI Code Generation

copy

Full Screen

1 protected RuntimeOptions currentRuntimeOptions() {2 RuntimeOptions runtimeOptions = super.currentRuntimeOptions();3 List<String> tags = runtimeOptions.getFilters().stream()4 .filter(filter -> filter instanceof TagFilter)5 .map(filter -> ((TagFilter) filter).getTagExpression())6 .collect(Collectors.toList());7 if (tags.isEmpty()) {8 return runtimeOptions;9 }10 String tagExpression = tags.stream().collect(Collectors.joining(" and "));11 return runtimeOptionsBuilder(runtimeOptions).addFilters(new TagFilter(tagExpression)).build();12 }13 private RuntimeOptionsBuilder runtimeOptionsBuilder(RuntimeOptions runtimeOptions) {14 return new RuntimeOptionsBuilder(runtimeOptions)15 .addPlugin(new SerenityReporter());16 }17 private class SerenityReporter implements Plugin {18 public void setEventPublisher(EventPublisher publisher) {19 publisher.registerHandlerFor(TestRunFinished.class, event -> SerenityReporter.this.generateReports());20 }21 private void generateReports() {22 try {23 if (SerenityReporter.class.getClassLoader().loadClass("net.serenitybdd.core.Serenity") != null) {24 SerenityReporter.class.getClassLoader().loadClass("net.serenitybdd.core.Serenity").getMethod("generateReportsForTestResultsFrom", ClassLoader.class).invoke(null, SerenityReporter.class.getClassLoader());25 }26 } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {27 e.printStackTrace();28 }29 }30 }31}

Full Screen

Full Screen

currentRuntimeOptions

Using AI Code Generation

copy

Full Screen

1 protected RuntimeOptions currentRuntimeOptions() {2 RuntimeOptions runtimeOptions = super.currentRuntimeOptions();3 List<String> tags = new ArrayList<>();4 tags.add("@Test");5 .withFilters(new Filters(tags, Collections.emptyList()));6 }7 protected List<String> storyPaths() {8 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");9 }10 protected List<Object> stepsFactory() {11 return new InstanceStepsFactory(configuration(), new LoginSteps())12 .createCandidateSteps();13 }14}15CucumberWithSerenity runner = new CucumberWithSerenity(YourTest.class);16runner.run();17@RunWith(CucumberWithSerenity.class)18@CucumberOptions(plugin = {"pretty", "html:target/cucumber-html-report"}, features = "src/test/resources/features")19public class TestRunner {20 protected RuntimeOptions currentRuntimeOptions() {21 RuntimeOptions runtimeOptions = super.currentRuntimeOptions();22 List<String> tags = new ArrayList<>();23 tags.add("@Test");24 .withFilters(new Filters(tags, Collections.emptyList()));25 }26 protected List<String> storyPaths() {27 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");28 }29 protected List<Object> stepsFactory() {30 return new InstanceStepsFactory(configuration(), new LoginSteps())31 .createCandidateSteps();32 }33}

Full Screen

Full Screen

currentRuntimeOptions

Using AI Code Generation

copy

Full Screen

1package com.test.automation.stepDefinitions;2import cucumber.api.java.en.Given;3import cucumber.api.java.en.Then;4import cucumber.api.java.en.When;5import cucumber.api.java.en.And;6public class StepDefinition {7@Given("^I want to write a step with precondition$")8public void i_want_to_write_a_step_with_precondition() throws Throwable {9 throw new PendingException();10}11@Given("^some other precondition$")12public void some_other_precondition() throws Throwable {13 throw new PendingException();14}15@When("^I complete action$")16public void i_complete_action() throws Throwable {17 throw new PendingException();18}19@When("^some other action$")20public void some_other_action() throws Throwable {21 throw new PendingException();22}23@When("^yet another action$")24public void yet_another_action() throws Throwable {25 throw new PendingException();26}27@Then("^I validate the outcomes$")28public void i_validate_the_outcomes() throws Throwable {29 throw new PendingException();30}31@Then("^check more outcomes$")32public void check_more_outcomes() throws Throwable {33 throw new PendingException();34}35@And("^I want to check more outcomes$")36public void i_want_to_check_more_outcomes() throws Throwable {37 throw new PendingException();38}39}40package com.test.automation.stepDefinitions;41import cucumber.api.java.en.Given;42import cucumber.api.java.en.Then;43import cucumber.api.java.en.When;44import cucumber.api.java.en.And;45public class StepDefinition {46@Given("^I want to write a step with precondition$")47public void i_want_to_write_a_step_with_precondition() throws Throwable {48 throw new PendingException();49}50@Given("^some other precondition$")51public void some_other_precondition() throws Throwable {52 throw new PendingException();53}54@When("^I complete action$")55public void i_complete_action() throws Throwable {56 throw new PendingException();57}58@When("^some other action$")59public void some_other_action() throws Throwable {60 throw new PendingException();61}62@When("^yet another action$")63public void yet_another_action() throws Throwable {64 throw new PendingException();65}66@Then("^I validate the outcomes$")67public void i_validate_the_outcomes() throws Throwable {68 throw new PendingException();69}70@Then("^check more outcomes$")71public void check_more_outcomes() throws Throwable {

Full Screen

Full Screen

currentRuntimeOptions

Using AI Code Generation

copy

Full Screen

1public class CucumberSerenityRunner extends Cucumber {2 public CucumberSerenityRunner(Class clazz) throws InitializationError {3 super(clazz);4 }5 protected RuntimeOptions createRuntimeOptions(Properties properties) {6 RuntimeOptions runtimeOptions = currentRuntimeOptions();7 return runtimeOptions;8 }9}10dependencies {

Full Screen

Full Screen

currentRuntimeOptions

Using AI Code Generation

copy

Full Screen

1CucumberSerenityRunner runner = (CucumberSerenityRunner) this.getClass().getDeclaredConstructor().newInstance();2RuntimeOptions runtimeOptions = runner.currentRuntimeOptions();3List<Object> cucumberOptions = runtimeOptions.getFilters();4System.out.println(cucumberOptions);5CucumberSerenityRunner runner = (CucumberSerenityRunner) this.getClass().getDeclaredConstructor().newInstance();6RuntimeOptions runtimeOptions = runner.currentRuntimeOptions();7List<Object> cucumberOptions = runtimeOptions.getFilters();8System.out.println(cucumberOptions);9CucumberSerenityRunner runner = (CucumberSerenityRunner) this.getClass().getDeclaredConstructor().newInstance();10RuntimeOptions runtimeOptions = runner.currentRuntimeOptions();11List<Object> cucumberOptions = runtimeOptions.getFilters();12System.out.println(cucumberOptions);13CucumberSerenityRunner runner = (CucumberSerenityRunner) this.getClass().getDeclaredConstructor().newInstance();14RuntimeOptions runtimeOptions = runner.currentRuntimeOptions();15List<Object> cucumberOptions = runtimeOptions.getFilters();16System.out.println(cucumberOptions);17CucumberSerenityRunner runner = (CucumberSerenityRunner) this.getClass().getDeclaredConstructor().newInstance();18RuntimeOptions runtimeOptions = runner.currentRuntimeOptions();19List<Object> cucumberOptions = runtimeOptions.getFilters();20System.out.println(cucumberOptions);21CucumberSerenityRunner runner = (CucumberSerenityRunner) this.getClass().getDeclaredConstructor().newInstance();

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful