How to run Selenium tests on Chrome using ChromeDriver?
Google Chrome dominates the browser market with a massive 64% global market share. With several useful features, it is one of the most preferred browsers in the world. Given its importance and usage, testing all websites on Chrome becomes crucial.
This article will explain how to perform Selenium tests on a Chrome browser using ChromeDriver. But before that, let’s understand what ChromeDriver is and how users can configure it on their systems.
What is a Selenium ChromeDriver?
A ChromeDriver is a standalone server or a separate executable used by Selenium WebDriver to control Chrome. Running Selenium test scripts on the Google Chrome browser is impossible without ChromeDriver. One can easily initialize the object of ChromeDriver using the following command:
WebDriver driver = new ChromeDriver
How to download ChromeDriver for Selenium?
You can download ChromeDriver for Selenium as per the ChromeDriver version using its official website. Here are the steps given below:
Steps to download ChromeDriver version 115 and above




Steps to download ChromeDriver version 114 and below

Now, we have the desired ChromeDriver downloaded depending on our Chrome browser version, let us see the 2 ways by which we can configure ChromeDriver via environment and System.setProperty() method of Java.
How to configure ChromeDriver?
You can configure ChromeDriver using different methods
Steps to configure ChromeDriver via Environment Variable
On Windows operating systems, we can declare system level variables by using Environment variables. Below steps will help you set up the environment variable for Chrome Driver. Whenever an instance of the WebDriver is created in Selenium script, it will automatically detect the path of the ChromeDriver from the system variables.



driver = new ChromeDriver();
This will automatically detect the ChromeDriver path from the system variable.
Configure ChromeDriver via System.setProperty method
ChromeDriver can also be configured by explicitly specifying the ChromeDriver path in the test script.
System.setProperty accepts key value pair where key would be “webdriver.chrome.driver” and value would be the path of the ChromeDriver exe path.
System.setProperty("webdriver.chrome.driver", "D:\\BStackDemo\\chromedriver.exe");Steps for macOS users:
Steps to run Selenium Tests on Chrome Browser
Let’s discuss how to run Selenium scripts on a Chrome browser using ChromeDriver.
Pro Tip: Want to dive deeper into Selenium implementation on BrowserStack with free interactive courses and lab exercises? Visit Test University
Now let’s consider a test case example wherein we want to perform 2 simple steps:
Refer to the code snippet below to get a better sense of executing the steps mentioned above:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class ChromeTest { public static void main(String args[]) { WebDriver driver; //Setting system properties of ChromeDriver System.setProperty("webdriver.chrome.driver", "D:\\BStackDemo\\chromedriver.exe"); //Creating an object of ChromeDriver driver = new ChromeDriver(); //launching the specified URL driver.get("https://bstackdemo.com/"); } }If you are configuring ChromeDriver via the environment variable, delete the System.setProperty() line from the above code and it should work.
Run Selenium Tests using ChromeDriver
- Although it’s vital to test web-apps for Chrome, it’s also important for a web app to be optimized for other browsers like Firefox, Safari, Edge, etc.
- Teams can leverage BrowserStack, which enable QAs to perform cross browser testing for their web apps across thousand of real browsers and browser versions like Safari, Opera, Edge, etc.
- All real browsers are installed on real desktop and mobile devices, thus providing the optimal environment for software testing in real user conditions.
ncG1vNJzZmivp6x7o77OsKqeqqOprqS3jZympmeXqralsY6rrKdlo5q5prrIrqRmrJWowbR51Kygp59dqLKtsc2irKZlk52%2FsLnEnamirpWn