views:

51

answers:

2

Hi all;

Such a junit :

@Test public void testA {...}

@Test pulic void testB {...}

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

Here is the question : closeBrowsers() method called after every test method; in that case it is called twice and i got "Wrong test finished." from JUnit. I need a junit method/annotation which will be called after all tests finised (just called once after all tests finished), is it possible ?

Also i tried to check if selenium is up or not in closeBrowsers() but no way i couldn't find any solution.

P.S : I 've read this one : http://stackoverflow.com/questions/1317844/how-to-close-a-browser-on-a-selenium-rc-server-which-lost-its-client

but i couldn't understand the solution and also currently http://www.santiycr.com.ar/djangosite/blog/posts/2009/aug/25/close-remaining-browsers-from-selenium-rc blog side is down

+2  A: 

Use the @AfterClass annotation.

http://junit.sourceforge.net/doc/faq/faq.htm#organize_3

Reflux
+2  A: 

You can make your selenium variable static, initialize it in @BeforeClass static method and cleanup in @AfterClass:

public class ...... {

  private static Selenium selenium;

  @BeforeClass
  public static void initSelenium() {
     selenium = new DefaultSelenium(...); // or initialize it in any other way
  }

  @Test
  public void testA {...}

  @Test
  pulic void testB {...}

  @AfterClass
  public static void closeBrowsers() throws Exception { 
    selenium.stop(); 
  }
}
ZloiAdun
Thanks.........
Altug