As to improve the Selenium 2 test speed?



  • 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.



  • 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.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2