Hi Robert,
We are using the Groovy binding for cuke4duke, but we suffered from
the same problem whereby the tests take much longer to run than they
should due to the browser opening and closing for each scenario.
Our first attempt to speed this up was to only create the driver if it
didn't already exist
Before {
if (!browser) {
browser = new FirefoxDriver();
}
}
Where the browser was stored in the Groovy script binding, this didn't
work though as a new script binding was created for each scenario.
After reading about Geb (
http://geb.codehaus.org) we discovered it
caches an instance of the driver automatically, so repeated calls to
new Browser() actually result in the same underlying browser, e.g.
Before {
browser = new Browser() // Browser is the Geb Browser object which
wraps a raw WebDriver instance
}
Geb is a Groovy API, so I don't think it would work too well if you
are writing your step definitions in Java, but looking into its source
code it think it uses thread local to store the driver instance so
it's available across different scenarios.
To ensure our scenarios are independent we clear the cookies after
each scenario:
After {
browser.clearCookies()
}
Not quite the answer you were looking for I'm sure but hopefully it
helps.
By the way I'll be talking at the Agile Testing UK usergroup at
SkillsMatter on the evening of the 26th Jan about Cucumber with Groovy
etc if you are interested/in the same country
http://agiletesting.org.uk/january_2011.php
Cheers,
Richard