Sometime ago I had a problem with running Selenium with GroovyTestCase framework. Recently I started a new project and have spent some time looking at this again.
Short answer: user error!
Long answer:
The problem
I instantiated all my stuff like this:
class MyTestSuite extends GroovyTestCase {
WebDriver driver = new FirefoxDriver()
// ... some other global variables go here
protected void setUp() throws Exception {
super.setUp()
// ... some other code to run at the start of each test
}
protected void tearDown() throws Exception {
driver.quit()
super.tearDown()
}
void test_one() {
driver.get("some_website")
// ... more test code goes here
}
void test_two() {
driver.get("some_other_website")
// ... more test code goes here
}
}
Each time I ran any of the tests, it launched like four browser windows and ran the test in one of them.
new FirefoxDriver() launches the new browser, as it is suppose to. The framework, I guess, launched the class four times, once for each of my methods, and Groovy automatically places that code in the constructor. It then started parsing for all the work (all the test* methods).
The solution
You need to launch the browser (only once per test) from the setUp(), like so:
class MyTestSuite extends GroovyTestCase {
WebDriver driver
// ... some other global variables go here
protected void setUp() throws Exception {
super.setUp()
driver = new FirefoxDriver()
// ... some other code to run at the start of each test
}
protected void tearDown() throws Exception {
driver.quit()
super.tearDown()
}
void test_one() {
driver.get("some_website")
// ... more test code goes here
}
void test_two() {
driver.get("some_other_website")
// ... more test code goes here
}
}
HTH,













