The Basics of Selenium: An Introduction for Beginners

Dulmini Attanagoda
5 min readDec 26, 2023

--

Let’s understand the basic concepts of Selenium

Hi guys 👋 This is the very first blog post of a blog post series that I am hoping to share on Medium. This series aims to share my knowledge of basic to advanced Selenium concepts. I will introduce ‘Selenium’ to a complete beginner in this blog post.

What is Selenium?

Selenium is an open-source tool that is used for automating the tests carried out from web browsers. Also, it can be a portable framework for automating applications that meet web pages. Through Selenium we can test applications across different browsers like Chrome, Firefox, and Safari. Also, testing can be carried out from various OS platforms like Windows, Mac, and Linux.
The Selenium test scripts can be integrated with tools such as TestNG and JUnit for managing test cases and generating reports. It can be also integrated with Maven and Jenkins.

Why Selenium?

Let’s discuss some major benefits of Selenium.

Open Source

The Open Source accessibility of Selenium test automation is among its most significant advantages. Anyone can download and use the source code because it is an open-source tool. Refactoring ability according to project requirements is another option. Predefined functions and classes now function better as a result. Selenium’s ease of use in creating test scripts to verify functionality has made it the most dependable web automation tool available.

Multi-Langue Support

For any competent software professional to enter the automation testing field, this has to be the most important and necessary requirement. The most popular languages testers use to write Selenium test automation code are C#, Java, PHP, Perl, Python, and Ruby. To avoid the need to learn a new language, enterprises have the option to continue using the same language that testers are currently using. However, there are a few situations where choosing a new language is convenient. For example, if the team is new or the software is being redesigned and the legacy language is now out of date. In these kinds of scenarios, Selenium test automation is quite helpful. Selenium provides the ability to select a new and simpler language for testing.

Cross-Browser Support

In today’s world, the most widely used browsers are Chrome, Firefox, Safari, Internet Explorer, Opera, and Edge. All these browsers are compatible with Selenium test automation scripts. Test scripts can be written and also run in all these mentioned browsers. This implies that, with the support of browser drivers, it is not necessary to rewrite the scripts for each of the browsers rather a single script should work for all browsers.

Cross-Platform Support

Selenium gives another benefit for us when we don't need to bother with the system configurations. Test scripts can be created on any operating system and run on any other operating system. For example, we can write a selenium test automation script on Windows, which can be run on Mac or Linux. As a result of this, QA engineers and testers are better equipped to write the scripts efficiently and pay minimal attention to the platform.

Framework Availability

Similar to templates, frameworks give multiple benefits to our script structure such as facilitating easy code maintenance, improving code reuse, increasing portability, lowering the cost of script maintenance, and improving the readability of the code. A variety of frameworks exist, including hybrid frameworks, data-driven frameworks, and keyword-driven frameworks.

Components of Selenium

Components of Selenium

Selenium IDE

Test case developers use the Selenium IDE (Integrated Development Environment) primarily as a record/run tool for creating Selenium test cases. Anyone new at creating automated test cases for their web applications can utilize the simple-to-use Selenium IDE tool from the Selenium Test Suite.

Selenium RC or Selenium Remote Controller

This tool allows you to develop responsive design tests in any scripting language of your choice. Server and client libraries are the two main components of Selenium RC. Its architecture is complex and it has its limitations.

Selenium WebDriver

An improved version of Selenium Remote Controller is called Selenium WebDriver. It was released onto the market to get around Selenium RC’s limitations. Despite being a more sophisticated version of RC, its architecture is entirely distinct from RC’s. Like Selenium RC, Selenium WebDriver necessitates knowledge of one programming language and supports multiple programming platforms for increased flexibility.

Selenium Grid

Selenium Grid allows users to run tests on different machines, with different browsers and OS simultaneously, which gives the ability to run tests in parallel, as such saving a lot of time and resources for testing on several machines.

If you haven’t already downloaded Selenium. Please refer to the following guide on how to install Selenium.

The Architecture of Selenium Web Driver

The Architecture of Selenium Web Driver

Selenium Client Library — Mainly web driver architecture that supports different languages like C#, Python, Ruby, and Java. Software testers can select the languages that they are comfortable with.

JSON Wire Protocol — The JSON Wire Protocol facilitates all the communication that is happening in Selenium between the browser and the code. This is the heart of Selenium. JSON Wire Protocol provides a medium for data transfer using a RESTful (Representational State Transfer) API which provides a transport mechanism and defines a RESTful web service using JSON over HTTP.

Browser Driver — The driver communicates with its respective browsers and executes the commands by interpreting JSON which it receives on the browser. The browser driver receives responses from the browser it sends JSON responses back to the client.

The following code block demonstrates a simple WebDriver example.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class SeleniumTest {
public static void main (String[]args){

// Set the path to the ChromeDriver executable
System.setProperty("webdriver.chrome.driver","C:\\Users\\HP\\Downloads\\chromedriver-win64\\chromedriver.exe");

// Initialize the ChromeDriver instance
WebDriver driver = new ChromeDriver();

// Open the Web page
driver.get("https://www.daraz.lk/");

// Close the Browser
driver.close();
}

}

How to run the tests in Firefox and Edge browsers with Gecko drivers.

// set the path to the GeckoDriver executable
System.setProperty("webdriver.gecko.driver","C:\\Users\\HP\\Downloads\\geckodriver-v0.30.0-win64\\geckodriver.exe");
// initialize the FirefoxDriver instance
WebDriver driver = new FirefoxDriver();

In the next blog post, we will discuss the topic of ‘Locators’ in Selenium. Click on the following link to view the next chapter 👇.

Conclusion

  • So, in this blog post, we have discussed the basic concepts of Selenium.
  • In the end, we have also understood how to create a web driver in Selenium.
  • As I’ve mentioned, next we will discuss the topic of ‘Locators in Selenium’.

Thank you for reading 🎉✨.

--

--