How to use findStory method of net.serenitybdd.jbehave.embedders.ExtendedEmbedder class

Best Serenity jBehave code snippet using net.serenitybdd.jbehave.embedders.ExtendedEmbedder.findStory

Run Serenity jBehave automation tests on LambdaTest cloud grid

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

copy
1package net.serenitybdd.jbehave.embedders.monitors;
2
3import net.serenitybdd.core.di.WebDriverInjectors;
4import net.serenitybdd.jbehave.SerenityReporter;
5import net.serenitybdd.jbehave.embedders.ExtendedEmbedder;
6import net.thucydides.core.guice.Injectors;
7import net.thucydides.core.util.EnvironmentVariables;
8import net.thucydides.core.webdriver.DriverConfiguration;
9import org.jbehave.core.embedder.EmbedderControls;
10import org.jbehave.core.embedder.EmbedderMonitor;
11import org.jbehave.core.embedder.MetaFilter;
12import org.jbehave.core.failures.BatchFailures;
13import org.jbehave.core.model.*;
14import org.jbehave.core.reporters.ReportsCount;
15import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
18import java.io.File;
19import java.util.Collections;
20import java.util.List;
21import java.util.Properties;
22import java.util.Set;
23import java.util.concurrent.ConcurrentHashMap;
24import java.util.concurrent.ExecutorService;
25
26/**
27 * User: YamStranger
28 * Date: 3/25/16
29 * Time: 6:35 PM
30 */
31public class ReportingEmbedderMonitor implements EmbedderMonitor {
32    private static final Logger logger = LoggerFactory.getLogger(ReportingEmbedderMonitor.class);
33    private SerenityReporter reporter;
34    private ExtendedEmbedder embedder;
35    private final DriverConfiguration configuration;
36    private final Set<String> processedStories=Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
37
38
39    public ReportingEmbedderMonitor(final ExtendedEmbedder embedder) {
40        this(configuration(), embedder);
41    }
42
43    public ReportingEmbedderMonitor(final DriverConfiguration configuration,
44                                    final ExtendedEmbedder embedder) {
45        this.configuration = configuration;
46        this.embedder = embedder;
47    }
48
49
50    @Override
51    public void runningEmbeddable(String name) {
52    }
53
54    @Override
55    public void embeddableFailed(String name, Throwable cause) {
56    }
57
58    @Override
59    public void embeddableNotConfigurable(String name) {
60    }
61
62    @Override
63    public void embeddablesSkipped(List<String> classNames) {
64    }
65
66    @Override
67    public void metaNotAllowed(Meta meta, MetaFilter filter) {
68    }
69
70    @Override
71    public void storyFailed(String path, Throwable cause) {
72    }
73
74    @Override
75    public void storiesSkipped(List<String> storyPaths) {
76    }
77
78    @Override
79    public void scenarioNotAllowed(Scenario scenario, MetaFilter filter) {
80    }
81
82    @Override
83    public void batchFailed(BatchFailures failures) {
84    }
85
86    @Override
87    public void beforeOrAfterStoriesFailed() {
88    }
89
90    @Override
91    public void generatingReportsView(File outputDirectory, List<String> formats, Properties viewProperties) {
92    }
93
94    @Override
95    public void reportsViewGenerationFailed(File outputDirectory, List<String> formats, Properties viewProperties, Throwable cause) {
96    }
97
98    @Override
99    public void reportsViewGenerated(ReportsCount count) {
100    }
101
102    @Override
103    public void reportsViewFailures(ReportsCount count) {
104    }
105
106    @Override
107    public void reportsViewNotGenerated() {
108    }
109
110    @Override
111    public void runningWithAnnotatedEmbedderRunner(String className) {
112    }
113
114    @Override
115    public void annotatedInstanceNotOfType(Object annotatedInstance, Class<?> type) {
116    }
117
118    @Override
119    public void mappingStory(String storyPath, List<String> metaFilters) {
120    }
121
122    @Override
123    public void generatingMapsView(File outputDirectory, StoryMaps storyMaps, Properties viewProperties) {
124    }
125
126    @Override
127    public void mapsViewGenerationFailed(File outputDirectory, StoryMaps storyMaps, Properties viewProperties, Throwable cause) {
128    }
129
130    @Override
131    public void generatingNavigatorView(File outputDirectory, Properties viewResources) {
132    }
133
134    @Override
135    public void navigatorViewGenerationFailed(File outputDirectory, Properties viewResources, Throwable cause) {
136    }
137
138    @Override
139    public void navigatorViewNotGenerated() {
140    }
141
142    @Override
143    public void processingSystemProperties(Properties properties) {
144    }
145
146    @Override
147    public void systemPropertySet(String name, String value) {
148    }
149
150    @Override
151    public void storyTimeout(Story story, StoryDuration storyDuration) {
152    }
153
154    @Override
155    public void usingThreads(int threads) {
156    }
157
158    @Override
159    public void usingExecutorService(ExecutorService executorService) {
160    }
161
162    @Override
163    public void usingControls(EmbedderControls embedderControls) {
164    }
165
166    @Override
167    public void invalidTimeoutFormat(String path) {
168    }
169
170    @Override
171    public void usingTimeout(String path, long timeout) {
172    }
173
174    @Override
175    public void runningStory(String path) {
176        logger.info("{}story running with path {}", this.hashCode(), path);
177        final Story story = embedder.findStory(path);
178        if (story == null) {
179            logger.error("can not find any story by path {}", path);
180        } else {
181            includeInReportSkippedAndIgnoredAndWip(story);
182        }
183    }
184
185
186    @Override
187    public void storiesNotAllowed(List<Story> notAllowed, MetaFilter filter) {
188        logger.debug("processing stories Not Allowed {}", notAllowed);
189        for (final Story story : notAllowed) {
190            includeInReportSkippedAndIgnoredAndWip(story);
191        }
192    }
193
194    @Override
195    public void storiesNotAllowed(List<Story> notAllowed, MetaFilter filter, boolean verbose) {
196        logger.debug("processing stories Not Allowed {}", notAllowed);
197        for (final Story story : notAllowed) {
198            includeInReportSkippedAndIgnoredAndWip(story);
199        }
200    }
201
202    private void includeInReportSkippedAndIgnoredAndWip(final Story story) {
203        final SerenityReporter reporter = reporter();
204        this.processedStories.addAll(
205                reporter.processExcludedByFilter(story, this.processedStories)
206        );
207    }
208
209    public synchronized SerenityReporter reporter() {
210        if (this.reporter == null) {
211            this.reporter = new SerenityReporter(this.configuration);
212        }
213        return reporter;
214    }
215
216
217    private static DriverConfiguration configuration() {
218        DriverConfiguration<DriverConfiguration> configuration =
219                WebDriverInjectors.getInjector().getInstance(DriverConfiguration.class);
220        EnvironmentVariables variables =
221                Injectors.getInjector().getProvider(EnvironmentVariables.class).get().copy();
222        if (variables != null) {
223            configuration = configuration.withEnvironmentVariables(variables);
224        }
225        return configuration;
226    }
227}
228
Full Screen
copy
1package net.serenitybdd.jbehave.embedders;
2
3import net.serenitybdd.jbehave.embedders.monitors.CompositeEmbedderMonitor;
4import org.jbehave.core.configuration.Configuration;
5import org.jbehave.core.embedder.*;
6import org.jbehave.core.model.Story;
7import org.jbehave.core.steps.CandidateSteps;
8import org.jbehave.core.steps.InjectableStepsFactory;
9
10import java.io.File;
11import java.util.List;
12import java.util.Map;
13import java.util.Properties;
14import java.util.concurrent.ConcurrentHashMap;
15import java.util.concurrent.ExecutorService;
16
17/**
18 * User: YamStranger
19 * Date: 3/25/16
20 * Time: 12:02 AM
21 */
22public class ExtendedEmbedder extends Embedder {
23    final Embedder embedder;
24    final Map<String, Story> stories = new ConcurrentHashMap<>();
25
26    public ExtendedEmbedder(Embedder embedder) {
27        this.embedder = embedder;
28        this.embedder.useEmbedderMonitor(new CompositeEmbedderMonitor(
29            embedder.embedderMonitor()!=null?embedder.embedderMonitor():embedderMonitor));
30    }
31
32    public CompositeEmbedderMonitor getEmbedderMonitor() {
33        return (CompositeEmbedderMonitor) this.embedder.embedderMonitor();
34    }
35
36    public void registerStory(final String path, final Story story) {
37        this.stories.put(path, story);
38    }
39
40    public Story findStory(final String path){
41        return this.stories.get(path);
42    }
43
44    @Override
45    public void mapStoriesAsPaths(List<String> storyPaths) {
46        embedder.mapStoriesAsPaths(storyPaths);
47    }
48
49    @Override
50    public void runAsEmbeddables(List<String> classNames) {
51        embedder.runAsEmbeddables(classNames);
52    }
53
54    @Override
55    public void runStoriesWithAnnotatedEmbedderRunner(List<String> classNames) {
56        embedder.runStoriesWithAnnotatedEmbedderRunner(classNames);
57    }
58
59    @Override
60    public void runStoriesAsPaths(List<String> storyPaths) {
61        embedder.runStoriesAsPaths(storyPaths);
62    }
63
64    @Override
65    public void generateReportsView() {
66        embedder.generateReportsView();
67    }
68
69    @Override
70    public void generateReportsView(File outputDirectory, List<String> formats, Properties viewResources) {
71        embedder.generateReportsView(outputDirectory, formats, viewResources);
72    }
73
74    @Override
75    public void generateCrossReference() {
76        embedder.generateCrossReference();
77    }
78
79    @Override
80    public void reportStepdocs() {
81        embedder.reportStepdocs();
82    }
83
84    @Override
85    public void reportStepdocsAsEmbeddables(List<String> classNames) {
86        embedder.reportStepdocsAsEmbeddables(classNames);
87    }
88
89    @Override
90    public void reportStepdocs(Configuration configuration, List<CandidateSteps> candidateSteps) {
91        embedder.reportStepdocs(configuration, candidateSteps);
92    }
93
94    @Override
95    public void reportMatchingStepdocs(String stepAsString) {
96        embedder.reportMatchingStepdocs(stepAsString);
97    }
98
99    @Override
100    public void processSystemProperties() {
101        embedder.processSystemProperties();
102    }
103
104    @Override
105    public EmbedderClassLoader classLoader() {
106        return embedder.classLoader();
107    }
108
109    @Override
110    public Configuration configuration() {
111        return embedder.configuration();
112    }
113
114    @Override
115    public List<CandidateSteps> candidateSteps() {
116        return embedder.candidateSteps();
117    }
118
119    @Override
120    public InjectableStepsFactory stepsFactory() {
121        return embedder.stepsFactory();
122    }
123
124    @Override
125    public EmbedderControls embedderControls() {
126        return embedder.embedderControls();
127    }
128
129    @Override
130    public EmbedderMonitor embedderMonitor() {
131        return embedder.embedderMonitor();
132    }
133
134    @Override
135    public EmbedderFailureStrategy embedderFailureStrategy() {
136        return embedder.embedderFailureStrategy();
137    }
138
139    @Override
140    public boolean hasExecutorService() {
141        return embedder.hasExecutorService();
142    }
143
144    @Override
145    public ExecutorService executorService() {
146        return embedder.executorService();
147    }
148
149    @Override
150    public StoryManager storyManager() {
151        return embedder.storyManager();
152    }
153
154    @Override
155    public List<String> metaFilters() {
156        return embedder.metaFilters();
157    }
158
159    @Override
160    public Map<String, MetaFilter.MetaMatcher> metaMatchers() {
161        return embedder.metaMatchers();
162    }
163
164    @Override
165    public MetaFilter metaFilter() {
166        return embedder.metaFilter();
167    }
168
169    @Override
170    public PerformableTree performableTree() {
171        return embedder.performableTree();
172    }
173
174    @Override
175    public Properties systemProperties() {
176        return embedder.systemProperties();
177    }
178
179    @Override
180    public StoryTimeouts.TimeoutParser[] timeoutParsers() {
181        return embedder.timeoutParsers();
182    }
183
184    @Override
185    public void useClassLoader(EmbedderClassLoader classLoader) {
186        embedder.useClassLoader(classLoader);
187    }
188
189    @Override
190    public void useConfiguration(Configuration configuration) {
191        embedder.useConfiguration(configuration);
192    }
193
194    @Override
195    public void useCandidateSteps(List<CandidateSteps> candidateSteps) {
196        embedder.useCandidateSteps(candidateSteps);
197    }
198
199    @Override
200    public void useStepsFactory(InjectableStepsFactory stepsFactory) {
201        embedder.useStepsFactory(stepsFactory);
202    }
203
204    @Override
205    public void useEmbedderControls(EmbedderControls embedderControls) {
206        embedder.useEmbedderControls(embedderControls);
207    }
208
209    @Override
210    public void useEmbedderFailureStrategy(EmbedderFailureStrategy failureStategy) {
211        embedder.useEmbedderFailureStrategy(failureStategy);
212    }
213
214    @Override
215    public void useEmbedderMonitor(EmbedderMonitor embedderMonitor) {
216        embedder.useEmbedderMonitor(embedderMonitor);
217    }
218
219    @Override
220    public void useExecutorService(ExecutorService executorService) {
221        embedder.useExecutorService(executorService);
222    }
223
224    @Override
225    public void useMetaFilters(List<String> metaFilters) {
226        embedder.useMetaFilters(metaFilters);
227    }
228
229    @Override
230    public void useMetaMatchers(Map<String, MetaFilter.MetaMatcher> metaMatchers) {
231        embedder.useMetaMatchers(metaMatchers);
232    }
233
234    @Override
235    public void usePerformableTree(PerformableTree performableTree) {
236        embedder.usePerformableTree(performableTree);
237    }
238
239    @Override
240    public void useSystemProperties(Properties systemProperties) {
241        embedder.useSystemProperties(systemProperties);
242    }
243
244    @Override
245    public void useTimeoutParsers(StoryTimeouts.TimeoutParser... timeoutParsers) {
246        embedder.useTimeoutParsers(timeoutParsers);
247    }
248
249    @Override
250    public String toString() {
251        return embedder.toString();
252    }
253}
254
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
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)