
16 July 2024 Leave a comment QA
Keeping your ChromeDriver updated in sync with your Chrome browser is crucial for maintaining the stability of your Selenium tests. If you are tired of manually updating your ChromeDriver every time Chrome updates, this guide will help you automate the process.
Using WebDriver Manager
One of the most efficient ways to automate ChromeDriver updates is by using the WebDriver Manager. This tool can automatically download the required driver binary file if it is not present locally.
Setting Up WebDriver Manager
Here’s how you can set up WebDriver Manager in your code:
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
To include the WebDriver Manager in your project, add the following dependency to your Maven POM file:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.7.1</version>
</dependency>
Using WebDriver Manager with Docker
For a more versatile solution that works with any programming language, consider using WebDriver Manager with Docker. This method allows you to run a WebDriver Manager server and download drivers from it.
Setting Up WebDriver Manager with Docker
Run the following command to set up the WebDriver Manager server using Docker:
# Mac OSX command
docker run -p 4041:4041 -v $HOME/wdm:/root/.m2/repository bonigarcia/webdrivermanager:4.0.0
# Windows command
docker run -p 4041:4041 -v %USERPROFILE%/wdm:/root/.m2/repository bonigarcia/webdrivermanager:4.0.0
This setup will store the drivers in your local $HOME/wdm
folder and inside the Docker image.
Automating ChromeDriver Updates with Python
If you prefer a custom solution, you can automate ChromeDriver updates using Python. The following script outlines the process:
import requests
url = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE_'
url_file = 'https://chromedriver.storage.googleapis.com/'
file_name = 'chromedriver_linux64.zip'
version = input("Enter Chrome version: ")
version_response = requests.get(url + version)
if version_response.text:
file = requests.get(url_file + version_response.text + '/' + file_name)
with open(file_name, "wb") as code:
code.write(file.content)
This script downloads the latest ChromeDriver version based on the user’s input and saves it in the current directory.
Conclusion
Automating ChromeDriver updates can save you significant time and effort, ensuring your Selenium tests run smoothly with the latest version of Chrome. Whether you choose WebDriver Manager, Docker, or a custom Python script, these solutions can streamline your testing process.
For those looking to further simplify their testing workflows, consider using Repeato, a no-code test automation tool for iOS and Android. Repeato allows you to create, run, and maintain automated tests quickly and efficiently, leveraging computer vision and AI for robust test automation. It’s an excellent choice for quality assurance professionals who need a reliable and easy-to-use solution.