How to Run Selenium Tests on Chrome Using ChromeDriver

running Selenium tests on Chrome with ChromeDriver

Summarize this blog post with:

In this fast-paced technical world, every QA engineer and developer is looking for a faster, more reliable way to execute web automation testing. If you want to run Selenium tests on Chrome, configuring ChromeDriver is the most important first step. Selenium ChromeDriver helps you launch and control the Chrome browser directly from your test scripts, making it the go-to setup for automation teams across the globe.

This guide covers how to download, install, and configure ChromeDriver using environment variables, System.setProperty(), and WebDriverManager to execute Selenium automation tests on Chrome efficiently.

Since Google Chrome is one of the most widely used web browsers globally, testing web applications on Chrome has become an essential part of modern test automation.

What is Selenium ChromeDriver?

Selenium is an open-source automation testing framework to test web applications using web browser interactions. It supports various browsers like Chrome, Firefox, Internet Explorer, and Safari.

We use ChromeDriver with Selenium to automate and execute tests on the Chrome browser. ChromeDriver is an executable driver that allows Selenium WebDriver to launch and control Google Chrome. As an open-source tool, ChromeDriver can be configured based on different automation testing requirements.

How to Download, Install, and Configure ChromeDriver for Selenium on Windows

Chrome Driver implements W3C WebDriver standards and protocols. To use Chrome Driver, we must first download it from the Chromium website, install it on the system, and set up the project.

To configure Chrome Driver in the code, we use the following line of code:

WebDriver driver = new ChromeDriver()

Chrome Browser implements the WebDriver Interface. We need Chromedriver.exe to start the server on the system that runs the test scripts in Selenium.

Make sure the ChromeDriver version matches the installed version of Google Chrome to avoid session creation errors during test execution. To check your Chrome version, go to the Chrome menu, click Help, and then click About Google Chrome. Download the matching ChromeDriver version from the official Chrome for Testing dashboard. A version mismatch will cause your Selenium tests to fail immediately with a SessionNotCreatedException error.

How to Configure ChromeDriver Path Using System Environment Variables in Windows

We can declare system-level variables for Chrome Driver so that whenever a webdriver instance is created in a Selenium script, it automatically detects the path of the Chrome Driver and runs on it.

Step 1: Once the ChromeDriver executable file is extracted and moved to the folder location, copy that location and set its path in the System’s environment variables.

unnamed

Step 2: Open the “System Properties” pop-up. Click on the “Environment Variables” button. In the System Variables section, click on the Path variable and then click on the Edit button. 

Configure Selenium Chrome Driver using Environment Variables

Step 3: On the Edit environment variable pop-up, click on the “New” button and add the ChromeDriver executable location. 

Step 4: Click on OK to save the configuration. 

Step 5. When we create an instance of ChromeDriver in the script, it will automatically detect the ChromeDriver path from the system variables and run the tests on the Chrome browser.

Configuring ChromeDriver in Selenium Using the System.setProperty() Method

There is another way to configure ChromeDriver in the test script, which is to configure it explicitly using the System.setProperty() method 

This method accepts a key-value pair where the

key is “webdriver.chrome.driver” and the value is the path of the ChromeDriver executable file that is chromedriver.exe

System.setProperty(“webdriver.chrome.driver”,”path of the chromedriver.exe”)

Running Selenium Tests on Chrome Browser with ChromeDriver

Once ChromeDriver is configured successfully, Selenium WebDriver can directly launch and automate the Chrome browser using test scripts. With the correct setup in place, developers can execute browser actions, validate web elements, and perform end-to-end automation testing efficiently.

Steps to Run Selenium Tests on Chrome Browser Using ChromeDriver (with Java)

  1. In any IDE, create a Java Project and add Selenium Java Jars to the Java build path. 
  2. Create a Java class and write the code below to launch the Chrome browser.

Delete the System.setProperty() line from the above code if ChromeDriver is configured in the environment variable.

Code Walkthrough: 

  1. Set the  system property “webdriver.chrome.driver” to the path of your ChromeDriver.exe file and instantiate a ChromeDriver class: System.setProperty(“webdriver.chrome.driver”,”chromedriver path”); 
  2. Maximize the window: driver.manage().window().maximize();  
  3. To open the URL: driver.get(“URL link”)

How to Use WebDriverManager to Automatically Configure ChromeDriver in Selenium

WebDriverManager provides an API using the class WebDriverManager (package io.github.bonigarcia.wdm). This class provides a group of static methods to create managers, i.e., objects devoted to providing automated driver management and other features.

The primary use of WebDriverManager is the automation of driver management. To use this feature, you need to select a given manager in the WebDriverManager API (e.g., chromedriver() for Chrome) and invoke the method setup().

Let us see how to invoke the browser using WebDriver Manager:

Add the below dependency to the pom.xml

The line of code invokes the Chrome browser using WebDriverManager.

Using WebDriverManager, there is no need to manually download or configure the ChromeDriver executable file. With a single line of code, WebDriverManager automatically downloads and manages the required driver version.

Conclusion

Selenium and Chrome continue to be one of the most widely used combinations for web automation testing. With proper ChromeDriver configuration, developers can execute reliable and scalable Selenium tests efficiently across Chrome browsers. Even though we can use ChromeDriver without any additional configuration, we have understood how to get the most out of ChromeDriver by configuring it. By default, ChromeDriver will try to launch the latest version of Google Chrome. Whether you choose environment variables, System.setProperty(), or WebDriverManager, each method lets you run Selenium tests on Chrome reliably — pick the one that best fits your project setup.

However, you can specify a different version by setting the ‘CHROME_DRIVER_VERSION’ environment variable. With the appropriate ChromeDriver configuration in place, Selenium can efficiently automate Chrome browser testing workflows.