Automation with Selenium

Xam-XukinXam-Xukin
3 min read

Introduction

Automation is an integral part of modern software development, and among the tools used for automation, Selenium stands out as the most popular and widely used framework. However, one aspect that can often be overlooked is the significance of managing the WebDriver versions. This article explores why managing the WebDriver version is crucial, how to do it effectively, and the tools available to simplify this process.

Selenium, ??

Selenium is an open-source tool for automating web browsers, allowing developers and testers to create scripts that mimic human actions, and consist of three main components. These include:

  1. Selenium WebDriver, the most widely used component, enables scripts to interact with various web browsers.

  2. Selenium IDE: An integrated development environment (IDE) that runs in the browser and makes it easier to create and run Selenium tests.

  3. Selenium Grid: A solution that allows tests to run on numerous machines at the same time, across different browsers and operating systems.

Selenium tests depend on the compatibility of the WebDriver's version with the browser's version, ensuring smooth functionality and preventing potential issues. Managing the driver's version is crucial to ensuring the effectiveness of the automation process.

Installation

Let's set up Selenium on our machines before we dive into webdriver management.

  1. Install Python: Selenium supports several programming languages, however, Python is the most popular one. Download and install Python from The Official Python webpage.

  2. Install pip: A package installer for Python that usually comes pre-installed.

     pip --version # Check if pip is installed
    
     curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # Download the script
    
     python get-pip.py # Run the script to install pip.
    
  3. Install Selenium using pip:

     pip install selenium
    
  4. Verify installation:

     pip list
    

WebDriver

WebDriver, a critical Selenium component, connects test scripts to web browsers, controlling them with instructions and obtaining results for various browsers. Different web browsers require different webdrivers, below is a list on a few common ones;

  • ChromeDriver: For Chrome browsers

  • GeckoDriver: For Firefox browsers

  • EdgeDriver: For Microsoft Edge browsers

  • SafariDriver: For Safari browsers

To ensure the Selenium tests run smoothly, one must ensure they download a webdriver version that corresponds to the web browser's version.

Visit the official website of the webdriver, i.e., ChromeDriver for Chrome browser and download the version that corresponds to the version of the browser.

WebDriver in the Project

After installing Selenium and getting the right WebDriver for your browser, the next step is setting WebDriver in the Selenium script.

One needs to specify the path where the WebDriver is stored in the script.

from selenium import webdriver

driver = webdrive.Chrome(executable_path="/path/to/chromedriver")

This completes most of the Selenium setup and the script could be able to automate some functions on the browser. However, manually checking and updating of webdrivers can be time consuming, and using scripts to automate updating of browser versions saves times and reduces errors.

WebDriverManager is a tool that simplifies WebDriver management by automatically downloading and configuring the correct version for your browser.

Setting up WebDriverManager

  1. Use pip to install webdriver manager library:

     pip install webdriver-manager
    
  2. Integrate the WebdriverManager with the Selenium script:

    Instead of manually specifying the webdriver path, use WebDriverManager to handle it.

     from selenium import webdriver
     from webdriver__manager.chrome import ChromeDriverManager
    
     driver = webdriver.Chrome(ChromeDriverManager().install())
    
  3. The WebDriver will automatically configure the correct version for the browser.

There are other alternative tools for managing the WebDriver versions, however, the WebDriverManager is the widely used. These tools include:

  1. SeleniumBase: A framework with built-in WebDriver management along with testing utilities.

  2. Selenium Manager: A new feature in Selenium 4 that automatically manages WebDriver's binaries.

Conclusion

Managing WebDriver version in Selenium is crucial for automation tests stability and reliability. Understanding WebDriver, using tools like WebDriverManager, and following best practices ensures efficient tests.

In future, as technology grows, automation testing trends like AI-driven test automation are expected to enhance WebDriver management, reducing manual tasks by automatically predicting and adjusting to browser version changes.

0
Subscribe to my newsletter

Read articles from Xam-Xukin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Xam-Xukin
Xam-Xukin

A software engineer with an inclination towards security. I like to simplify the things I know so you can understand them better, the gods must be crazy! A champion for decentralization technologies, there's huge potential in the blockchain technology. Crazy righ? Sometimes I love to play chess & eat tuna.