Selenium is the most popular tool suit when it comes to automated cross-browser testing of website applications. Moreover, the creator of WebDriver and Core Contributor to Selenium projects, named Simon Stewart, publicly introduced Selenium 4 in 2018.
Since then, the new version of Selenium has been gaining a lot of attention for Selenium Testing Services because of its latest features and functionalities. Furthermore, the good news is that the Beta Version of Selenium 4 is available on the official website that you can check and download to get started with it.
Are you ready to learn what’s new in Selenium Version 4? Sounds great! Let’s first understand its basics.
When you think about “Selenium,” what is the first thing that comes in your mind? Because most people, when they hear about Selenium, they first think about Selenium WebDriver, and it truly happens with many of them, and maybe you also think the same.
However, there are two pieces that help make up the Selenium Test Project, these are Selenium IDE and Selenium Grid. Knowing about bits and pieces that help make up the Selenium Automation Testing is necessary because this process will help you understand the 4th version of Selenium and get a new approach to automated testing.
Let’s read a bit about Selenium WebDriver, Selenium IDE, and Selenium Grid below:
So, Selenium WebDriver is an open-source API that lets you interact with a browser on a computer in the same way as a human user would. It was built mainly for browser automation.
Selenium IDE is the most famous record and playback automation tool. Whereas Selenium Grid helps you save time by distributing your tests across various machines.
Now, it is high time when we understand – What is new in Selenium 4?
Selenium 4 is a loaded Selenium Testing Framework with excellent features like improved Selenium Grid architecture, relative locators, and a very super-useful Selenium IDE.
One of the most significant under-the-hood changes in Selenium 4 is W3C compliance of WebDriver APIs, which correlates to less flaky and more stable cross-browser tests.
Explore the best of Selenium 4 with automation testing experts!
Turn Chances To Opportunities With BugRaptors…
Here are some of the common changes that you will experience while using Selenium 4:
In Selenium 3, which was the earlier version of Selenium, the JSON Wire Protocol was responsible for maintaining the conversation or communication between the web browser and the test code.
As a result, the API queries had to be encoded and decoded using the W3C protocol, which was a complex task and a very time-consuming process. This will change in Selenium 4 with WebDriver, as in this version, the WebDriver APIs will follow the W3C standardization.
Browser drivers like Chromedriver, geckodriver will follow the W3C standard, which is the Webdriver in Selenium 4, and it will make direct communication with web browsers.
Furthermore, the Selenium Versus WebDriver W3C protocol goes hand-in-hand with JSON Wire Protocol. And, you will find it as the default protocol in Selenium 4 because JSON Wire Protocol will be discarded in the new version of Selenium.
Also, the native support for Opera and PhatomJS is eliminated in Selenium 4 because there is no need for WebDriver implementations under development.
The reason for this is that the Opera Browser is based on Chromium, and the people who are planning to test their implementations on Opera cannot choose it for testing with selenium on the Chrome Browser. On the other hand, PhantomJS users have the option of testing in headless mode on Firefox and Chrome.
Thus, WebDriver W3C Protocol is the biggest architectural change that you can experience in Selenium 4. As a result, WebDriver W3C standardization offers stability for cross-browser testing compared to the previous releases of Selenium.
The Selenium Grid that you use for distributing test execution is based on the Hub-Node architecture. Therefore, there is an urge to separate the Hub and Node(s) while performing the automation tests because the Hub and Node are combined into a single jar file. And, after the starting of the server, it acts both as Hub and Node.
Furthermore, the earlier releases of Selenium Grid 4 offered support for Router, Distributor Processes, Session Map, and more. Due to the more scalable and traceable infrastructure, the Selenium Grid 4 provides support in four processes such as Router, Session Map, Distributor, and Node.
This Grid will now support IPV6 addresses and help users to communicate with the Grid using the HTTPS protocol. Therefore, the configuration of files with the improved Selenium Grid is much easier because users can easily configure the Grid using the human-understandable Tom’s Obvious Minimal (TOML) language.
Besides, the Grid in Selenium 4 has a user-friendly graphical user interface, and the Docker compatibility in Selenium Grid 4 makes it possible to use on Virtual Machines.
Plus, users can have flexible options to deploy the Selenium Grid on Kubernetes. Moreover, you can leverage Selenium Grid 4 in the DevOps process since it supports tools like Azure, AWS, and more.
The Selenium IDE is ubiquitous for Automation Test Engineers because they know how to perform record and playback testing with it.
It is one of the best solutions that are available for web testing and helps you get out-of-the-box results. But the earlier available Selenium IDE that works only on Firefox extension doesn’t have exciting features to use.
With Selenium Version 4, the Selenium IDE can become a useful solution for major browsers like Firefox and Chrome. In addition, the web extension or plugin for Selenium IDE is forecasted to come soon on the MS Edge Store.
Since we have received the exhausted official documentation of Selenium 4, the content layout will make it easy for you to obtain the desired information in a few clicks.
Besides, you need to understand the Selenium 4 is in the Alpha stage, which means you will get improved documentation to know how new APIs and features in Selenium 4 works and how you can use them in the test code.
Into the bargain, there are various aspects of Selenium Grid 4 and WebDriver W3C Protocol cover in Selenium 4 Documentation. Similarly, being an automation tester of the Selenium Automation Testing Company, you can use the documentation to be familiar with the new APIs offered by Selenium 4.
The team finally eliminated a number of methods you were previously warned about. This cleanup job is much needed for a long time. However, the pretty great news is that from driver’s interfaces, classes to methods code base have been thoroughly cleaned up.
For instance:
The replacement of iterations keyboard has done with Actions and KeyInput instead. All the changes list you can directly check in the official documentation. If you are worried about how you will manage everything after replacing some things, then there is no need to worry because Selenium did focus on maintaining backward compatibility with legacy versions.
This means you can easy to add the latest version into your old tests and work smoothly if some methods were deprecated by the team. Rest, the better experience you can get while implementation or using Selenium Version 4.
It is one of the most amazing functionalities of this new release and renowned as Relative Locators that you can use for Automation Scripting. You may know about locators due to their existence in Selenium for many years, finding by link text, XPath, CSS Selectors, and so on.
The problem with locators is that it requires you to study a lot about the page's structure, and you must know how the DOM itself is arranged.
Sometimes, using locators becomes a more challenging task due to the requirement of a human language. Yet, you don’t need to worry because relative locators also come to reduce your stress.
Since this is the approach in which you tell Selenium about the element that is needed to interact based on its position relative to other web elements using a fairly human-readable syntax.
Also, these concepts are part of test automation for a long and may come in vendor tools like Quick Test Professional. And, these concepts are part of many other open-source and free automation frameworks such as Taiko and Sahi.
Additionally, you will be glad to know that finally, it is a part of your Selenium. If you have attended any conferences for automation, you may know some best approaches to find tricky web elements. The locator-strategy techniques include very complex CSS, XPath, or stacking uploads of distinct locators.
For instance, the syntax for New Relative Location is as follow:
//import static org.openqa.selenium.support.locators.RelativeLocator.withTagName; WebElement passwordField= driver.findElement(By.id("password")); WebElement emailAddressField = driver.findElement(withTagName("input") .above(passwordField));
//import static org.openqa.selenium.support.locators.RelativeLocator.withTagName; WebElement emailAddressField= driver.findElement(By.id("email")); WebElement passwordField = driver.findElement(withTagName("input") .below(emailAddressField));
//import static org.openqa.selenium.support.locators.RelativeLocator.withTagName; WebElement cancelButton= driver.findElement(By.id("cancel")); WebElement submitButton= driver.findElement(withTagName("button") .toRightOf(cancelButton));
In this syntax, Relative Locators is an effort to encapsulate this strategy in code. To find the elements, you can say “find elements,” and tell “what kind” of element are you looking for?
For example, search an input element “above here,” and “low here,” or you can find an input element “to the right of this,” and it will consider all filters and say, “Okay, this is the element you want or searching for. This one is a unique advantage that you can acquire to find elements using a more human language.
So, this approach is not much complicated. Nonetheless, if you don’t know about the box model and don’t have familiarity with Selenium automation testing, then you need to learn to load up your test case with these friendly locators.
Most of the time, you can get the exact things from WebDriver that you want to do. However, if you fail to achieve the best response from WebDriver, then it can happen due to the instructions in which your computers are good at, but people don’t like them.
It is another feature that people usually love to talk about when it comes to tools like Cypress.io and when taps into the Chrome DevTool protocol debugging info. In fact, you need to understand that it comes with many features that are based on the current debugging protocol.
And, the best part is Selenium is now a new feature across the chrome Browser DevTools debugging protocol. Similarly, this is the Chrome Debugging Protocol, also defined as CDP, is a low-level protocol used by debugging tools to communicate with Chrome.
Moreover, it acts almost like a machine code. For example, below, we’ve given a code that you may want to write.
package main import (
"context"
"fmt"
"io/ioutil"
"log"
"time"
"github.com/mafredri/cdp"
"github.com/mafredri/cdp/devtool" "github.com/mafredri/cdp/protocol/dom" "github.com/mafredri/cdp/protocol/page" "github.com/mafredri/cdp/rpcc"
)
func main()
{
err := run(5 * time.Second) if err != nil { log.Fatal(err)
}
}
func run(timeout time.Duration) error
{
ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() // Use the DevTools HTTP/JSON API to manage targets (e.g. pages, webworkers).
devt := devtool.New("http://127.0.0.1:9222")
pt, err := devt.Get(ctx, devtool.Page)
if err != nil
{
pt, err = devt.Create(ctx) if err != nil { return err }
}
Many of you don’t like to follow this approach, but you have to choose when there is no other option left in your hand. As a result, popular libraries wrap the underlining protocol in a more user-friendly syntactic layer.
On the other hand, tools like Puppeteer don't' utilize raw Chrome Debugging Protocol (CDP): Since it has developed a user-friendly API layer on top of the raw CDP for easy interaction. However, the problem with this tool is it uses only JavaScript language.
Suppose if you have a choice of using a different language. In that case, what you will do if the tool is not making according to your preferred language. Are you able to learn different programming languages? If not, you may not use the Chrome Debugging Protocol directly as it is completely written in a machine language. Similarly, you may not like to write code that requires the direct WebDriver Protocol.
However, you will be happy to know that the Selenium Contributors provides ease in version 4 and take some common use cases in it and implemented them on the top of the CDP, which only use friendly APIs that feel Selenium-ish and can be utilized with any of its language bindings.
Now it’s time to compare the Selenium CDP GeoLocation code snippet with the raw CDP syntax that you saw above in our blog.
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
public void geoLocationTest(){ ChromeDriver driver = new ChromeDriver();
Map coordinates = new HashMap()
{{
put("latitude", 50.2334); put("longitude", 0.2334); put("accuracy", 1); }};
driver.executeCdpCommand("Emulation.setGeolocationOverride", coordinates); driver.get("
In comparison to the previous CDP code, this code seems very easy to read and write. Thus, this is the big difference that you can experience in Selenium 4 compared to its old versions.
One of the main benefits of the Selenium 4 is it allows you to run a test with the previous and latest versions of Chrome, including the latest and old versions of Edge and many other browser vendor versions. Thus, your tests will work smoothly and as per your expectations, and the great thing is you need to download them while using a new version of the API or browsers. Also, it gives you access to use crucial test information around security and performance. There are some best Chrome Development Properties that you can explore below and capture in your tests:
Application Cache
Fetch
Network
Performance
Profiler
Resource Timing
Security
Target CDP domains
In order to grow with Software testing trends, the developers have also included a technology called Open Telemetry into the new grids, which you can consider for distributed tracing.
Furthermore, the open telemetry data can be consumed by other tools that support Open Telemetry, such as Honeycomb, Jaeger, Datadog, and others.
If you're a sysadmin, you'll appreciate this because you can simply integrate it into your existing infrastructure and even figure out what's going on and obtain some insight into what's going on in the Grid. Also, if you need more transparency while running Selenium Grid Tests, you can easy to have it.
In the Grid, you can find a new and innovative front-end console, which is driven by a GraphQL endpoint. Furthermore, you can efficiently run your GraphQL query against the Selenium Grid either in your local machine or in a distributed way. Not only this, but also, it allows you to extract a whole bunch of useful information.
Below is the syntax that you can check to run your query of each node in the grid using the new GraphSQL API.
curl -X POST -H "Content-Type: application/json" --data '{"query": "{ grid { nodes { status } } }"}' -s
According to Simon, if you want to gain maximum benefit from automation efforts, you should remember the test pyramid. If you have several small tests, integration tests, techniques, and end-to-end selenium tests, you are doing it well.
However, if you have hundreds of thousands of end-to-end tests and five-unit tests that you need to run using the Selenium testing framework, you can face pain.
Suggested Read: Case Study on Social Media Platform Testing Using Selenium
Are you interested in learning the deepest secrets of Selenium 4, or do you need any help with Selenium Automation Testing? Then Talk to our experts at BugRaptors.
We are the leading software testing company with great expertise in using Selenium and are very well acquainted with all versions of Selenium, including Selenium 4, and the know-how to test a web application ideally using Selenium.
For more information, you can instantly connect with us and let us know your requirements.
Interested to share your
Read More
BugRaptors is one of the best software testing companies headquartered in India and the US, which is committed to catering to the diverse QA needs of any business. We are one of the fastest-growing QA companies; striving to deliver technology-oriented QA services, worldwide. BugRaptors is a team of 200+ ISTQB-certified testers, along with ISO 9001:2018 and ISO 27001 certifications.
Corporate Office - USA
5858 Horton Street, Suite 101, Emeryville, CA 94608, United States
+1 (510) 371-9104Test Labs - India
2nd Floor, C-136, Industrial Area, Phase - 8, Mohali -160071, Punjab, India
+91 77173-00289Corporate Office - India
52, First Floor, Sec-71, Mohali, PB 160071,India
United Kingdom
97 Hackney Rd London E2 8ET
Australia
Suite 4004, 11 Hassal St Parramatta NSW 2150
UAE
Meydan Grandstand, 6th floor, Meydan Road, Nad Al Sheba, Dubai, U.A.E