How to use fromPackage method of net.serenitybdd.jbehave.Finder class

Best Serenity jBehave code snippet using net.serenitybdd.jbehave.Finder.fromPackage

Source:ClassFinder.java Github

copy

Full Screen

...34 *35 * @param packageName The base package36 * @return The classes37 */38 public List<Class<?>> fromPackage(String packageName) {39 if (expectedAnnotations == null) {40 return allClassesInPackage(packageName);41 } else {42 return annotatedClassesInPackage(packageName);43 }44 }45 private List<Class<?>> allClassesInPackage(String packageName) {46 try {47 String path = packageName.replace('.', '/');48 if (packageName.isEmpty()) {49 packageName = "/";50 }51 Enumeration<URL> resources = classResourcesOn(path);52 List<URI> dirs = new ArrayList<>();...

Full Screen

Full Screen

Source:SaikuStepFactory.java Github

copy

Full Screen

...51 }*/52 return types;53 }54 /*private List<Class> getCandidateClasses() {55 List<Class<?>> allClassesUnderRootPackage = ClassFinder.loadClasses().withClassLoader(classLoader).fromPackage(rootPackage);56 List<Class> candidateClasses = Lists.newArrayList();57 for(Class<?> classUnderRootPackage : allClassesUnderRootPackage) {58 if (hasAnnotatedMethods(classUnderRootPackage)) {59 candidateClasses.add(classUnderRootPackage);60 }61 }62 return candidateClasses;63 }*/64 private Converter<CandidateSteps, CandidateSteps> toThucydidesCandidateSteps() {65 return new Converter<CandidateSteps, CandidateSteps>() {66 public CandidateSteps convert(CandidateSteps candidateSteps) {67 return new SerenityCandidateSteps(candidateSteps);68 }69 };...

Full Screen

Full Screen

Source:WhenLoadingClassesFromAPackage.java Github

copy

Full Screen

...11import static org.hamcrest.core.IsNot.not;12public class WhenLoadingClassesFromAPackage {13 @Test14 public void shouldLoadAllClassesInAPackage() {15 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("net.serenitybdd.jbehave.pages");16 assertThat(classes.size(), is(1));17 assertThat(classes.get(0).getName(), is("net.serenitybdd.jbehave.pages.StaticSitePage"));18 }19 @Test20 public void shouldNotCrashForARootPackage() {21 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("net");22 assertThat(classes.size(), not(0));23 }24 @Test25 public void shouldLoadAllClassesInNestedPackages() {26 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("net.serenitybdd.jbehave");27 assertThat(classes.size(), greaterThan(10));28 }29 @Test30 public void shouldLoadAllAnnotatedClassesInNestedPackages() {31 List<Class<?>> classes = ClassFinder.loadClasses().annotatedWith(Given.class).fromPackage("net.serenitybdd.jbehave");32 assertThat(classes.size(), greaterThan(10));33 }34 @Test35 public void shouldLoadNoClassesIfThePackageDoesNotExist() {36 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("that.does.not.exist");37 assertThat(classes.size(), is(0));38 }39 @Test40 public void shouldNotLoadResourcesOnClasspath() {41 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("stories");42 assertThat(classes.size(), is(0));43 }44 @Test45 public void shouldLoadClassesFromDependencies() {46 List<Class<?>> classes = ClassFinder.loadClasses().annotatedWith(Ignore.class).fromPackage("net.thucydides.jbehave");47 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());48 assertThat(classnames, hasItem("net.thucydides.jbehave.SomeBoilerplateSteps"));49 }50 @Test51 public void shouldLoadAllClassesInAGivenPackageFromAnotherModuleAndAllSubpackages() {52 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("net.thucydides.jbehave");53 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());54 assertThat(classnames, hasItem("net.thucydides.jbehave.SomeBoilerplateSteps"));55 }56 // enable testing from an IDE, where otherwise the classpath is setup to depend directly on .class files, without packaging to .jar57 @Test58 public void shouldLoadClassesInAGivenPackageFromADependencyJar() {59 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("org.junit.runners");60 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());61 assertThat(classnames, hasItem("org.junit.runners.JUnit4"));62 }63 // enable testing from an IDE, where otherwise the classpath is setup to depend directly on .class files, without packaging to .jar64 @Test65 public void shouldLoadNestedClassesInAGivenPackageFromADependencyJar() {66 List<Class<?>> classes = ClassFinder.loadClasses().fromPackage("org.junit.runners");67 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());68 assertThat(classnames, hasItem("org.junit.runners.model.RunnerScheduler"));69 }70 // enable testing from an IDE, where otherwise the classpath is setup to depend directly on .class files, without packaging to .jar71 @Test72 public void shouldLoadAnnotatedClassesInAGivenPackageFromADependencyJar() {73 List<Class<?>> classes = net.thucydides.core.reflection.ClassFinder.loadClasses()74 .annotatedWith(Deprecated.class)75 .fromPackage("junit.framework");76 List<String> classnames = classes.stream().map(Class::getName).collect(Collectors.toList());77 assertThat(classnames, hasItem("junit.framework.Assert"));78 }79}...

Full Screen

Full Screen

Source:SerenityStepFactory.java Github

copy

Full Screen

...16 protected List<Class> getCandidateClasses() {17 List<Class<?>> allClassesUnderRootPackage = new ArrayList<>();18 ClassFinder classFinder = ClassFinder.loadClasses().withClassLoader(classLoader);19 for (String packageName: this.rootPackages) {20 allClassesUnderRootPackage.addAll(classFinder.fromPackage(packageName));21 }22 List<Class> candidateClasses = Lists.newArrayList();23 for(Class<?> classUnderRootPackage : allClassesUnderRootPackage) {24 if (hasAnnotatedMethods(classUnderRootPackage)) {25 candidateClasses.add(classUnderRootPackage);26 }27 }28 return candidateClasses;29 }30 public static SerenityStepFactory withStepsFromPackage(List<String> rootPackages, Configuration configuration) {31 return new SerenityStepFactory(configuration, rootPackages, defaultClassLoader());32 }33 private static ClassLoader defaultClassLoader() {34 return Thread.currentThread().getContextClassLoader();...

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