Nishil Patel
Jul 18, 2024
8 min read
ChromeDriver enables communication between your web apps and the Chrome browser. You can configure it to run software tests across the browser right from your local machine or through remote setup.
1.
Introduction
2.
What is ChromeDriver?
3.
What is WebDriver?
4.
What are “Capabilities” in WebDriver?
5.
Relationship Between WebDriver and ChromeDriver
6.
What Exactly Does ChromeDriver Do, and What Can You Do With It?
7.
How Does It Help in Automation?
8.
Setting Up ChromeDriver
9.
How ChromeDriver is Used in Automated Testing Frameworks like Selenium
10.
How to Configure ChromeDriver for Selenium?
11.
Use Cases for ChromeDriver
12.
Common Issues and Troubleshooting
13.
Best Practices for Using Chrome Driver
14.
How to Stay Informed About New Releases And Updates
15.
FAQs
If you're looking for a browser that reigns supreme on the internet, Google Chrome stands out unequivocally. With over 3.45 billion users and commanding an impressive 63.87% share of the global browser market, Chrome is ubiquitous across modern devices, from laptops to smartphones. Web apps interact with Chrome through an executable driver file known as ChromeDriver. Let's dive in.
ChromeDriver is an executable file that lets you control and run automation tests of web apps within the Chrome browser. It's a free-to-use driver that functions as a standalone server and enables communication between your test scripts and the Chrome browser.
ChromeDriver implements the W3C WebDriver standard by extending the WebDriver class with Chromium-specific capabilities. Capabilities are key-value pairs (just like in an object). You can configure them to run automated test scripts for web apps across browsers. The test scripts can be written in Java, Python, C#, etc.
You can download ChromeDriver for:
Also Read: Top 24 Chrome Extensions for Software Testers
WebDriver helps define a standard interface for interacting with web browsers. It's an open-source tool. It abstracts browser-specific details and allows you to write test scripts that work across various browsers (not just Chrome).
It can work with local user agents (like sending HTTP requests in your browser running on your local machine) or with capabilities in remote browser instances.
For example, if your web app places API calls or requires user actions for automation testing (using test scripts), the WebDriver interface takes care of it by communicating with the browser. For Chrome, it's the ChromeDriver that embeds this transactional information.
For instance, you can automate:
Also Read: Top 10 Automation Testing Tools
Capabilities in WebDriver are key-value pairs that define desired browser behaviors and features. They are programming language-neutral and can be passed as an argument to create a WebDriver instance.
Using capabilities, you can configure browser settings, such as:
WebDriver doesn't directly control browsers. Instead, it relies on browser-specific details. For Google Chrome it's the ChromeDriver browser driver (powered by WebDriver).
If you are using Firefox, you would use the GeckoDriver as the browser driver. Similarly, for MS Edge, you’d use Edge WebDriver. Each browser has its corresponding driver that WebDriver communicates with to perform actions.
ChromeDriver extends the WebDriver class using the ChromeOptions object provided by the WebDriver API. This is for a WebDriver session (or an instance) containing Chromium-specific capabilities. These capabilities enable you to perform actions beyond the standard WebDriver interface.
For instance, you can:
ChromeDriver allows you to perform various automation tasks while testing apps on the web. Selenium is a pretty popular automation framework for it (covered in upcoming sections). It’s especially beneficial while simulating GUI-related features and functions.
For example, you can automate:
Also Read: What is Functional Testing?
Here’s a stepwise guide on how to download ChromeDriver for version 115 and above:
Step 1 - Go to the ChromeDriver official downloads page.
Step 2 - To get the latest version, click the “the Chrome for Testing availability dashboard” text.
This takes you to the download dashboard page. (As of writing this article, version 126 is the latest one available.)
Step 3 - You can download among Stable, Beta, Dev, and Canary versions. Choose the version based on your platform.
For instance, you can install the latest stable version for Windows.
To start downloading, copy the link for the Win64 option and paste it into your browser tab. This instantly downloads the chromedriver-win64.zip file on your system.
Step 4 - Next, extract the downloaded zip file to retrieve the chromedriver.exe file.
Step 5 - Lastly, copy and paste the chromedriver.exe application file to your automation project’s root directory.
It’s all set.
Here’s a stepwise guide on how to download ChromeDriver for version 114 and below:
Step 1 - Go to Google’s official downloads page for version 114 or below. For instance, here’s a link for version chromedriver 114.0.5735.90
Step 2 - Next, click on the desired platform to start downloading. For instance, hit chromedriver_win32.zip to start the binary file download.
After the download finishes, extract the zip file, and copy the chromedriver.exe application to the root directory of your automation project.
Step 1 - Open the link here (it takes you to the 114 version download page) and hit “Parent Directory”.
Step 2 - It takes you to the index page for all Chrome driver versions, which you can select, click, and download as shown above.
Selenium WebDriver is widely used to run automated test scripts for web apps in the browser. The Selenium WebDriver is a collection of different APIs for running automated tests.
ChromeDriver is one among many other APIs. It enables Selenium scripts to communicate with the Chrome browser to execute and run automation tests.
Here are some ways to configure it for different operating systems while using Selenium:
Here’s how to configure ChromeDriver using environment variables on your Windows machine.
You can define an environment variable at the system level for Selenium to auto-detect the path for ChromeDriver. Simply put, the newly defined system variable points to the location of ChromeDriver. This happens automatically whenever you create a new instance of a WebDriver session.
Here’s how to set up an environment variable for ChromeDriver at the system level:
Step 1 - Once you download, extract, and copy the chromedriver.exe file to your project’s location, copy the location of the executable file.
Step 2 - Search and open “Edit system environment variables” from the Control Panel.
Step 3 - Click “Environment Variables” from the “Advanced” tab.
Step 4 - Under the System variables tray, select “Path” and then hit “Edit”.
Step 5 - Click “New” and paste the path location of the previously copied chromedriver.exe file.
It’s all set now.
Use the following code in your Selenium script to auto-detect the driver from the system variable, whenever you need the ChromeDriver instance:
new_driver = new ChromeDriver();
You can also set the driver path manually in your test script using the System.setProperty() method. Here’s the code:
System.setProperty("webdriver.chrome.driver", "C:\\MyWebApp\\chromedriver.exe");
This method lets you input key: value pairs. Here you’ve:
key: webdriver.chrome.driver
value: C:\\MyWebApp\\chromedriver.exe
That’s it. Your setup is ready to go.
Here’s how to configure ChromeDriver using the Mac terminal.
ChromeDriver is pretty good at performing software testing-related tasks. Using it, you can:
Also Read: Types of Software Testing Tools
Here are some common issues that you may encounter while configuring ChromeDriver and tips to keep them at bay:
Here is a list of some best practices you can borrow:
To stay updated, you can:
Nishil is a successful serial entrepreneur. He has more than a decade of experience in the software industry. He advocates for a culture of excellence in every software product.
Meet the Author: Nishil Patel, CEO, and Co-founder of BetterBugs. With a passion for innovation and a mission to improve software quality.
We never spam.
Share your experience with the founderhere!