PicoContainer support

323 views
Skip to first unread message

Joey Robonaut

unread,
Feb 2, 2015, 11:11:13 PM2/2/15
to thucydid...@googlegroups.com
I see the project serenity-picocontainer but it's empty.  Are there plans to incorporate support for PicoContainer?  I really like their Storing behavior for managing multithreaded dependencies, which is useful when running on Selenium Grid.

John Smart

unread,
Feb 2, 2015, 11:19:43 PM2/2/15
to Joey Robonaut, thucydid...@googlegroups.com
Not easily, or at least not with the standard Cucumber module - Cucumber only allows one dependency injection framework, and Serenity is effectively a dependency injection framework. I toyed with the idea of integrating PicoContainer as an optional module (hence the module) but I don't use it myself so didn't know the best way to go about it. If you tell me more about they way you would like to use it, I could see what I could do.

On 3 February 2015 at 15:11, Joey Robonaut <jpn...@gmail.com> wrote:
I see the project serenity-picocontainer but it's empty.  Are there plans to incorporate support for PicoContainer?  I really like their Storing behavior for managing multithreaded dependencies, which is useful when running on Selenium Grid.

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
___________________________________________________
John Smart | Wakaleo Consulting  |  +61 407 247 642
Optimizing your software development process
http://www.wakaleo.com  |  john....@wakaleo.com
___________________________________________________

The dates for the 2014 BDD workshops have been scheduled! Check out our upcoming BDD/TDD Master classes and our Advanced BDD Requirements Workshops, coming soon to Sydney and Melbourne!
___________________________________________________
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Joey Robonaut

unread,
Feb 3, 2015, 10:15:31 AM2/3/15
to thucydid...@googlegroups.com, jpn...@gmail.com
Hi John,
Below are my objectives.  I have implemented such a framework based on jBehave, but I would like to abandon it and move to Cucumber/Serenity BDD.

- run multiple .feature files concurrently and generate a single report
- each thread is given its own test session; no sharing of page objects or step def instances between threads, and instances are destroyed when thread/.feature is ended
- ability to inject container-managed dependencies into page object or step defs, some dependencies being "singleton" (shared between threads) others being "threadlocal".  This is where PicoContainer is helpful.  For example (jBehave):

/* subclass of JUnitStories */

@Override
public List<CandidateSteps> candidateSteps() {
   
return new PicoStepsFactory(configuration(), getPicoContainer())
           
.createCandidateSteps();
}

private PicoContainer getPicoContainer() {
   
// root container
   
MutablePicoContainer top = new PicoBuilder()
           
.withBehaviors(new Caching())   // Singleton behavior
           
.withConstructorInjection()
           
.build();
    top
.addComponent(ContentDAO.class);
    top
.addComponent(UserDAO.class);
   
   
// child container
   
final ClassLoadingPicoContainer child = new ClassLoadingPicoContainer(
            top
.getClass().getClassLoader(),
           
new ThreadCaching(),            // Thread-Local behavior
            top
);
    child
.addComponent(WebElementRepository.class);
   
   
// scan the classpath for step def classes
    child
.visit(rootName, ".*\\.class", true, new ClassLoadingPicoContainer.ClassVisitor() {
       
@Override
       
public void classFound(@SuppressWarnings("rawtypes") Class clazz) {
           
// concrete classes only
           
int mods = clazz.getModifiers();
           
if (Modifier.isAbstract(mods) || Modifier.isInterface(mods)) {
               
return;
           
}
           
           
// search type hierarchy to see if its a step
           
for (Class<?> cur = clazz; cur != null && cur != Object.class; cur = cur.getSuperclass()) {
               
if (cur == AbstractSteps.class) {
                    child
.addComponent(clazz);
                   
break;
               
}
           
}
       
}
   
});
   
return child;
}

/* example stepdef */
public class MySteps extends AbstractSteps {

   
private ContentDao contentDao; // singleton
   
private UserDao userDao; // singleton
   
private WebElementRepository repo; // threadlocal
 
   
public MySteps(ContentDAO contentDao, UserDAO userDao, WebElementRepository repo) {
       
this.contentDao = contentDao;
       
this.userDao = userDao;
       
this.repo = repo;
   
}

   
// ...
}

 
I see Serenity uses a simple declaration only approach with Guice under the hood.  I would be content if this were possible given the current toolsets.

PS - could you enable post editing in this group?
Reply all
Reply to author
Forward
0 new messages