How to use getConfiguration method of net.serenitybdd.jbehave.runners.SerenityReportingRunner class

Best Serenity jBehave code snippet using net.serenitybdd.jbehave.runners.SerenityReportingRunner.getConfiguration

Source:SerenityReportingRunner.java Github

copy

Full Screen

...69 storyDescriptions = buildDescriptionFromStories();70 }71 return storyDescriptions;72 }73 protected Configuration getConfiguration() {74 if (configuration == null) {75 configuration = getConfiguredEmbedder().configuration();76 }77 return configuration;78 }79 public ExtendedEmbedder getConfiguredEmbedder() {80 if (configuredEmbedder == null) {81 configuredEmbedder = (ExtendedEmbedder) configurableEmbedder.configuredEmbedder();82 }83 return configuredEmbedder;84 }85 List<String> getStoryPaths() {86 if ((storyPaths == null) || (storyPaths.isEmpty())) {87 storyPaths = storyPathsFromRunnerClass();88 }89 return storyPaths;90 }91 private List<String> storyPathsFromRunnerClass() {92 try {93 List<String> storyPaths = new StoryPathsExtractor(configurableEmbedder).getStoryPaths();94 String storyFilter = getStoryFilterFrom(configurableEmbedder);95 return storyPaths.stream()96 .filter(story -> story.matches(storyFilter))97 .collect(Collectors.toList());98 } catch (Throwable e) {99 LOGGER.error("Could not load story paths", e);100 return Collections.emptyList();101 }102 }103 private String getStoryFilterFrom(ConfigurableEmbedder embedder) {104 String defaultStoryFilter = environmentVariables.getProperty(SerenityJBehaveSystemProperties.STORY_FILTER.getName(), ".*");105 Optional<Method> getStoryFilter = Arrays.stream(embedder.getClass().getMethods())106 .filter(method -> method.getName().equals("getStoryFilter"))107 .findFirst();108 if (getStoryFilter.isPresent()) {109 try {110 Optional<Object> storyFilterValue = Optional.ofNullable(getStoryFilter.get().invoke(embedder));111 return storyFilterValue.orElse(defaultStoryFilter).toString();112 } catch (IllegalAccessException | InvocationTargetException e) {113 LOGGER.warn("Could not invoke getStoryFilter() method on {}", embedder, e);114 }115 }116 return defaultStoryFilter;117 }118 private EnvironmentVariables environmentVariablesFrom(ConfigurableEmbedder configurableEmbedder) {119 if (configurableEmbedder instanceof SerenityStories) {120 return ((SerenityStories) configurableEmbedder).getEnvironmentVariables();121 } else {122 return Injectors.getInjector().getProvider(EnvironmentVariables.class).get();123 }124 }125 @Override126 public Description getDescription() {127 if (description == null) {128 description = Description.createSuiteDescription(configurableEmbedder.getClass());129 for (Description childDescription : getDescriptions()) {130 description.addChild(childDescription);131 }132 }133 return description;134 }135 private int testCount = 0;136 @Override137 public int testCount() {138 if (testCount == 0) {139 testCount = countStories();140 }141 return testCount;142 }143 @Override144 public void run(RunNotifier notifier) {145 beforeStoriesRun(getConfiguredEmbedder());146 getConfiguredEmbedder().embedderControls().doIgnoreFailureInView(getIgnoreFailuresInView());147 getConfiguredEmbedder().embedderControls().doIgnoreFailureInStories(getIgnoreFailuresInStories());148 getConfiguredEmbedder().embedderControls().useStoryTimeoutInSecs(getStoryTimeoutInSecs());149 getConfiguredEmbedder().embedderControls().useStoryTimeouts(getStoryTimeout());150 getConfiguredEmbedder().embedderControls().useThreads(getThreadCount());151 if (metaFiltersAreDefined()) {152 getConfiguredEmbedder().useMetaFilters(getMetaFilters());153 }154// if (!isRunningInMaven() && !isRunningInGradle()) {155 JUnitScenarioReporter junitReporter = new JUnitScenarioReporter(notifier, testCount(), getDescription(),156 getConfiguredEmbedder().configuration().keywords());157 // tell the reporter how to handle pending steps158 junitReporter.usePendingStepStrategy(getConfiguration().pendingStepStrategy());159 JUnitReportingRunner.recommendedControls(getConfiguredEmbedder());160 addToStoryReporterFormats(junitReporter);161// }162 try {163 getConfiguredEmbedder().runStoriesAsPaths(getStoryPaths());164 } catch (Throwable e) {165 throw new SerenityManagedException(e);166 } finally {167 getConfiguredEmbedder().generateCrossReference();168 }169 shutdownTestSuite();170 }171 private boolean isRunningInGradle() {172 return Stream.of(new Exception().getStackTrace()).anyMatch(elt -> elt.getClassName().startsWith("org.gradle"));173 }174 /**175 * Override this method to add custom configuration to the JBehave embedder object.176 *177 * @param configuredEmbedder178 */179 public void beforeStoriesRun(ExtendedEmbedder configuredEmbedder) {180 }181 private void shutdownTestSuite() {182 StepEventBus.getEventBus().testSuiteFinished();183 }184 List<CandidateSteps> getCandidateSteps() {185 if (candidateSteps == null) {186 StepMonitor originalStepMonitor = createCandidateStepsWithNoMonitor();187 createCandidateStepsWith(originalStepMonitor);188 }189 return candidateSteps;190 }191 private void createCandidateStepsWith(StepMonitor stepMonitor) {192 // reset step monitor and recreate candidate steps193 getConfiguration().useStepMonitor(stepMonitor);194 candidateSteps = buildCandidateSteps();195 candidateSteps.forEach(196 step -> step.configuration().useStepMonitor(stepMonitor)197 );198 }199 private StepMonitor createCandidateStepsWithNoMonitor() {200 StepMonitor usedStepMonitor = getConfiguration().stepMonitor();201 createCandidateStepsWith(new NullStepMonitor());202 return usedStepMonitor;203 }204 private List<CandidateSteps> buildCandidateSteps() {205 List<CandidateSteps> candidateSteps;206 InjectableStepsFactory stepsFactory = configurableEmbedder207 .stepsFactory();208 if (stepsFactory != null) {209 candidateSteps = stepsFactory.createCandidateSteps();210 } else {211 Embedder embedder = getConfiguredEmbedder();212 candidateSteps = embedder.candidateSteps();213 if (candidateSteps == null || candidateSteps.isEmpty()) {214 candidateSteps = embedder.stepsFactory().createCandidateSteps();215 }216 }217 return candidateSteps;218 }219 private void addToStoryReporterFormats(JUnitScenarioReporter junitReporter) {220 StoryReporterBuilder storyReporterBuilder = getConfiguration().storyReporterBuilder();221 StoryReporterBuilder.ProvidedFormat junitReportFormat222 = new StoryReporterBuilder.ProvidedFormat(junitReporter);223 storyReporterBuilder.withFormats(junitReportFormat);224 }225 private List<Description> buildDescriptionFromStories() {226 List<CandidateSteps> candidateSteps = getCandidateSteps();227 JUnitDescriptionGenerator descriptionGenerator = new JUnitDescriptionGenerator(candidateSteps, getConfiguration());228 List<Description> storyDescriptions = new ArrayList<>();229 addSuite(storyDescriptions, "BeforeStories");230 PerformableTree performableTree = createPerformableTree(candidateSteps, getStoryPaths());231 storyDescriptions.addAll(descriptionGenerator.createDescriptionFrom(performableTree));232 addSuite(storyDescriptions, "AfterStories");233 return storyDescriptions;234 }235 private int countStories() {236 JUnitDescriptionGenerator descriptionGenerator = new JUnitDescriptionGenerator(getCandidateSteps(), getConfiguration());237 return descriptionGenerator.getTestCases() + beforeAndAfterStorySteps();238 }239 private int beforeAndAfterStorySteps() {240 return 2;241 }242 private PerformableTree createPerformableTree(List<CandidateSteps> candidateSteps, List<String> storyPaths) {243 ExtendedEmbedder configuredEmbedder = this.getConfiguredEmbedder();244 configuredEmbedder.useMetaFilters(getMetaFilters());245 BatchFailures failures = new BatchFailures(configuredEmbedder.embedderControls().verboseFailures());246 PerformableTree performableTree = configuredEmbedder.performableTree();247 RunContext context = performableTree.newRunContext(getConfiguration(), candidateSteps,248 configuredEmbedder.embedderMonitor(), configuredEmbedder.metaFilter(), failures);249 performableTree.addStories(context, configuredEmbedder.storyManager().storiesOfPaths(storyPaths));250 return performableTree;251 }252 private void addSuite(List<Description> storyDescriptions, String name) {253 storyDescriptions.add(Description.createTestDescription(Object.class,254 name));255 }256 private boolean metaFiltersAreDefined() {257 String metaFilters = getMetafilterSetting();258 return !StringUtils.isEmpty(metaFilters);259 }260 private String getMetafilterSetting() {261 Optional<String> environmentMetafilters = getEnvironmentMetafilters();...

Full Screen

Full Screen

getConfiguration

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.jbehave.runners.SerenityReportingRunner2import net.thucydides.core.ThucydidesSystemProperty3import net.thucydides.core.reports.html.HtmlAggregateStoryReporter4import net.thucydides.core.reports.html.HtmlAggregateStoryReporter.HtmlAggregateStoryReporterBuilder5import org.jbehave.core.configuration.Configuration6import org.jbehave.core.configuration.MostUsefulConfiguration7import org.jbehave.core.embedder.Embedder8import org.jbehave.core.io.LoadFromClasspath9import org.jbehave.core.io.StoryFinder10import org.jbehave.core.junit.JUnitStory11import org.jbehave.core.junit.JUnitStoryReporter12import org.jbehave.core.model.ExamplesTableFactory13import org.jbehave.core.reporters.Format14import org.jbehave.core.reporters.StoryReporterBuilder15import org.jbehave.core.steps.CandidateSteps16import org.jbehave.core.steps.InstanceStepsFactory17import org.jbehave.core.steps.ParameterConverters18import org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter19import java.util.List20import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_REPORTS21import static net.thucydides.core.ThucydidesSystemProperty.WEBDRIVER_DRIVER22class AcceptanceTest extends JUnitStory {23 Configuration configuration() {24 Configuration configuration = new MostUsefulConfiguration()25 configuration.useStoryLoader(new LoadFromClasspath(this.class))26 configuration.useParameterConverters(new ParameterConverters().addConverters(new ExamplesTableConverter(new ExamplesTableFactory(new LoadFromClasspath(this.class)))))27 configuration.useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(this.class))28 .withDefaultFormats()29 .withFormats(Format.CONSOLE, Format.HTML, Format.XML)30 .withFailureTrace(true)31 .withFailureTraceCompression(true)32 .withCrossReference(new CrossReference())33 .withRelativeDirectory("target/serenity"))34 }35 List<CandidateSteps> candidateSteps() {36 return new InstanceStepsFactory(configuration(), new AcceptanceTestSteps()).createCandidateSteps()37 }

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