Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

@Before
public  void setUpBeforeClass() throws Exception {
    System.setProperty("webdriver.chrome.driver",
    "drivers/chromedriver.exe");
    driver = new ChromeDriver();
    driver.get(baseUrl);
}

@After
public  void tearDownAfterClass() throws Exception {
    driver.quit();
}

Thanks advance.

share|improve this question
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 '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

2 Answers 2

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

 
discard

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.