1

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 1

3

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(...);
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Does this work, when you have @Test-methods in different java classes? They have to be, because there are so many tests.
But you have to list all the classes in @SuiteClasses anotation? No way to just include all classes in test package?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.