What's a static class?
> instantiating the browser and then my step definitions using this class to
> get a reference to the driver.
> Seems ugly and wanted to know if there was a better way to achieve this?
I would recommend dependency injection. See
https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-webbit-websockets-selenium
I just modified it a little to do what you're asking for:
https://github.com/cucumber/cucumber-jvm/commit/ed160d3070bcced399457cd171cfc59ce991f466
HTH,
Aslak
> Thanks
> Rakesh
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to
> cukes+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cukes?hl=en.
>
On Apr 16, 2012 2:51 PM, "Rakesh" <rakesh.m...@gmail.com> wrote:
>
> Hi,
>
> I wanted to resurrect this thread because I am not sure its still valid. Some threads recently have just confused me even more about state between tests.
>
> I have cucumber-jvm running with picocontainer wiring up my step defs before each scenario and thats fine.
>
> However, I need to talk to the database to clean up and insert test data too. Problem is instantiating a connection to the database takes time and I'd rather set up a pool once and then have the stepdefs ask for a connection.
>
> How can I achieve this?
Create a connection pool class that manages/pools/caches the connections in the way you want, and then inject an instance of that into your stepdefs instead of directly injecting a database or connection object.
Cheers,
--Aaron V.
Not knowing your specific case, I'd imagine it'd go something like this:
Make a ConnectionPool class...
public class ConnectionPool {
private Connection conn;
public Connection getConnection() {
if (conn == null) {
conn = /* create the connection however you want */;
}
return conn;
}
}
Then inject it in your stepdefs w/ PicoContainer...
public class MyStepdefs {
private final ConnectionPool pool;
public MyStepdefs(ConnectionPool pool) {
this.pool = pool;
}
//... steps that use pool.getConnection() to get a connection ...
}
--
--Aaron V.
[ http://github.com/avh4 ]