Best Serenity jBehave code snippet using net.serenitybdd.jbehave.SerenityStories.getStoryPath
Source:SerenityStories.java  
...83    }84    @Override85    public List<String> storyPaths() {86        Set<String> storyPaths = new HashSet<>();87        List<String> pathExpressions = getStoryPathExpressions();88        StoryFinder storyFinder = new StoryFinder();89        for (String pathExpression : pathExpressions) {90            if (absolutePath(pathExpression)) {91                storyPaths.add(pathExpression);92            }93            for (URL classpathRootUrl : allClasspathRoots()) {94                storyPaths.addAll(storyFinder.findPaths(classpathRootUrl, pathExpression, ""));95            }96            storyPaths = removeDuplicatesFrom(storyPaths);97            storyPaths = pruneGivenStoriesFrom(storyPaths);98        }99        return sorted(storyPaths);100    }101    private List<String> sorted(Set<String> storyPaths) {102        List<String> sortedStories = Lists.newArrayList(storyPaths);103        Collections.sort(sortedStories);104        return sortedStories;105    }106    private Set<String> removeDuplicatesFrom(Set<String> storyPaths) {107        Set<String> trimmedPaths = new HashSet<>();108        for(String storyPath : storyPaths) {109            if (!thereExistsALongerVersionOf(storyPath, storyPaths)) {110                trimmedPaths.add(storyPath);111            }112        }113        return trimmedPaths;114    }115    private boolean thereExistsALongerVersionOf(String storyPath, Set<String> storyPaths) {116        for(String existingPath : storyPaths) {117            if ((existingPath.endsWith("/" + storyPath)) || (existingPath.endsWith("\\" + storyPath))) {118                return true;119            }120        }121        return false;122    }123    private Set<String> pruneGivenStoriesFrom(Set<String> storyPaths) {124        List<String> filteredPaths = Lists.newArrayList(storyPaths);125        for (String skippedPrecondition : skippedPreconditions()) {126            filteredPaths = removeFrom(filteredPaths)127                    .pathsNotStartingWith(skippedPrecondition)128                    .and().pathsNotStartingWith("/" + skippedPrecondition)129                    .filter();130        }131        return new HashSet<>(filteredPaths);132    }133    class FilterBuilder {134        private final List<String> paths;135        public FilterBuilder(List<String> paths) {136            this.paths = paths;137        }138        public FilterBuilder pathsNotStartingWith(String skippedPrecondition) {139            List<String> filteredPaths = new ArrayList<>();140            for (String path : paths) {141                if (!startsWith(skippedPrecondition, path)) {142                    filteredPaths.add(path);143                }144            }145            return new FilterBuilder(filteredPaths);146        }147        public FilterBuilder and() {148            return this;149        }150        public List<String> filter() {151            return ImmutableList.copyOf(paths);152        }153        private boolean startsWith(String skippedPrecondition, String path) {154            return path.toLowerCase().startsWith(skippedPrecondition.toLowerCase());155        }156    }157    private FilterBuilder removeFrom(List<String> filteredPaths) {158        return new FilterBuilder(filteredPaths);159    }160    private List<String> skippedPreconditions() {161        return DEFAULT_GIVEN_STORY_PREFIX;162    }163    private boolean absolutePath(String pathExpression) {164        return (!pathExpression.contains("*"));165    }166    private Set<URL> allClasspathRoots() {167        try {168            Set<URL> baseRoots = new HashSet<>(Collections.list(getClassLoader().getResources(".")));169            return addGradleResourceRootsTo(baseRoots);170        } catch (IOException e) {171            throw new IllegalArgumentException("Could not load the classpath roots when looking for story files", e);172        }173    }174    private Set<URL> addGradleResourceRootsTo(Set<URL> baseRoots) throws MalformedURLException {175        Set<URL> rootsWithGradleResources = new HashSet<>(baseRoots);176        for (URL baseUrl : baseRoots) {177            String gradleResourceUrl = baseUrl.toString().replace("/build/classes/", "/build/resources/");178            rootsWithGradleResources.add(new URL(gradleResourceUrl));179        }180        return rootsWithGradleResources;181    }182    /**183     * The root package on the classpath containing the JBehave stories to be run.184     */185    protected String getRootPackage() {186        return RootPackage.forPackage(getClass().getPackage());187    }188    protected List<String> getStoryPathExpressions() {189        return Lists.newArrayList(Splitter.on(';').trimResults().omitEmptyStrings().split(getStoryPath()));190    }191    /**192     * The root package on the classpath containing the JBehave stories to be run.193     */194    protected String getStoryPath() {195        return (StringUtils.isEmpty(storyFolder)) ? storyNamePattern : storyFolder + "/" + storyNamePattern;196    }197    /**198     * Define the folder on the class path where the stories should be found199     */200    public void findStoriesIn(String storyFolder) {201        this.storyFolder = storyFolder;202    }203    public void useFormats(Format... formats) {204        this.formats = Arrays.asList(formats);205    }206    public void findStoriesCalled(String storyNames) {207        Set<String> storyPathElements = new StoryPathFinder(getEnvironmentVariables(), storyNames).findAllElements();208        storyNamePattern = Joiner.on(";").join(storyPathElements);...Source:WhenRunningASelectionOfJBehaveStories.java  
...25        SerenityStories first = new SerenityStorySampleForFistLevel();26        SerenityStories second = new SerenityStorySampleForSecondLevel();27        // Then28        assertThat(first.getRootPackage(), equalTo(second.getRootPackage()));29        assertThat(first.getStoryPath(), equalTo(second.getStoryPath()));30        assertThat(first.stepsFactory().createCandidateSteps().containsAll(second.stepsFactory().createCandidateSteps()), is(true));31        assertThat(first.getStoryPath(), is("**/*.story"));32    }33    final static class StoriesInTheSubsetFolderSample extends SerenityStories {34        StoriesInTheSubsetFolderSample(EnvironmentVariables environmentVariables) {35            super(environmentVariables);36            findStoriesIn("stories/subset");37        }38    }39    @Test40    public void a_subset_of_the_stories_can_be_run_individually() {41        // Given42        SerenityStories stories = new StoriesInTheSubsetFolderSample(environmentVariables);43        // When44        run(stories);45        // Then...getStoryPath
Using AI Code Generation
1public class JBehaveStories extends SerenityStories {2    public JBehaveStories() {3        findStoriesCalled("**/*.story");4    }5    protected List<String> storyPaths() {6        return getStoryPath("**/*.story");7    }8}getStoryPath
Using AI Code Generation
1public class AcceptanceTestSuite extends SerenityStories {2    public AcceptanceTestSuite() {3        findStoriesCalled("stories/**/story.story");4        configuredEmbedder().embedderControls()5            .doGenerateViewAfterStories(true)6            .doIgnoreFailureInStories(true)7            .doIgnoreFailureInView(true)8            .useThreads(2)9            .useStoryTimeoutInSecs(60);10    }11    public List<String> storyPaths() {12        return new StoryFinder().findPaths(13            getStoryPath(),14            Arrays.asList("**/*.story"),15            Arrays.asList(""));16    }17    public String getStoryPath(){18        return "stories/";19    }20}21public class AcceptanceTestSuite extends SerenityStories {22    public AcceptanceTestSuite() {23        findStoriesCalled("stories/**/story.story");24        configuredEmbedder().embedderControls()25            .doGenerateViewAfterStories(true)26            .doIgnoreFailureInStories(true)27            .doIgnoreFailureInView(true)28            .useThreads(2)29            .useStoryTimeoutInSecs(60);30    }31    public List<String> storyPaths() {32        return new StoryFinder().findPaths(33            getStoryPath(),34            Arrays.asList("**/*.story"),35            Arrays.asList(""));36    }37    public String getStoryPath(){38        return "stories/";39    }40}getStoryPath
Using AI Code Generation
1public class MyStory extends SerenityStories {2    public MyStory() {3        findStoriesCalled("**/*.story");4    }5    protected List<String> storyPaths() {6        return new SerenityStories().getStoryPath("**/*.story");7    }8}getStoryPath
Using AI Code Generation
1public class SerenityStories extends JUnitStories {2    public List<String> storyPaths() {3        return getStoryPath("stories/*.story");4    }5}6public class SerenityStories extends JUnitStories {7    public List<String> storyPaths() {8        return getStoryPath("stories/*.story");9    }10}11public class SerenityStories extends JUnitStories {12    public List<String> storyPaths() {13        return getStoryPath("stories/*.story");14    }15}16public class SerenityStories extends JUnitStories {17    public List<String> storyPaths() {18        return getStoryPath("stories/*.story");19    }20}21public class SerenityStories extends JUnitStories {22    public List<String> storyPaths() {23        return getStoryPath("stories/*.story");24    }25}26public class SerenityStories extends JUnitStories {27    public List<String> storyPaths() {28        return getStoryPath("stories/*.story");29    }30}31public class SerenityStories extends JUnitStories {32    public List<String> storyPaths() {33        return getStoryPath("stories/*.story");34    }35}36public class SerenityStories extends JUnitStories {37    public List<String> storyPaths() {38        return getStoryPath("stories/*.story");39    }40}41public class SerenityStories extends JUnitStories {42    public List<String> storyPaths() {getStoryPath
Using AI Code Generation
1@UsingSteps(instances = {SampleSteps.class})2public class SampleStories extends SerenityStories {3    public SampleStories() {4        String storyPath = getStoryPath("sample.story");5        runSerenity().inASingleSession().withAnnotatedResultsIn("target/site/serenity")6                .withStoryPath(storyPath);7    }8}9package com.sample.steps;10import net.thucydides.core.annotations.Step;11import net.thucydides.core.steps.ScenarioSteps;12public class SampleSteps extends ScenarioSteps {13    public void step1() {14    }15    public void step2() {16    }17}18package com.sample.steps;19import net.thucydides.core.annotations.Step;20import net.thucydides.core.steps.ScenarioSteps;21public class SampleSteps extends ScenarioSteps {22    public void step1() {23    }24    public void step2() {25    }26}27package com.sample.stories;28import com.sample.steps.SampleSteps;29import net.serenitybdd.jbehave.SerenityStories;30import net.thucydides.core.annotations.Steps;31import net.thucydides.core.annotations.UsingSteps;32@UsingSteps(instances = {SampleSteps.class})33public class SampleStories extends SerenityStories {34    SampleSteps sampleSteps;35    public SampleStories() {36        runSerenity().inASingleSession().withAnnotatedResultsIn("target/site/serenity")37                .withStoryPath("sample.story");38    }39}40public class SampleStories extends SerenityStories {41    SampleSteps sampleSteps;42    public SampleStories() {43        runSerenity().inASingleSession().withAnnotatedResultsIn("target/site/serenity")44                .withStoryPath("sample.story");45    }46    public void runStory() {47        sampleSteps.step1();48        sampleSteps.step2();49    }50}getStoryPath
Using AI Code Generation
1@Narrative(text={"This is a sample narrative text"})2public class SampleNarrative extends SerenityStories {3    public SampleNarrative() {4        super();5        findStoriesCalled("**/sample.story");6    }7}8@Narrative(text={"This is a sample narrative text"})9public class SampleNarrative extends SerenityStories {10    public SampleNarrative() {11        super();12        findStoriesCalled("**/sample.story");13    }14}15@Narrative(text={"This is a sample narrative text"})16public class SampleNarrative extends SerenityStories {17    public SampleNarrative() {18        super();19        findStoriesCalled("**/sample.story");20    }21}22@Narrative(text={"This is a sample narrative text"})23public class SampleNarrative extends SerenityStories {24    public SampleNarrative() {25        super();26        findStoriesCalled("**/sample.story");27    }28}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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
