Selenium 4: New Features

Yashraj Gore
Zenitech
Published in
6 min readSep 4, 2020

Ever since the announcement by Simon Stewart, the founding member of Selenium, some of the major updates for Selenium 4 at the Selenium Conference in Bangalore, the tech community is curious to implement and try out the new features the Selenium 4 comes with. This article takes you through the various features introduced in web testing automation through Selenium 4.

Selenium 4 has introduced new changes in the following aspects:

  1. W3C WebDriver Standardization of WebDriver API
  2. Selenium IDE (The Next Generation)
  3. Selenium Grid with improved stability
  4. Chrome DevTools and ChromiumDriver
  5. Relative Locators
  6. Management for windows and tabs

Let’s get to know these changes introduced:

W3C WebDriver Standardization of WebDriver API

Selenium 4 is upgrading from JSON Wire Protocol to W3C WebDriver Protocol. This change brings standardization of W3C standards for Selenium WebDriver.

Before Selenium 4 implementation:

After Selenium 4 implementation:

The advantages this upgrade brings is:

  • It allows for communication without any encoding and decoding of API requests.
  • The seamless implementation of WebDriver across different softwares will be possible by this change.
  • The tests will be more consistent across the browsers.
  • The standard protocol will ensure that the Selenium tests are stable

Selenium IDE (The Next Generation)

Selenium IDE was implemented as Firefox AddOn which was used to record, edit and debug the Selenium Tests. Previously the Selenium IDE was available only as a Firefox extension. With the W3C standardization of IDE, it could be run in any browsers compared to the old version. The UI has been retained more or less similar to the previous version.

Selenium 4 IDE

The new features introduced in Selenium 4 for Selenium IDE are:

  • While the tests get recorded, the alternative locators too are recorded. Hence, even if the developer were to modify the element, the test would continue to pass on account of the alternative locator. This will prove more useful in terms of stability to the tests and for editing the tests.
  • The Code Export feature of the new Selenium IDE provides support to all official language bindings of Selenium such as C#, Java, JavaScript, Python and Ruby. This allows exporting Selenium IDE commands to a programming language or a test framework.
  • The new IDE comes with a “Selenium-side-runner” which runs on NodeJs. This allows the users for the execution of the recorded tests in parallel with multi-browser capability. The exported Selenium IDE tests can be executed through the command line using the Selenium side runner. It can be installed with the following command:

npm install -g selenium-side-runner

or

yarn global add selenium-side-runner

  • The Control flows have been introduced in the Selenium IDE. This gives more control over the flow of the tests using the ‘while’ and ‘if’ statements. The various flows conditionals and loop statements supported are:
  1. if
  2. else if
  3. else
  4. repeat if
  5. while
  6. times

The Selenium 4 IDE has been developed as a standalone app using Electron. It is tightly integrated with the browsers which enable better listening capabilities for the IDE and makes the test recording powerful.

Selenium Grid with improved stability

Selenium 4 has introduced the capability to support advanced tools such as docker and Kubernetes for the DevOps processes. The Docker will assist to spin up containers making the need for users to set up heavy virtual machines redundant. Users can deploy it on Kubernetes resulting in scaling and self-healing abilities.

The advantages this upgrade brings is:

  • Users can deploy the Grid in standalone, hub-node as well as in distributed mode.
  • Grid comes with the capability of distributed tracing. In a distributed system it would help in Root Cause Analysis, Optimization of Performance and dependency analysis of the services.
  • The Grid UI has been improved to be more user-friendly with relevant information in terms of test cases execution, details of the sessions and much more.

Chrome DevTools

Google Chrome comes with Chrome Dev Tools which are a set of web development tools. These are used to edit pages while they load as well as help in debugging purposes. Selenium 4 comes with support for the Chrome Dev Tools.

As you can see in the screenshot for the org.openqa.selenium.devtools package, various packages are available such as :

  • Application cache
  • Background Service
  • Console
  • Debugger
  • Inspector
  • Performance
  • Network, etc

These all packages included will contribute likewise:

  • Emulating Geo-Location, Network Responses, Network Conditions
  • Emulate the time-zone
  • Analyze performance metrics
  • Study the log messages printed to the console
  • Filter URLs among many other such functions

ChromiumDriver

Until Selenium 3 version, the ChromeDriver and EdgeDriver inherited implementations from the RemoteWebDriver. While in the Selenium 4 implementation, both the drivers extend ChromiumDriver.

ChromiumDriver class contains various methods such as getDevTools() to create connections with DevTools among several other methods.

Relative Locators

Relative Locators is a new feature introduced in Selenium 4. Earlier for writing automation tests, XPath locators and CSS based locators such as findByID. findByName, findByLinkText, etc were used. In addition to that, now we can find elements using Relative Locators using the tagname attribute of the element. They help to locate elements which are close to other ones. It would help in cases for dynamic values for elements, unstable applications, etc

Several methods help to locate close-by elements such as:

  • above()
  • below()
  • toLeftOf()
  • toRightOf()
  • near()

General Syntax:

driver.findElement(withTagName(“<insertTagNameValue>”).above(element));

Example of usage:

Management for windows and tabs

Selenium 4 provides new ways of handling the windows and tabs. We are able to navigate to two separate URLs in separate windows at the same time. The newWindow API contains the window and tab function which are similar to one another but come with a different WindowType. WindowType is basically the type of new browser window which is created upon execution.

To create a new Tab, we use WindowType.Tab while to create a new window, we use WindowType.Window as you can see in below example:

That concludes the discussion for the changes introduced in Selenium 4. Selenium 4 enhances our automation test writing experience by simplifying writing the code in several ways. You can get the latest version of Selenium here from the Maven Repository.

Additional information:

https://github.com/SeleniumHQ/seleniumhq.github.io

https://github.com/SeleniumHQ/selenium

https://www.selenium.dev/documentation/en/

--

--