What is Selenium 4? The latest in Selenium Automation Testing for browsers
Introduction
Every business needs an effective software testing strategy to develop high-performing quality products in less time. Software automation testing has become feasible with the help of Agile and DevOps technologies. The introduction of reusable test suites and robust automation frameworks make the testing process quicker. We all know that Selenium is a widely used tool for cross-browser web automation testing. It has proven to be one of the most preferred stable tools for any development pipeline. With the release of the beta version of Selenium – Selenium 4, automated Selenium testing has become stronger and more reliable than ever before.
The official release of the new Selenium 4
The official release of the initial Alpha version (4.0.0.alpha1) of Selenium 4 was announced in May 2019. In June 2021, the beta version (4.0.0.beta4) with the latest driver was released, and finally on October 13, 2021, Selenium 4.0 was officially released. The latest updated version 4.1.0, was released on November 22, 2021.
The release of Selenium 4 was already announced back in August 2018 by the founder, Simon Stewart. He introduced the new version not only for web drivers but also for the Grid and IDE. You can download Selenium 4 from GitHub or the Official Selenium website. It covers Java, .Net, Python, Ruby, and JavaScript programming languages.
There is no doubt that Selenium automation testing has become a standard for the software industry and Selenium is a go-to tool for web app testing. This new update of Selenium is not only a game-changer for the test automation engineers but also for those who rely on Selenium for codeless automation testing when there is a lack of in-house QA expertise to implement it. Selenium not only eases deployment for testers with limited knowledge about web browsers but also enables them to run regression tests, load testing, synthetic monitoring, etc., even with no knowledge.
What are the new Selenium 4 features?
Selenium 4 is the all-new approach to automation testing. Before jumping on to the latest version and how it has raised the bar of selenium test automation. Let’s briefly understand the major components of Selenium 4.
Selenium WebDriver– It is a web framework or API that allows you to interact with the web browser, automate web applications and verify their performance. It allows you to choose from the available programming languages to create test scripts.
Selenium IDE and Selenium Grid: Selenium IDE is a record and playback automation tool used to create selenium test cases whereas, Selenium Grid is a tool that helps save time by distributing tests across multiple virtual and physical platforms.
What is new in Selenium 4?
Selenium has evolved over the years and has released its latest stable version, Selenium 4. Let’s take a look at what is new in Selenium 4.
W3C standardization
Selenium 4 has adopted the W3C (World Wide Web Consortium) standard Web Driver Protocol for a more stable cross-browser testing. All the browsers like Google Chrome, Safari, IE are already compliant with the W3C standard. The interaction between the web browser driver and Selenium Web Driver will be based on W3C standard protocol.
Selenium 4 features have been enhanced and it now has an improved Selenium Grid Architecture, relative locators, improved Selenium IDE, etc.
The figure below shows a Selenium 3 scenario where the communication between a web browser (at End Node) and a Selenium 3.0 Test happened through JSON Wire protocol (at Local End). Selenium 3 requires encoding and decoding of the API, which ultimately became a very time-consuming process. Selenium 4.0 changed this scenario by facilitating direct communication and abolished the need for encoding and decoding of API by following W3C standardization.
Selenium 4 has browser WebDrivers like Chromedriver, Geckodriver that follows W3C standards to communicate with web browsers, leaving JSON wire protocol to be discarded.
But there’s nothing to worry about. It is not a change of concern for existing users as most of the Browser Drivers have already been able to transition smoothly from Selenium 3 to Selenium 4 by adapting to W3C standard protocols. Furthermore, this architectural improvement has made Selenium 4 a much more stable and efficient test automation tool. Here’s how Selenium with JSON wire Protocol(A) and the improved Selenium with JSON wire Protocol Removed(B) look like:
Selenium 4 IDE Enhancements
Selenium IDE record and playback tool will now have many improved features such as:
- New Plug-in system allows any browser vendor to easily plug into the new Selenium 4 IDE, with its locator strategy and Selenium IDE plugin.
- The New CLI runner (Selenium-side-runner) will not have a HTML based runner but will be entirely based on NodeJS. It will also allow parallel test case execution and key metrics on the total tests executed, test-run time and test PASS / FAIL status.
- It allows easy code export of the recording in the desired official language bindings such as Java, Python, JavaScript, .Net & Ruby.
- Earlier, Selenium IDE only supported Firefox, but now Selenium 4 is available for even Chrome and might come for MS Edge as well, as forecasted.
- New element location feature allows locating indistinguishable elements within the web pages; this helps in stable targeted tests.
- There have been some improvements in the flow control so that the users can establish better conditional statements in test cases.
Optimized Selenium Grids
Selenium Grid was launched long back and its users must be aware of how complicated it was to install and configure. With Selenium 4 these issues no longer persist. The new features of Selenium 4 provide stability, improved UI and solve problems related to Hub-Node connection. Hub and Node are the two main elements of Selenium Grid. Look at the diagram below to understand the connection.
In Simple terms, Selenium Hub is a server-like central point that controls all the test machines within its network. Selenium Grid has only one hub to assign the test execution task to a specific node. A Node is simply a test machine that performs the actual tests. There can be multiple nodes in a grid that are used to execute tests on an individual system.
-Until now, testers faced problems connecting a node to the Hub, but with Selenium 4, these experiences have become smooth and easy. Because now, it no longer needs to be set up to start nodes and hubs separately. Now, the Selenium Grid itself acts as both a Hub and Node. It now allows running test cases for different browsers, browser versions and operating systems parallelly.
-The New Grid comes with improved security features as a part of its infrastructure.
-It also provides easy access to the updated UI atop the GraphQL model. The upgraded UI provides information about the session capacity, running time, etc.
-Selenium 4 now has Refreshed Documentation with information on the new APIs and how to use them in the test code with fewer clicks.
-Improved observation and monitoring introduced; improved logging and request tracing processes fastening the debugging process for resolving the script issues easily.
-Virtual Network Computing previews of running sessions are also available to understand what happens while the session is running.
-The Grid also integrates Open Telemetry support to figure out what is happening exactly and where and when it happened.
-It supports fully distributed mode for infrastructure that runs Kubernetes (Kubernetes for self-healing and better scaling)
-Selenium provides standalone mode, fully distributed mode and Hub & Node types of the grid. The new Selenium 4 comes with Docker support to accelerate containers instead of installing heavy VM.
-Supports advanced platforms like AWS, Azure and helps in the DevOps process.
Addition to Relative Locators
Selenium locators are also known as Friendly locators that allow locating Elements located near/concerning the location of other web elements on the page (or based on GUI location). Selenium 4 has the following additional locators:
-above() – to locate web elements just above the specified element
-below() – to locate web elements just above the specified element
-toLeftOf() -to locate web elements existing on the left of the specified element
-toRightOf() -to locate web elements existing on the right of the specified element
-near() -to locate web elements existing (near) at approximately fifty pixels away from the specified element. Users can always modify the pixel value as per need.
Better Window and Tab Management
With Selenium 4, users can now open a new window and a new tab on the same browser in the same session. It has a newWindow method to create new windows or switch between the tabs without creating any separate WebDriver objects.
Full-Page WebElement snapshot
Selenium 4 allows capturing screenshots at element, section and full-page levels of UI. It enables taking full-page screenshots of individual WebElement with the getFullPageScreenshotAs() method in Firefox. Selenium 3 allowed taking a screenshot but not for specific web elements.
Source: https://www.softwaretestingmaterial.com/selenium-4/
Chrome Driver and Dev tools:
The new version of Selenium provides native support for Chrome DevTools protocol to use native Chrome Dev Tools like profiler, network monitoring, security, fetch, caching, resource timing, etc. These tools allow users to perform network performance simulations and geolocation testing while solving bugs. The Chromedriver extends to Remote WebDriver Class in Selenium 3, but with Selenium 4, the Chrome driver class extends to Chromium Driver.
Conclusion
Selenium automation testing with Selenium 4 has experienced a great architectural shift with some beneficial enhancements, making Selenium a much stable and feature-rich test automation platform. World Wide Web Consortium compliance has made Selenium invincible. Selenium Test Automation using Selenium 4 has made it possible to manage all sorts of browser automation in the future. Selenium 4, powered by the new features and improvements, has gained user trust and confidence to use it for Selenium Automation Testing projects without the fear of the tool getting outdated.
Published on Java Code Geeks with permission by Priyanka Charak, partner at our JCG program. See the original article here: What is Selenium 4? The latest in Selenium Automation Testing for browsers Opinions expressed by Java Code Geeks contributors are their own. |