0 min read

Learn the Usage of Selenium ChromeDriver: How to run Selenium Tests?

A web browser is the window which provides you with access to the world of the Internet. It is the application software required for accessing a local website or the World Wide Web. Undeniably, it has overwhelming utility. Users have the option of choosing from a range of web browsers available.

Moreover, most of the major browsers offer different useful features which help users customize their own experience. In this regard, Google Chrome Browser is a market leader, being one of the top preferred web browser, with a market share of nearly 65-67%. Given its wide scale usage and global coverage, it becomes imperative to test web applications/websites on the Chrome browser.

In this respect, Selenium as a foremost Automation Testing Tool is preferred for the testing purpose since it offers cross-browser functionality. This is facilitated through the Selenium ChromeDriver.

The ChromeDriver is provided by Google Chrome which helps in establishing connection between the browser and Selenium WebDriver. Once you configure ChromeDriver, you will be able to run Selenium Tests on Chrome browser.

In this blog, we shall look at what is Selenium ChromeDriver. We shall get into the details of how to download, install and configure ChromeDriver for Windows. Consequently, we shall look at the steps to run Selenium Tests on Chrome browser.

 

What is Selenium ChromeDriver?

If you wish to run Selenium tests on the Chrome browser, the medium which facilitates that act is the ChromeDriver. The Selenium ChromeDriver is the standalone server which helps in executing the open-source Selenium WebDriver Chromium Protocol.

The translation of the Selenium commands into purposive actions on the browser is facilitated through the interaction of the Selenium tests with the ChromeDriver through the JsonWireProtocol.

It is evident that the ChromeDriver Selenium is indispensable for running Selenium tests on the browser. You can achieve this act by instantiating the object of the ChromeDriver and assigning it to a WebDriver object. The initialization of object of the ChromeDriver can be done through the following command.

WebDriver new = new ChromeDriver

 

What are the Pre-Requisites for Selenium ChromeDriver?

Before you can begin the process of executing Selenium tests or even launch the ChromeDriver, it is mandatory that your system should be equipped with few essential requisites.

Java/JDK/JRE

Java Development Kit or JDK is required for writing the Java program. It encompasses JRE and other development tools, including debugger and compiler. Since here we are focussed on writing Selenium Tests in Java, the presence of JDK is a must.

You can run a Google search for Download Java Oracle or you can directly visit the site through this link: https://www.oracle.com/in/java/technologies/javase-downloads.html. From the site you need to go to JDK Download.

java se downloads

On clicking the download link, you will be redirected to Java SE 16-Downloads Page. The page offers a list of catalogued Java Development Kits.

You will be required to choose the one which best corresponds to your system configuration. This JDK version comes along with Java Runtime Environment (JRE), so you won’t be required to download and install JRE separately.

Java SE Development Kits

You will just be required to click on the specific file and run Java on your computer. Consequently, JDK will be successfully installed on your system.

Eclipse IDE

IDE stands for Integrated Development Environment. It serves as an editor and offers features which ease the programming requirements of users.

In this case, we are referring to the Eclipse IDE which can be downloaded from the official website of Eclipse.

You can run a Google search for Download Eclipse IDE Packages or directly click on the given link: https://www.eclipse.org/downloads/packages/.

You will be directed to a page showing Eclipse IDE 2021-06 R Packages. You need to scroll down and search for Eclipse IDE for JAVA Developers and download it according to the version and compatibility of your operating system (32 bit or 64 bit).

Eclipse IDE Packages

Selenium WebDriver

One of the important pre-requisites for Selenium ChromeDriver is the installation of the Selenium WebDriver.

In order to get a detailed understanding of how to download, install and set-up Selenium, refer to our blog on Selenium Download: A Complete Tutorial

 

How to Install and Configure ChromeDriver on Windows?

We have already seen that Selenium ChromeDriver is indispensable to executing Selenium tests on Chrome browser.

In order to successfully, download, install and configure ChromeDriver, it is important to be careful of the specific version of your Chrome browser. This is important because the compatibility of the ChromeDriver is dependent on the version of your browser.

  • In order to check the version of your browser, click on the three dots on the top right corner of your browser.
  • From the drop down menu, click on Help and then on About Google Chrome
  • The page which will open thereafter will give you the details of the Chrome version
How to Install and Configure ChromeDriver on Windows
How to Install and Configure ChromeDriver on Windows - 2

Once you are clear about your browser version, you will need to download the corresponding ChromeDriver version.

You can navigate to the link of the official ChromeDriver website and download the specific ChromeDriver version, based on your browser version.

https://chromedriver.chromium.org/downloads

current releases

Since the browser version in this case is 99, you can click on the ChromeDriver 99.0.4844.51 link, which will redirect you to the ChromeDriver index page. Herein, you will come across different versions of ChromeDriver, based on your operating system. You can opt for the Win32 version for Windows.

ChromeDriver index

You can download the specific Chrome browser version and once the download is complete, you can extract the zip file and place the chromedriver.exe at a specific location on your system.

Once the ChromeDriver has been downloaded, you will be required to set-up and configure ChromeDriver in order to be able to use it in to conduct Selenium tests.

One of the ways to set-up and configure ChromeDriver is by using System Properties in Environment Variables. In order to do that, follow the given steps:

  • Navigate to My Computer and right click in order to get the drop down menu where you have the Properties option
properties
  • Go to Change Settings and click on Advanced Tab. Select Environment Variables from the Advanced Tab
Environment Variables
  • You will come across a list of options from which you have to choose the option of Path and then click on Edit
choose path
  • You will be redirected to the Edit Environment Variable. From the pop-up, click on the New button. Herein, you will be required to paste the path of your ChromeDriver file and then click on OK
 

Steps to Run Selenium Tests on Chrome Browser

In this section, we shall elaborate on the steps to run Selenium Tests on Chrome Browser. We have already covered the pre-requisites for Selenium ChromeDriver as well as the procedure to download, install and configure ChromeDriver. Once this process of setting up Selenium ChromeDriver is complete, we can proceed to execute the tests.

Step 1: Proceed with the installation of the Eclipse IDE and import all the Selenium dependencies into the project directory

Step 2: You will be required to set the properties by specifying the type of driver to be used, as also specifying its path where it is stored

Step 3: In this step you will be required to initialize the object of the ChromeDriver. This launches the Chrome browser

Step 4: The driver.get() method function can be used to navigate to a particular URL

Step 5: Different web elements can be located with the help of specific locators offered by Selenium. XPath in Selenium serves as an important strategy for locating elements in Selenium. If you wish to read more on this topic, do refer to our blog on XPath in Selenium: A Complete Tutorial.

Example:

We are considering a test case sample where we want to perform three steps.

  1. Open Chrome Browser
  2. Navigate to www.google.com 
  3. Enter Facebook in the search text box

Refer to the Code snippet below.

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.chrome.ChromeDriver;

public class ChromeExample {

public static void main(String[] args) {

//Setting system properties of ChromeDriver

System.setProperty(“webdriver.chrome.driver”, “C://Selenium-java syntax//chromedriver_win32//chromedriver.exe”);

//Creating an object of ChromeDriver

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

//Deleting all the cookies

driver.manage().deleteAllCookies();

//Specifiying pageLoadTimeout and Implicit wait

driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

//launching the specified URL

driver.get(“https://www.google.com/“);

//Locating the elements using name locator for the text box

driver.findElement(By.name(“q”)).sendKeys(“Facebook”);

//name locator for google search button

WebElement searchIcon = driver.findElement(By.name(“btnK”));

searchIcon.click();

}

}

After the execution of the above code, the Selenium ChromeDriver helps in launching the Chrome browser, in opening the Google website and enter the value Facebook in the search box. This is the way in which Selenium test scripts are run on Chrome browser, using ChromeDriver.

 

Conclusion

Given the overwhelming significance of Google Chrome as a web browser, it has become imperative to test web applications on the Chrome browser. This is facilitated with the help of Selenium ChromeDriver which provides for automated browser testing of applications on Chrome. In this blog, we have covered the pre-requisites for Selenium ChromeDriver, the process to download Chromedriver, install and configure it as well as the steps to run Selenium tests on Chrome browser.

sdet automation certification course
 

 

Like what you read?
Share with your community!

Subscribe to our
newsletter