I have dozens of Selenium Webdriver tests. I want to run them all at once. How do I run the test so that each test does not open a new Webdriver browser window?
1 Answer
You have to initiate/teardown your webdriver in a @BeforeClass/@AfterClass, and use this webdriver in all your test.
public class MyTest {
WebDriver driver;
@BeforeClass
public static void setUpClass() {
driver = new RemoteWebDriver(new URL(hubAddress), capability);
}
@AfterClass
public static void setDownClass() {
driver.quit();
}
@Test
public void Test1(){
driver.get(...);
}
@Test
public void Test2(){
driver.get(...):
}
}
Or make it static in an TestSuite, with the same @BeforeClass/@AfterClass :
@RunWith(Suite.class)
@SuiteClasses({ Test1.class, Test2.class})
public class MyTestSuite {
public static WebDriver driver;
@BeforeClass
public static void setUpClass() {
driver = new RemoteWebDriver(new URL(hubAddress), capability);
}
@AfterClass
public static void setDownClass() {
driver.quit();
}
}
and
public class Test1 {
@Test
public void Test1(){
MyTestSuite.driver.get(...);
}
}