Unleashing the Power of Selenium 4: A Deep Dive into Selenium Manager

Unleashing the Power of Selenium 4: A Deep Dive into Selenium Manager

Selenium is a popular framework for automated web testing. However, one of the common challenges that Selenium users face is the management of browser drivers. Browser drivers are executables that allow Selenium to communicate with different browsers, such as Chrome, Firefox, or Edge. To run a Selenium test, you need to have the matching driver version for your browser installed and configured on your system. This can be tedious and error-prone, especially when browsers update frequently and drivers need to be synchronized.

Fortunately, Selenium 4.6.0 introduces a new feature that simplifies this process: Selenium Manager. Selenium Manager is a tool that automatically detects, downloads, and caches the appropriate browser drivers for your system. With Selenium Manager, you don't need to worry about setting up drivers manually or using third-party libraries. You just need to have Selenium 4.6.0 or later and your browser of choice installed, and Selenium Manager will take care of the rest. This feature is implementation from the most lovable feature of existing bonigarcia webdrivermanager.

Now we don’t want to use any System.setProperty(…….). Phew.. 😮‍💨

How to use Selenium Manager

Selenium Manager is shipped with all releases of Selenium 4 (Java, JavaScript, Python, Ruby, and .Net). It is a binary tool implemented in Rust that runs as a command-line interface (CLI). You can use Selenium Manager in two ways:

  • As a fallback mechanism for the Selenium bindings. If you don't provide any driver on your system or through system properties, Selenium Manager will be invoked automatically by the Selenium bindings to configure the driver for you. This is the recommended way to use Selenium Manager, as it integrates seamlessly with your existing Selenium code.
  • As a standalone tool. You can also run Selenium Manager directly from the command line, without using the Selenium bindings. This can be useful for debugging or testing purposes, or if you want to have more control over the driver management.

Adding Selenium 4.6.0 jar Maven dependency in POM.xml

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.6.0</version>
</dependency>

To use Selenium Manager as a fallback mechanism, you just need to write your Selenium code as usual, without specifying any driver. For example, in Java, you can create a ChromeDriver instance like this:

import org.openqa.selenium.chrome.ChromeDriver;

public class SeleniumManagerExample {
  public static void main(String[] args) {
    // No need to set webdriver.chrome.driver system property
    ChromeDriver driver = new ChromeDriver();
    driver.get(\"https://www.google.com\");
    // Do some actions with the driver
    driver.quit();
  }
}

When you run this code, Selenium Manager will detect the Chrome version installed on your system, resolve the corresponding chromedriver version, download it if necessary, and store it in a local cache folder. Then, it will set the webdriver.chrome.driver system property for you and launch the driver. You will see some logs from Selenium Manager in the console, indicating the steps it performed.

To use Selenium Manager as a standalone tool, you need to download the selenium-manager binary from the Selenium repository and run it from the command line. You can use the --help option to see the available commands and options. For example, to download the latest chromedriver for your system, you can run:

selenium-manager driver download chrome

This will download the chromedriver binary and store it in the cache folder. You can also specify a specific browser version or driver version, or use a different cache folder. To see the list of available drivers and versions, you can run:

selenium-manager driver list

This will show the supported browsers and drivers, as well as the online metadata used to resolve the driver versions.

Benefits of Selenium Manager

Selenium Manager offers several benefits over the traditional approach of manual driver management or using third-party libraries. Some of the main advantages are:

  • It is built-in Selenium. You don't need to install any extra dependency or library to use Selenium Manager. It is part of the Selenium 4 distribution and works out of the box with the Selenium bindings.
  • It is cross-platform. Selenium Manager is implemented in Rust, which allows it to run on different operating systems and architectures. It can detect and download the drivers for Windows, Linux, and Mac OS.
  • It is up-to-date. Selenium Manager uses the online metadata maintained by the browser vendors to resolve the driver versions. This ensures that it always downloads the latest and compatible driver for your browser.
  • It is fast and efficient. Selenium Manager uses a local cache folder to store the downloaded drivers. This avoids unnecessary downloads and saves bandwidth and disk space. It also checks the integrity of the downloaded files and handles errors gracefully.
  • It is flexible and configurable. Selenium Manager can be used as a fallback mechanism or as a standalone tool, depending on your needs and preferences. You can also customize some aspects of Selenium Manager, such as the cache folder location, the driver download timeout, or the log level.

Conclusion

Selenium Manager is a new feature in Selenium 4 that simplifies the driver management for Selenium users. It automatically detects, downloads, and caches the appropriate browser drivers for your system, without requiring any manual setup or configuration. It is a built-in, cross-platform, up-to-date, fast, and flexible tool that integrates seamlessly with the Selenium bindings. With Selenium Manager, you can focus on writing your Selenium tests, without worrying about the driver management.

Happy Testing.. 🤗