Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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 '13 at 13:17
yes, I start a new browser for every test. – Xosler Oct 21 '13 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 '13 at 13:54
up vote 3 down vote accepted

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.

share|improve this answer

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

protected WebDriver getWebDriver() {

  if (driver == null) {
   driver = new InternetExplorerDriver();
  return driver;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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