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?
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.
Features of Selenium 4
Selenium is now W3C compliant
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.
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.
- 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
- 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
- Distributed : On Distributed mode, each component needs to be started on its own. This setup is more suitable for large Grids.
- Event Bus: serves as a communication path to other Grid components in subsequent steps.
java -jar selenium-server-4.0.0.jar event-bus
- Session Map: responsible for mapping session IDs to the Node where the session is running.
java -jar selenium-server-4.0.0.jar sessions
- 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
- 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
- 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
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.
|above||The required WebElement is ‘above’ a specified (or particular) element.|
|below||The required WebElement is ‘below’ a specified (or particular) element.|
|to_left_of||The required WebElement is ‘to the left of’ a specified (or particular) element.|
|to_right_of||The required WebElement is ‘to the right of’ a specified (or particular) element.|
|near||The 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.
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.
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 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.