Selenium 4 is released! What must every QA know?
Back in August of 2018, the whole Test-automation community had been struck by the big news: Simon Stewart, the founding member of Selenium, had officially confirmed the release date and some of the major updates for Selenium 4 at the Selenium Conference in Bangalore.
Why Selenium 4.0 is important
A perfect example of such codeless automation software is CloudQA. On top of Selenium, we’ve developed a tool that requires zero effort from the team, integrates with the third-party applications, makes building test cases easier than ever before, monitors your web page performance 24/7, and costs less than hiring a junior manual tester.
If you want to learn more about the benefits of Selenium-based codeless automation tools, get a free demo.
Now, Let’s look at some of the new and exciting features Selenium 4.0 has to offer.
Selenium 4 major changes
W3C Web Driver Standardization
First of all, Selenium 4 WebDriver is completely W3C Standardized. The WebDriver API has grown to be relevant outside of Selenium and has been used in multiple tools for automation. For example, such mobile testing tools as Appium and iOS Driver heavily rely on it. The W3C standard will also encourage the compatibility across different software implementations of the WebDriver API.
Here’s how Selenium Grid communicates with the Driver executables in previous versions:
A test in Selenium 3.0 communicates with the browser at the End node through the JSON wire protocol at the local end. This approach requires encoding and decoding of API.
With the updates we’re expecting to see in Selenium 4, the test will directly communicate without any encoding and decoding of API requests through W3C Protocol. Although JAVA bindings will be backward compatible, the focus will remain more on the W3C Protocol. The JSON wire protocol will no longer be used.
There are multiple contributors to the W3C WebDriver specs, and the whole process can be seen on GitHub.
Selenium 4 IDE TNG
The Selenium IDE support for Chrome is available now. You can download it from- https://selenium.dev/selenium-ide/
As we all know that Selenium IDE is a record and playback tool. It will now be available with the following, much richer and advanced features:
- New plug-in system. Any browser vendor will now be able to easily plug into the new Selenium IDE. You’ll be able to have your own locator strategy and Selenium IDE plug-in.
- New CLI runner. It will be completely based on NodeJS, not the old HTML-based runner, and will have the following capabilities:
- WebDriver Playback. The new Selenium IDE runner will be based entirely on the WebDriver.
- Parallel execution. The new CLI runner will also support parallel test case execution and will provide useful information like time taken, and the number of test cases passed and failed.
Improved Selenium Grid
Anyone who has ever worked with Selenium Grid knows how difficult it is to set up and configure. Selenium Grid supports test case execution on different browsers, operating systems, and machines providing parallel execution capability.
There are two main elements of the Selenium Grid: Hub and Node.
Hub acts as a server, a central point to control all the test machines in the network. In Selenium Grid there is only one hub that allocates the test execution to a particular node based on capability matches.
Node, in simple words, is a test machine where test cases actually run.
Until now, the setup process of the Selenium Grid has often caused testers difficulties with connecting a node to the hub.
In Selenium 4, the grid experience has become smooth and easy since there will no longer be any need to set up and start hubs and nodes separately. Once you start a Selenium server, the grid will act as both a hub and node. It also supports a fully distributed mode, for use in modern infrastructure running Kubernetes. The new Selenium grid comes with improved security as part of the infrastructure.
The Selenium grid has an updated UI placed on top of a GraphQL model that is accessible to everyone. VNC previews are now available so that you can get a feel of what’s happening inside a running session. OpenTelemetry support has also been integrated into the Grid, so now you can find out exactly what’s going on, where, and when.
For more details on Selenium Grid, we suggest checking out the selenium grid.
Selenium provides three types of grid-
- Standalone Mode
- Hub and Node
- Fully Distributed
The new selenium server jar contains everything which is required to run a grid. It has all the dependencies. The new grid also comes with Docker Support. For now, the docker integration doesn’t make use of UNIX domain sockets, so ensure your docker daemon is listening on port 2375.
For more details, refer to- https://github.com/SeleniumHQ/seleniumhq.github.io/commit/82a548054e6ce3c486b98929ff6e4e4fa205d71a
“Passive observability is the ability to do descriptive tracing.”
– Simon Stewart
Observability, logging, and debugging are no more confined to DevOps now. As part of the release, the request tracing and logging with hooks is improved to provide automation engineers a hold on debugging.
Documentation plays a key role in the success of any project. Selenium docs have not been updated since the release of Selenium 2.0. Meaning, that anyone trying to learn Selenium in the past several years, had to use the old tutorials.
So, naturally, the renewed and up-to-date documentation, which SeleniumHQ provides us along with the 4.0 version, has become one of the most important Selenium updates within the testing automation community.
Improvements in Selenium 4.0
ChromiumDriver and DevTools:
In Selenium 3, EdgeDriver and ChromeDriver have their own implementation inherited from RemoteWebDriver class. In Selenium 4 Chromedriver and EdgeDriver are inherited from ChromiumDriver. ChromiumDriver class has predefined methods to access the dev tools. Consider the below code snippet-
DevTools can also be used for performance measurement and to get page load time.
Better Window and Tab Management
newWindow() method opens a new window or tab based on the WindowType given in its parameter.
In Selenium 4, there are “relative locators“. that can allow users to specify where on-page elements are found near a specified element with a more human-friendly language.
As an example, “above that element” can be used for specifying an element that is placed on top of the specified element.
- toLeftOf-toLeftOf() : Element located to the left of specified element.
- toRightOf-toRightOf() : Element located to the right of the specified element.
- above-above() : Element located above the specified element.
- below-below() : Element located below the specified element.
- near-near() : Element is at most 50 pixels far away from the specified element. The pixel value can be modified.
Now we can take full page screenshots with getFullPageScreenshotAs() method in Firefox. But instead of typecasting it to the ‘TakesScreenshot’ interface, we need to typecast it to the FirefoxDriver instance.
File src = ((FirefoxDriver) driver).getFullPageScreenshotAs(OutputType.FILE);
Firefox and Chromium Users
There might be some more interesting features and improvements, so go ahead and explore!
Faster Test Automation with Codeless Selenium