I'm trying to create Selenium tests to my Java application, but each test spends about 5 seconds to execute. The most time consuming part of the test is to initialize the Selenium.

I'm initialize the web driver @before each test and kill the driver @after test.

Is there any way to start the webdriver and "restart it" every test? Or should I start it and run all tests and then finishes him off? How do I can reduce the time of tests?

I'm using selenium 2, maven and Junit 4.

So I am starting and finishing the tests

public  void setUpBeforeClass() throws Exception {
    driver = new ChromeDriver();

public  void tearDownAfterClass() throws Exception {

Thanks advance.

  • 1
    It might help for you to elaborate on what you mean by "initialize Selenium". For example, do you start a new browser for every test?
    – user246
    Oct 21, 2013 at 13:17
  • yes, I start a new browser for every test.
    – Xosler
    Oct 21, 2013 at 13:38
  • how should be the structure for the tests? should have a webDriverPool that provides the driver? I know a little Selenium, but I have problems with the structure of the tests
    – Xosler
    Oct 21, 2013 at 13:54

2 Answers 2


Some people may prefer to use a new Driver instance for every test in order to avoid one test's side-effects from impacting another test. I have never run into that problem. For efficiency reasons, I try to re-use a single Driver for all tests in a suite.


Agree with User246 and here is an example of how to do:

protected WebDriver getWebDriver() {

  if (driver == null) {
   driver = new InternetExplorerDriver();
  return driver;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.