[selenium-users] Closing Browsers after last test is complete using Junit 3 [java]

155 views
Skip to first unread message

shinflak

unread,
May 20, 2010, 11:37:40 AM5/20/10
to Selenium Users
Hello,

Can anyone suggest a way to close the browser only after all the tests
are complete? Some code for how I start and reuse the same browser
for each test is listed below:

public abstract class FOOSeleniumTestBase extends SeleneseTestCase {

protected static boolean isSeleniumStarted;

static {
selenium = new JRISelenium ("localhost",
4444,"*firefox","http://foo.com");
}

public void setUp() throws Exception {
if (!isSeleniumStarted){
selenium.start();
isSeleniumStarted = true;
}//end if
}// end setUp()
...
}

I am running Junit 3 and would like to find a way to count all the
test methods that are being run in the TestSuite and then decrement
that count so that I can only stop the server in the final tear down.

Any help would greatly be appreciated.

Thanks
shinflak

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Santiago Suarez Ordoñez

unread,
May 23, 2010, 6:31:29 PM5/23/10
to seleniu...@googlegroups.com
You can move your tests to TestNG, there you have the @AfterSuite annotation that does that work for you:

Hope that helps.

Santiago Suarez Ordoñez
Clients Success Engineer
Sauce Labs Inc
http://saucelabs.com

shinflak

unread,
May 26, 2010, 1:24:03 AM5/26/10
to Selenium Users
Thanks for the advice. I was hoping to avoid moving to TestNG and
continue with Junit since that is what our development group is using
but it might be worth the effort.

Thanks Again
jd


On May 23, 5:31 pm, Santiago Suarez Ordoñez <santi...@gmail.com>
wrote:


> You can move your tests to TestNG, there you have the @AfterSuite annotation
> that does that work for you:http://testng.org/doc/documentation-main.html#annotations
>
> Hope that helps.
>
> Santiago Suarez Ordoñez
> Clients Success Engineer

> Sauce Labs Inchttp://saucelabs.com

> > selenium-user...@googlegroups.com<selenium-users%2Bunsubscribe@go oglegroups.com>

Felipe Knorr Kuhn

unread,
May 26, 2010, 1:53:03 AM5/26/10
to seleniu...@googlegroups.com
Hello, jd

I would recommend you using TestNG too.

My scenario is a bit complex and I was able to do what I needed only
with TestNG.

I'm currently using the @BeforeSuite/@AfterSuite annotations to start
Selenium RC and create a singleton instance of Firefox to use
throughout the tests.

FK

saju thomas

unread,
May 26, 2010, 3:43:14 AM5/26/10
to Selenium Users
If you want to use with junit itself, the approach i use .It works
with junit3 and junit4 for me.

@Before
public void setUp() {
selenium = new LoggingDefaultSelenium(new
HttpCommandProcessor("localhost", 4444, "*firefox",
"http://172.16.1.13:8080/"));
selenium.start();
}


@Test
public void runTests() throws Exception {
login.logintest();
employee.createEmployee();

}

@After
public void tearDown() {
selenium.stop();
}


On May 26, 10:53 am, Felipe Knorr Kuhn <fkn...@gmail.com> wrote:
> Hello, jd
>
> I would recommend you using TestNG too.
>
> My scenario is a bit complex and I was able to do what I needed only
> with TestNG.
>
> I'm currently using the @BeforeSuite/@AfterSuite annotations to start
> Selenium RC and create a singleton instance of Firefox to use
> throughout the tests.
>
> FK
>

Raja sankar

unread,
May 26, 2010, 5:12:28 AM5/26/10
to seleniu...@googlegroups.com
You can also use a try-catch-finally and call the selenium stop in the finally.
Reply all
Reply to author
Forward
0 new messages