selenium 4

When it comes to testing web applications, Selenium is without a doubt the most popular test automation tool. Since Simon Stewart announced Selenium 4 in 2018, it has been the buzz of the town. It has been a long time, and it has finally launched on October 13, 2021. In the latest edition, there are a slew of new features and adjustments to look forward to. Let’s go through all you need to know about Selenium 4 in this article.

In this post, you will learn about the following topics:

What’s new in Selenium 4?

The first and most significant change is that the Selenium project has migrated to the W3C protocol and will no longer use the JSON wire protocol. Because all contemporary browsers are W3C compliant and there are no compatibility issues, this adjustment was made. Apart from that, there have been a number of modifications to Selenium Grid, CDP Integration, New Locator Strategy, and improvements to Selenium IDE.

How to get Selenium 4?

If you’re new to Selenium, make sure you have Java installed and that the JAVA HOME environment variable is set before you begin.

The Selenium 4 jar files can be downloaded from the official Selenium download website. Select the appropriate WebDriver Language Bindings to download. This page contains links to download Selenium Grid and Selenium IDE.

LanguageDownload Link
Javahttps://github.com/SeleniumHQ/selenium/releases/download/selenium-4.1.0/selenium-java-4.1.0.zip
C#https://www.nuget.org/api/v2/package/Selenium.WebDriver
Rubyhttps://rubygems.org/gems/selenium-webdriver/versions/4.1.0
Pythonhttps://pypi.python.org/pypi/selenium
JavaScripthttps://npmjs.org/package/selenium-webdriver

Features of Selenium 4

Selenium is now W3C compliant

World Wide Web Consortium - Wikipedia

Selenium 4 is now W3C compliant, as previously stated. With webDriver w3c protocol, you can get more reliable, stable, and less flaky test automation. In Selenium 4, the JSON wire protocol is totally replaced by the W3C protocol. The good news is that you may already be using the W3C protocol. This is due to the fact that the WebDriver W3C protocol has been available in Selenium since version 3.8.

Improved Selenium Grid

Selenium Grid is a distributed test execution platform that uses a Hub-Node design. Selenium Grid in Selenium 4 has a more user-friendly interface. It also works with DevOps processes and tools like as Azure, AWS, and others.

Instead of building up virtual machines, you can now easily spin up docker containers for your test run using Docker Support. It has also been rebuilt to allow QAs to deploy the grid on Kubernetes for better scaling.

See also  Most Popular 40 Selenium Interview Questions With Answers

The Grid will now support IPV6 addresses, and users can communicate with the Grid using the HTTPS protocol. grid instances can be written in TOML (Tom’s Obvious, Minimal Language) which will make it easier for humans to understand.

Grid can be used in three different ways. You will be able to handle easier than in previous versions, where you had to set up and start hubs and nodes independently.

  1. Standalone : Standalone is the sum of all components, and it seems to the user that they are all being executed as one. After launching it in Standalone mode, you’ll have a fully functional Grid of one. Standalone is also the quickest way to get a Selenium Grid up and running.
java -jar selenium-server-4.0.0.jar standalone
  1. Hub and Node : It enables the classic Hub & Node(s) setup. These roles are suitable for small and middle-sized Grids.

java -jar selenium-server-4.0.0.jar hub

java -jar selenium-server-4.0.0.jar node

  1. Distributed : On Distributed mode, each component needs to be started on its own. This setup is more suitable for large Grids.
  1. Event Bus: serves as a communication path to other Grid components in subsequent steps.
java -jar selenium-server-4.0.0.jar  event-bus
  1. Session Map: responsible for mapping session IDs to the Node where the session is running.
java -jar selenium-server-4.0.0.jar sessions
  1. New Session Queue: adds the new session request to a queue, then the distributor processes it.
java -jar selenium-server-4.0.0.jar sessionqueue
  1. Distributor: Nodes register to it, and assigns a Node for a session request.
java -jar selenium-server-4.0.0.jar distributor --sessions http://localhost:5556 --sessionqueue http://localhost:5559 --bind-bus false
  1. Router: the Grid entrypoint, in charge of redirecting requests to the right component.
java -jar selenium-server-4.0.0.jar router --sessions http://localhost:5556 --distributor http://localhost:5553 --sessionqueue http://localhost:5559
  1. Node(s)
java -jar selenium-server-4.0.0.jar node 

Relative Locator Strategy

New more friendly locators based on the visual representation of DOM are introduced as Relative Locators.

aboveThe required WebElement is ‘above’ a specified (or particular) element.
belowThe required WebElement is ‘below’ a specified (or particular) element.
to_left_ofThe required WebElement is ‘to the left of’ a specified (or particular) element.
to_right_ofThe required WebElement is ‘to the right of’ a specified (or particular) element.
nearThe required WebElement is ‘at most 50 pixels’ away from the specified (or particular) element.

The idea behind this strategy is that it allows you to find things by describing them on a page. “Find the element that is underneath the image,” rather than “find the INPUT inside the DIV with the ‘id’ of’main,'” is more natural. In general, you may consider of them as a technique of locating elements on a page based on their visual placement.

See also  Best IDEs for Selenium with Java to use in 2024

Chrome Debugging Protocol Integration

Selenium 4 has support for the Chrome DevTools Protocol. This allows for more efficient testing and resolution of critical faults on specific pages. You can use this to conduct geolocation settings as well.

Easier Window/Tab Management

Selenium 4 includes a new API called newWindow, which allows you to build and switch between new windows or tabs. Previously, you had to build a new driver object and then use the WindowHandle function to complete the process. You can now transition to a different window or tab without having to create a new driver object.

Example : Switch to a new window

driver.get("https://www.google.com/");
driver.switchTo().newWindow(WindowType.WINDOW);
driver.navigate().to("https://www.automated-360.com/");

Example : Switch to a new tab

driver.get("https://www.google.com/");
driver.switchTo().newWindow(WindowType.TAB);
driver.navigate().to("https://www.automated-360.com/");

Selenium IDE 4

Selenium IDE is the most popular recording and playback tool in the Selenium suite. Selelnium IDE for Firefox, Chrome, and Edge is now available.

Selenium IDE has a user-friendly interface that makes it easier to use. It includes the Selenium IDE command line runner, which allows you to run Selenium IDE tests in any browser, in parallel, and on a Grid without having to write any code.

Selenium IDE

The control flow structure in Selenium IDE is made up of commands like if, while, and times. It now records multiple locations for each element, so that if one locator fails, the other is used.

The code for Selenium IDE-recorded test cases can be exported in any language binding, including Java, C#, Python,.NET, and JavaScript.

Selenium IDE Test Export
image 4

Revamped Documentation

The documentation has been considerably redesigned, with a user-friendly interface for navigating to the relevant section or page. This will make it easier for testers and developers to access the information they need for a particular tool, language binding, or another project.

To summarise, these significant Selenium 4 improvements appear to be pretty promising and will undoubtedly make your tests easier than ever. I hope this has been of assistance to you.

Check out Selenium 4 – New Features Bootcamp on Udemy

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.