Selenium 4 Improvements!

The launch of Selenium 4 on October 13, 2021, started a wave of exhilaration among testers and the developer’s community. If you are one of the community members who are willing to migrate to version 4, but still are not sure about the impact or are unable to answer the question “what problems will selenium 4 solve ?” here is a quick recapitulation for you.

# WEB DRIVERS

W3C Compliance

This means that now selenium can directly interact with the browser without the JSON wire protocol that was responsible for communicating between the browser’s native APIs and Selenium APIs. How does it help end-user you ask? Any application that is W3C standard compliant can be directly integrated with selenium, making our testing on browsers like Chrome, Edge, Firefox faster and more stable.

Relative Locators

Newly introduced locators, also known as friendly locator is my personal favorite update. This will enable users to locate elements by specifying directions. In addition to the existing 8 locators new 5 locators are :

  • above()
  • below()
  • toLeftOf()
  • toRightOf()
  • near()

Better Tab Management

We all have struggled with the problem of multiple tabs or session issues at some point or the other, with SE4 we can now open multiple windows/tabs without creating a new driver object. To open a new window/tab and switch to the window /tab now we can use syntaxes:

  • driver.switchTo().newWindow(WindowType.WINDOW);
  • driver.switchTo().newWindow(WindowType.TAB);

New APIs for Chrome DevTools Protocol

The introduction of the new class “ChromiumDriver class” will enable us to manipulate browsers and opens up a world of possibilities! With help of methods getDevTools() and executeCdpCommands() we can now simulate many scenarios. For instance:

  • Mocking of user’s geolocation
  • Network traffic can now be monitored natively
  • Option to simulate poor network strength/connection
  • Change device mode to responsive design mode

Action Class

This class is quite the popular one and kind of solves a lot of problems while automating, as it gives us the freedom to simulate input action from keyboard and mouse. In the new version, the functions have been modified making it further simpler to use.

OldNew
moveToElement(onElement).click();click(WebElement);
moveToElement(onElement).contextClick();contextClick(WebElement);
moveToElement(onElement).clickAndHold();clickAndHold(WebElement);
release() is now part of action class

# GRIDS

Grid Types

We have been running the SE grid via classical grid i.e. we were starting the hub and node separately with commands. SE4 now made our lives easier by introducing Standalone mode which configures both hub and node mode. Simply by providing the “java -jar selenium-server-4.0.0-alpha-1.jar standalone ” command, the hub will start and will start listening to localhost, we no longer require to pass URL http://localhost:4444/wd/hub.

Now, Selenium Grid 4 consists of four processes – Router, Distributor, Session Map, and Node.

Architecture

We had three processes earlier– Router, Session Map, and Distributor. Selenium 4 has a new architecture that supports four separate processes – Router, Session Map, Distributor, and Node.

  • Router that listens to the new session requests
  • Distributor hat selects the node where test will take place
  • Session Map  Maps the session ID to the node.
  • Node – Test machine where the test execution takes place.

In addition to the above features, the Grid can now manage Docker containers on your local machine, pulling images such as the stand-alone Firefox server, so your infrastructure maintenance becomes just a little bit less taxing

# IDE

With the introduction of SE4, our popular record and playback tool is back and not only for firefox but it is supported for chrome as well(Soon to be launched for Edge). Some key features provided are:

  • User friendly improved GUI
  • Selenium IDE runner aka SIDE. It allows user to run side projects on a node.js platform and freedom to run cross browser tests on cloud grid
  • Improved element locator algorithm, will eventually make the test case stable

Conclusion

The purpose of the blog was to provide brief info about some key features that Selenium4 has to offer. Also, If you are thinking of migrating to SE4 it can be easily achieved as the version is quite stable now. Please share your experience with us if you have migrated to this version and let us know about the issues you phased.

Have automation testing on your radar?

If yes, then feel free to chat with our live agent at impledge.com

Thank you !!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s