In this post, will discuss about controlling ChromeDriver’s lifetime in Selenium Webdriver.

Controlling ChromeDriver's lifetime in Selenium Webdriver

Normally we use ChromeDriver for webdriver’s execution of test scripts.
ChromeDriver is a separate executable that WebDriver uses to control Chrome.

Once Chrome Browser is installed in the system, webdriver user’s downloads ChromeDriver binary for the platform that they use to execute the scripts.

ChromeDriver expects Chrome Browser installed in the default location for any platform.

We can also force ChromeDriver to use a custom location by setting a special capability.

Setting custom location for ChromeDriver:
ChromeOptions options = new ChromeOptions();
Set a Chrome preference
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);
Controlling ChromeDriver’s lifetime

The ChromeDriver class starts the ChromeDriver server process at creation and terminates it when quit is called.

This can waste a significant amount of time for large test suites where a ChromeDriver instance is created per test. To remedy this we can use ChromeDriverService

Use ChromeDriverService. Available in most of the languages and allows us to start\stop the ChromeDriver server.

When execute below example by looping the test several times(say 10 times), time got saved by 10 to 15 seconds by using ChromeDriverService instead of ChromeDriver.

In this example, I  quit the driver at method level. Same can be experimented in different ways at Class level and Suite level as well.

public class ChromeDriverService_Example {

WebDriver driver;
ChromeDriverService chromeService;
String chromeDriverPath;

public void setup() throws IOException
   chromeDriverPath = "\\chromedriver.exe";
   System.setProperty("", chromeDriverPath);
   chromeService = new ChromeDriverService.Builder().usingDriverExecutable(new File(chromeDriverPath)).usingAnyFreePort().build();

public void createDriver() throws MalformedURLException
   driver = new RemoteWebDriver(service.getUrl(),;
   //driver = new ChromeDriver(chromeService);

public void chromeTest1() throws IOException

public void quitDriver()

public void createAndStopService() {
Selenium Page Object Generator Chrome Extension
Basic Usage of TestNG