How to use getRootPackage method of net.serenitybdd.jbehave.SerenityStories class

Best Serenity jBehave code snippet using net.serenitybdd.jbehave.SerenityStories.getRootPackage

Source:SerenityStories.java Github

copy

Full Screen

...70 return configuration;71 }72 @Override73 public InjectableStepsFactory stepsFactory() {74 return SerenityStepFactory.withStepsFromPackage(getRootPackage(), configuration()).andClassLoader(getClassLoader());75 }76 /**77 * The class loader used to obtain the JBehave and Step implementation classes.78 * You normally don't need to worry about this, but you may need to override it if your application79 * is doing funny business with the class loaders.80 */81 public ClassLoader getClassLoader() {82 return Thread.currentThread().getContextClassLoader();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 */...

Full Screen

Full Screen

Source:WhenRunningASelectionOfJBehaveStories.java Github

copy

Full Screen

...24 // Given25 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);...

Full Screen

Full Screen

Source:ExtendedSerenityStories.java Github

copy

Full Screen

...22public class ExtendedSerenityStories extends SerenityStories {23 @Override24 public InjectableStepsFactory stepsFactory() {25 return new ExtendedSerenityStepsFactory(configuration(),26 getRootPackage(),27 getClassLoader());28 }29 @Override30 protected String getRootPackage() {31 return "org.activiti.cloud.acc";32 }33}...

Full Screen

Full Screen

getRootPackage

Using AI Code Generation

copy

Full Screen

1package net.serenitybdd.jbehave;2import java.io.File;3import java.io.IOException;4import java.util.List;5import org.jbehave.core.configuration.Configuration;6import org.jbehave.core.configuration.Keywords;7import org.jbehave.core.io.StoryFinder;8import org.jbehave.core.junit.JUnitStory;9public class SerenityStories extends JUnitStory {10 private final String rootPackage;11 public SerenityStories() {12 this.rootPackage = getRootPackage();13 }14 public SerenityStories(String rootPackage) {15 this.rootPackage = rootPackage;16 }17 public Configuration configuration() {18 return new SerenityStoryReporterBuilder().withKeywords(keywords())19 .withFailureTrace(true).withFailureTraceCompression(true)20 .withDefaultFormats().build();21 }22 public List<String> storyPaths() {23 try {24 return new StoryFinder().findPaths(25 codeLocationFromPath(rootPackage), "**/*.story",26 "");27 } catch (IOException e) {28 throw new RuntimeException(e);29 }30 }31 public String getRootPackage() {32 String rootPackage = this.getClass().getPackage().getName();33 File rootPackageDirectory = codeLocationFromPath(rootPackage);34 if (rootPackageDirectory.isDirectory()) {35 return rootPackage;36 } else {37 return rootPackage.replace(rootPackage.substring(rootPackage38 .lastIndexOf(".") + 1), "");39 }40 }41 protected Keywords keywords() {42 return new SerenityStoryReporterBuilder().keywords();43 }44 protected File codeLocationFromPath(String path) {45 return new File(path.replace(".", File.separator));46 }47}

Full Screen

Full Screen

getRootPackage

Using AI Code Generation

copy

Full Screen

1public class AcceptanceTestSuite extends SerenityStories {2 public AcceptanceTestSuite() {3 runSerenity().inASingleSession();4 findStoriesCalled("stories/**/*.story");5 }6 public InjectableStepsFactory stepsFactory() {7 Configuration configuration = configuration();8 return new InstanceStepsFactory(configuration, new AcceptanceTestSuiteSteps());9 }10 protected List<String> storyPaths() {11 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");12 }13 public WebDriver getDriver() {14 return super.getDriver();15 }16 public void run() {17 super.run();18 }19 public List<String> storyPaths() {20 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()).getFile(), "**/*.story", "");21 }22 protected List<String> storyPaths() {23 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()).getFile(), "**/*.story", "");24 }25 public void run() {26 super.run();27 }28}29public class AcceptanceTestSuite extends SerenityStories {30 public AcceptanceTestSuite() {31 findStoriesCalled("stories/**/*.story");32 }33 public InjectableStepsFactory stepsFactory() {34 Configuration configuration = configuration();35 return new InstanceStepsFactory(configuration, new AcceptanceTestSuiteSteps());36 }37 protected List<String> storyPaths() {38 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");39 }40 public WebDriver getDriver() {41 return super.getDriver();42 }43 public void run() {44 super.run();45 }46 public List<String> storyPaths() {47 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()).getFile(), "**/*.story", "");48 }49 protected List<String> storyPaths() {50 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()).getFile(), "**/*.story", "");51 }

Full Screen

Full Screen

getRootPackage

Using AI Code Generation

copy

Full Screen

1package com.serenity.jbehave.test;2import net.serenitybdd.jbehave.SerenityStories;3public class SerenityStoryRunner extends SerenityStories {4 public SerenityStoryRunner() {5 findStoriesCalled("**/*.story");6 }7 protected String getRootPackage() {8 return "com.serenity.jbehave.test";9 }10}11package com.serenity.jbehave.test;12import org.junit.runner.RunWith;13import net.serenitybdd.jbehave.SerenityStories;14@RunWith(SerenityStoryRunner.class)15public class SerenityStoryRunner extends SerenityStories {16 public SerenityStoryRunner() {17 findStoriesCalled("**/*.story");18 }19 protected String getRootPackage() {20 return "com.serenity.jbehave.test";21 }22}23package com.serenity.jbehave.test;24import org.junit.runner.RunWith;25import net.serenitybdd.jbehave.SerenityStories;26@RunWith(SerenityStoryRunner.class)27public class SerenityStoryRunner extends SerenityStories {28 public SerenityStoryRunner() {29 findStoriesCalled("stories/*.story");30 }31 protected String getRootPackage() {32 return "com.serenity.jbehave.test";33 }34}

Full Screen

Full Screen

getRootPackage

Using AI Code Generation

copy

Full Screen

1 def serenityStories = new SerenityStories()2 def rootPackage = serenityStories.getRootPackage()3 def rootPackagePath = rootPackage.replace('.', '/')4 def storyFiles = fileTree(storyPath).include('**/*.story')5 def featureFiles = fileTree(featurePath).include('**/*.feature')6 def storyFilesList = storyFiles.collect { it.name }7 def featureFilesList = featureFiles.collect { it.name }8 if (storiesWithoutFeatures.size() > 0 || featuresWithoutStories.size() > 0) {9 throw new GradleException("Story files without feature file or feature files without story file")10 }11}12task checkStories {13 doLast {14 checkStories()15 }16}

Full Screen

Full Screen

getRootPackage

Using AI Code Generation

copy

Full Screen

1package com.serenitybdd.jbehave.steps;2import net.thucydides.core.annotations.Steps;3import net.thucydides.core.steps.ScenarioSteps;4import com.serenitybdd.jbehave.steps.serenity.EndUserSteps;5public class EndUserSteps extends ScenarioSteps {6 EndUserSteps endUser;7 public void is_the_home_page() {8 endUser.is_the_home_page();9 }10 public void looks_for(String keyword) {11 endUser.looks_for(keyword);12 }13 public void should_see_definition(String definition) {14 endUser.should_see_definition(definition);15 }16}17package com.serenitybdd.jbehave.steps.serenity;18import net.thucydides.core.annotations.Step;19import net.thucydides.core.steps.ScenarioSteps;20import org.openqa.selenium.WebDriver;21import com.serenitybdd.jbehave.pages.DictionaryPage;22public class EndUserSteps extends ScenarioSteps {23 DictionaryPage dictionaryPage;24 public void is_the_home_page() {25 dictionaryPage.open();26 }27 public void looks_for(String keyword) {28 enters(keyword);29 starts_search();30 }31 public void enters(String keyword) {32 dictionaryPage.enter_keywords(keyword);33 }34 public void starts_search() {35 dictionaryPage.lookup_terms();36 }37 public void should_see_definition(String definition) {38 dictionaryPage.should_see_definition(definition);39 }40 public WebDriver getDriver() {41 return getDriver();42 }43}44package com.serenitybdd.jbehave.pages;45import net.thucydides.core.annotations.DefaultUrl;46import net.thucydides.core.pages.PageObject;47import org.openqa.selenium.WebDriver;48public class DictionaryPage extends PageObject {49 public DictionaryPage(WebDriver driver) {50 super(driver);51 }52 public void enter_keywords(String keyword) {53 $("#searchInput").type(keyword);54 }

Full Screen

Full Screen

getRootPackage

Using AI Code Generation

copy

Full Screen

1package net.serenitybdd.jbehave;2import java.util.List;3import org.jbehave.core.configuration.Configuration;4import org.jbehave.core.configuration.MostUsefulConfiguration;5import org.jbehave.core.configuration.spring.SpringStoryControls;6import org.jbehave.core.embedder.Embedder;7import org.jbehave.core.embedder.MetaFilter;8import org.jbehave.core.embedder.MetaFilter.MetaBy;9import org.jbehave.core.embedder.MetaMatcher;10import org.jbehave.core.embedder.MetaMatcher.NameMatcher;11import org.jbehave.core.embedder.MetaMatcher.NotMatcher;12import org.jbehave.core.embedder.MetaMatcher.NotNameMatcher;13import org.jbehave.core.embedder.MetaMatcher.StartingMatcher;14import org.jbehave.core.embedder.MetaMatcher.StartingNameMatcher;15import org.jbehave.core.embedder.StoryControls;16import org.jbehave.core.embedder.StoryManager;17import org.jbehave.core.embedder.StoryRunner;18import org.jbehave.core.io.CodeLocations;19import org.jbehave.core.io.LoadFromClasspath;20import org.jbehave.core.io.LoadFromRelativeFile;21import org.jbehave.core.io.LoadFromURL;22import org.jbehave.core.io.StoryFinder;23import org.jbehave.core.io.UnderscoredCamelCaseResolver;24import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner;25import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.ConfigurableEmbedder;26import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.ConfigurableEmbedderBuilder;27import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.SerenityStoryPathResolver;28import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.SerenityStoryPathResolver.StoryPathResolver;29import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner.SerenityStoryPathResolver.StoryPathResolver.StoryPathResolverBuilder;30import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner

Full Screen

Full Screen

getRootPackage

Using AI Code Generation

copy

Full Screen

1package net.serenitybdd.jbehave;2import org.jbehave.core.configuration.Configuration;3import org.jbehave.core.configuration.Keywords;4import org.jbehave.core.configuration.MostUsefulConfiguration;5import org.jbehave.core.io.StoryFinder;6import org.jbehave.core.junit.JUnitStory;7import org.jbehave.core.junit.JUnitStoryReporter;8import org.jbehave.core.model.Story;9import org.jbehave.core.reporters.StoryReporterBuilder;10import org.jbehave.core.steps.InjectableStepsFactory;11import org.jbehave.core.steps.InstanceStepsFactory;12import org.junit.runner.RunWith;13import java.util.List;14import java.util.Properties;15import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;16import static org.jbehave.core.reporters.Format.*;17@RunWith(SerenityRunner.class)18public class SerenityStories extends JUnitStory {19 public SerenityStories() {20 configuredEmbedder().embedderControls().doGenerateViewAfterStories(true).doIgnoreFailureInStories(false).doIgnoreFailureInView(false).doVerboseFailures(true).useThreads(1).useStoryTimeoutInSecs(60);21 }22 public Configuration configuration() {23 Properties viewResources = new Properties();24 viewResources.put("decorateNonHtml", "true");25 Class<? extends SerenityStories> embeddableClass = this.getClass();26 Keywords keywords = new SerenityKeywords();27 return new MostUsefulConfiguration()28 .useKeywords(keywords)29 .useStoryLoader(new SerenityStoryLoader(codeLocationFromClass(embeddableClass)))30 .useStoryReporterBuilder(new StoryReporterBuilder()31 .withCodeLocation(codeLocationFromClass(embeddableClass))32 .withFailureTrace(true)33 .withFailureTraceCompression(true)34 .withKeywords(keywords)35 .withDefaultFormats()36 .withViewResources(viewResources)37 .withFormats(CONSOLE, TXT, HTML, XML, STATS));38 }39 public InjectableStepsFactory stepsFactory() {40 return new InstanceStepsFactory(configuration(), new SerenityStepFactory().createCandidateSteps());41 }42 public List<Story> candidateStories() {43 return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful