03/12/2022

Selenium Software Testing: guide, tools, pros, cons and more

SHARE:

  • Linkedin Logo
  • Twitter Logo
  • Facebook Logo
  • Mail Logo

This post features an introduction to Selenium automation testing.

It also explains how the set of tools came to exist, its advantages and disadvantages, what type of tests you can do with it, and when it becomes necessary.

Logo Selenium

What is Selenium?

Selenium is an open-source set of tools used to automate tests (also known as a test automation framework) which provides a single interface which allows users to write test scripts using different programming languages such as Java, C#, Ruby, Groovy, Perl, PHP, and Python.

The tests can be executed using most web browsers (Firefox, Chrome, and Edge, among others) and different operating systems, such as Windows and Linux.

Each one of the tools offered by Selenium covers the different quality control testing needs; they can be used individually or they can be combined.

The Selenium testing tools are: Selenium WebDriver, which is used to automate tests based on web applications; Selenium IDE, implemented as an extension in some browsers which makes it possible to record, edit and debug tests. Lastly, there is Selenium Grid, developed in order to execute tests simultaneously in a distributed manner.

Selenium Origins

📚📖  Selenium was created in 2004 at ThoughtWorks when Jason Huggins tried to build a framework to test an internal application for Schedules and Expenses.

Jason started doing demos using the testing tool for various colleagues, who were motivated by its potential as a framework to be used with other web applications.

After several demos, Paul Hammant, a ThoughtWork co-worker, started debating about Selenium’s open code.

Together with other colleagues, they analyzed the possibility of a “server” type component. This server would act as an HTTP proxy and deceive the browser’s instance into thinking that the tes script and the web application under test came from the same source. This was developed in Java, and the original client-side controller (TestRunner) was moved to Ruby.

In the early stages, this was the original Selenium, referred to as “Driven Selenium” or “Selenium B” in the evolution timeline.
Later on, around 2005, more testing and programming specialists joined the project. That is how Dan Fabulich and Nelson Sproul, with the help of Pat Lightbody, offered to introduce several modifications which transformed “Driven Selenium” into “Selenium Remote Control” (RC).
In 2006, Shinya Kasatani became interested in Selenium and pointed out that she could include the central code in an IDE module within a Firefox browser, record tests, and play them back in the same plugin.

In 2007, Jason joined Google along with several people, such as Jennifer Bevan, and they continued with the development and stabilization of Selenium RC.

At the same time, Simon Stewart from ThoughtWorks developed a superior test automation tool called WebDriver, and, in 2009, after meeting with the developers in a Test Automation conference in Google, decided to merge both projects and name the new project Selenium WebDriver or Selenium 2.0.

In 2008, Philippe Hanrigou at ThoughtWorks created Selenium Grid, which provides a center which makes it possible to execute several Selenium tests simultaneously in any number of remote systems, thus minimizing the test execution time.

In 2016, Selenium RC became obsolete and WebDriver, also known as Selenium 3.0, became the standard implementation.

A lot has happened since. Also, in addition to Selenium WebDriver, the Selenium project has become a set of tools composed of Selenium WebDriver, Selenium IDE and Selenium Grid.Selenium Origins

Why is it called Selenium?

The name “Selenium” came from a joke made by Jason Huggins in an email, making fun of a competitor named Mercury, saying that mercury intoxication can be cured by taking Selenium supplements. The people who received the email took on the name as an inspiration to christen the project.
Selenium Testing Tools

The following sections include a brief description of each Selenium Testing Tool. They are:

  • Selenium Integrated Development Environment (IDE)
  • Selenium Remote Control (RC) – Obsoleto
  • Selenium WebDriver
  • Selenium Grid

Types of selenium

1. Selenium IDE

Selenium IDE is an integrated development environment for testing. It is implemented as an extension for Firefox and Chrome. It allows for the recording, edition and debugging of tests. Originally, it was referred to as “Selenium Recorder”.

Users can develop test scripts and create recordings, which can then be manually edited with sentences and commands so that the recording’s playback is successful.

Scripts are generated in Selenese, a language specific to Selenium, which provides commands that execute actions over browser objects, such as clicking a button, selecting items from a list of options, verifying the presence of a text, and also capturing all of the page due to the actions.

2. Selenium Remote Control (RC)

Selenium RC is a client/server system which makes it possible to control browsers locally using different programming languages.

This was the initial framework for all Selenium projects for a very long time. It is the first test automation tool which allows users to develop scripts using different programming languages.

Selenium Remote Control, also known as Selenium 1, was later on merged into Selenium WebDriver.

3. Selenium WebDriver

Selenium WebDriver is Selenium Remote Control’s successor. It is the most widely used Selenium component. It allows users to write code using different programming languages and to interact with their desired browser. WebDriver is composed of a set of APIs which allow the tester to control browsers at an operating system level, web pages and their HTML elements.

When executing Selenium WebDriver, a browser instance is triggered and executes the test script. This instance is specific to the server; for example, Google has developed and maintains ChromeDriver with the aim to integrate with Selenium and support the automation of tests in Chromium/Chrome.

With Selenium WebDriver, it is also possible to integrate with several libraries such as Cucumber, TestNG or JUnit.

As shown in the image above, the WebDriver and RC projects were merged, and their features were incorporated into Web Driver version 2, which was named “Selenium 2”.

Later on, Selenium 3 came out, which was a Selenium 2 update with many improvements and new features, and has since become a standard in the World Wide Web Consortium (W3C).

Nowadays, Selenium 4 is the latest Selenium version, and it is available for the Java, .NET, Python, Ruby and JavaScript programming languages.

This latest version includes several improvements and new features, such as the introduction of relative locators. When using a Chromium or Firefox browser, the version also includes ways to handle authentication, the intersection of networks and tasks in order to wait for a DOM change or to provide a way to see errors in JavaScript, among others.

Selenium supports seven different object locators as a way to interact with a web application. This is important when creating automated tests, since it makes it possible to click, slide, enter text, using the following locators:

Simple locators:

  • By.id() – Locate an element using the “id” attribute of the HTML tag.
  • By.name() – Locate an element using the “name” attribute of the HTML tag.
  • By.tagName() – Locate an element using the name of the tag (for example, input).
  • By.className() – Locate an element using one of the tag’s CSS classes.
  • By.linkText() and By.partialLinkText() – Locate an element using the exact text or a partial text for an “a” tag (link).

Advanced locators:

  • By.cssSelector() – Locate an element using a CSS locator.
  • By.xPath() – Locate an element using an XPath

Last, but not least, as mentioned above, the new locators are available (“Relative Locators”), which are useful when it is difficult to build a locator for a particular element. In those cases, these locators search for the web elements in a more human-like language, such as “above this element” or “to the right of this other element”; that is to say, these elements take use an element that had been located before or another locator as a starting point.

Examples:

  • RelativeLocator.with(By.tagName()).above(By.id())
  • RelativeLocator.with(By.tagName()).below(By.id())
  • RelativeLocator.with(By.tagName()).toLeftOfOf(By.id())
  • RelativeLocator.with(By.tagName()).toRightOf(By.id())

4. Selenium Grid

Selenium Grid is a server which allows for browser instances to be used enabling the parallel execution of several simultaneous tests on different machines.

It is an environment with multiple instances with a hub and different nodes. The hub is a “master” server which controls and communicates with other nodes. The nodes are remote devices where, basically, the Selenium test scripts are executed. The execution instructions are sent from the hub, and users can verify whether or not all of the applications for the different systems are being executed successfully.

An example is the LambdaTest tool, which is used to perform tests on the cloud within Selenium Grid.

Selenium Features 

👍 Selenium Advantages

Because it is a set of tools, Selenium offers many possibilities for the automation of tests, which allows for users to find something that adapts to their needs and working style.

As mentioned before, Selenium can be used in all modern browsers, such as Chrome, Firefox, Safari, Internet Explorer, Opera and Edge. It is compatible with different operating systems such as Windows, Linux, Mac OS and UNIX, and it works with several programming languages.

The main objective of having automated tests is to save time and effort. By using Selenium Grid, you can execute tests in parallel, which reduces the tests’ execution time.

In addition, because it is open source, the tools can be adapted depending on the needs of every user, and there is a large number of users using it, which makes it easier to learn how to use it and share best practices.

Lastly, these are some other advantages:

  • It is free: there are no licensing costs.
  • It is easy to install.
  • It has a high degree of integration, so it is possible to perform different tests and reports in parallel.
  • Code can be reused, and test scripts can be used in different scenarios and browsers.
  • There is a lot of documentation available, both official and from the Selenium community.

👎 Selenium Disadvantages

Regardless of the many benefits and advantages, we should also point out that there are some features it does not have.

For the automation of tests in both desktop applications and mobile applications, it requires other drivers and additional components.

For example, you can use Appium for applications executed on mobile devices.

The features linked to test reports and data reports are available if you integrate with other tools.

Likewise, you need to consider how the infrastructure will be maintained. Configuring several components and Selenium Grid is a task that will require some time. They involve continuous monitoring, updates and patches.

Another disadvantage is that users must have some programming knowledge in order to carry out tests. In spite of how convenient it is because you can use several programming languages, oftentimes testers do not have the necessary programming knowledge, which limits how much they can use it.

Types of Selenium Tests

Below, you will find a description of the different types of tests that can be automated using Selenium automation testing:

UI tests are just one type of functional tests. In order to automate tests, Selenium remotely controls browser instances, obtaining elements from the user’s graphic interface so it can simulate tasks or interactions, such as filling in fields, selecting options from dropdowns, and clicking buttons, among others.

Regression tests ensure that no secondary effects are introduced into the features of an application when the code changes, or when new features are introduced into the application. Automated tests make these types of tests easier to run, saving time when new versions need to be released.

Compatibility tests guarantee that a web application meets the performance requirements for the different combinations of operating systems and browsers. Selenium automated tests make these types of tests much easier because Selenium supports many different browsers and operating systems.

The aim of end-to-end tests is to verify that all points of contact within an application work correctly. For example, the tester could write a series of test cases to verify that the search, recording, payment, and query functions for a product work as expected (and fail when invalid values are entered in the corresponding fields).

Why automate tests with Selenium?

If tests are executed frequently and repeatedly, it is a good time to start evaluating the need of implementing automated tests. It is also the case when it takes too long to perform them manually. That is when users should consider automating using the Selenium testing tool.

As mentioned above, there are many advantages of using Selenium when implementing automated tests: there are no licenses or costs when using it, the tool imitates user actions, it is easy to implement, there are different tools for every scenario, it supports different programming languages, it is compatible with other frameworks, code can be reused and there is quite a large community for support.

How to choose the right Selenium tool

Given that there are several Selenium tools and components, making a decision about which tool to use might not be as easy as pie for new users. In the following section, you will find a short guide that will help you correctly choose the Selenium components to use for each one of your needs:

Selenium IDE

  • If you have no previous programming or test automation knowledge.
  • To create simple test cases and test suites, which can then be exported into Selenium WebDriver.
  • To execute custom JavaScript code using runScript.
  • To test a web application only for Firefox and Chrome.
  • To export a test script into several programming languages.

Selenium WebDriver

  • If you need to use a specific programming language for your automated test cases.
  • To test applications and generate custom reports in an HTML format.
  • If you want to test web applications with dynamic data.
  • If you want to test applications with AJAX-based features.
  • If you want to test applications on different platforms using Selenium Grid or test CI/CD applications.

Selenium Grid

  • If you need to execute automated test cases on different browsers and operating systems simultaneously.
  • If you need to execute a very large test suite in the least amount of time.

Example of a Selenium automated test case

Let’s suppose you want to manually test a scenario in which you will need to verify a registration page for users on a web application. You will need to validate the input fields and the successful registration of a user.

1. Enter the URL in the address bar.

2. Enter invalid data in each input field (email address, username and password).

3. Verify whether the entries were validated against the corresponding regular expressions and any pre-existing values in the database.

4. Enter valid data for each input field, click on “Register”.

5. Verify whether or not the Welcome screen was displayed with the username.

6. Tag the test as “approved” if it did, and “failed” if the registration function was interrupted at any point during the test.

This is a very common system test, and it is very likely that testers verify every possible flow while searching for errors with every operating system combination and in as many browsers as necessary.

Depending on the number of manual testers and the level of details for each test, the task can take several days or weeks in order to ensure that the application is functional.
Therefore, when faced with these types of tests and the need to perform them repeatedly, it is time to start using Selenium automated tests.

In Summary

Selenium is a very complete test automation tool for web applications, since there are multiple features that cover most of the crucial needs of users who want to automate tests.

In order to meet these needs, Selenium has a set of tools such as Selenium IDE, Selenium WebDriver, and Selenium Grid, and each of those tools have their own characteristics, and can be used individually or by combining them.

In addition, one of the main features why Selenium stands out is because of its wide coverage and its support of several programming languages, operating systems and browsers.

Using Selenium testing tool makes creating and executing functional tests much easier, which in turn improves the quality of web applications.