Selenium 4.0 stable version was officially released on 13th October 2021. Now let’s take a look at what it will offer. Communication among client-servers by W3C Web driver standardization protocols, multiple enhancements in grid, easy navigation among tabs and window, full screen capture possibilities, new relative locators inspired by native english language and many more.
Now the question is do we take it as a pinch of salt or celebrate? Let’s look at what has changed.
Selenium 4 Features
World Wide Web Consortium (W3C) Standards for WebDriver
In Selenium 3, communication between selenium web-driver APIs and browser native API was done by a phenomenon in which a client (user machine) on which web-driver is installed sends an object to the server in an JSON form. This JSON was used in encoded and decoded formats.
Now in selenium 4, encoding and decoding of JSON objects is not required as it is based on W3C standard protocol. It follows a standard procedure which makes requests and responses to interact without any encryptions.
Back in 2011, grid was developed in which various issues were associated like installation was complex and connection set up between node and hub was very trivial. With Selenium 4, a stable version is given in which the above mentioned issues are covered. Moreover, the user interface has become more user friendly as information like session capacity are visible on the go. Text executions are possible now on multiple nodes by a central point called hub.
New Locators and methods
Five locators newly added in Selenium 4 above, below, toLeftOf, toRightOf, and near.
- above(): locates element above the reference element
- below(): locates element below the reference element
- toLeftOf(): locates element left of the reference element
- toRightOf(): locates element right of the reference element
- near(): locates element near the reference element with distance of 50 px. Distance is added as an attribute.
- Method “withTagName()” returns an instance of above relative locators.
In the new release, there’s no need to create a new driver object in the same session to open a new tab or window.
- Pass WindowType.TAB to newWindow() method will create a new tab
- Pass WindowType.WINDOW to newWindow() method will create new window
Note: For switching between windows, pass the window ID to switchTo().window()
Browsers Support Revoked for Opera and PhantomJS
PhantomJS was a headless browser which was used for headless browser interactions. Opera, a web-browser developed by company Opera which is currently called chromium. Implementations of Webdriver for browsers PhantomJS and Opera are deprecated, so in this release support on these browsers is no longer available now. But, users can use a walkaround for these browsers as well. For opera(chromium), use chrome browser and for phantomJS use headless mode on chrome or firefox.
In 2017, IDE got deprecated. Now, it is introduced with multiple features.
- User Interface being more enhanced and the experience becomes user friendly.
- Can export code for Java, Python, JS, .Net, Ruby.
- For multi-browser parallel execution and playback functionality command line interface which is a selenium side runner is used which uses NodeJs.
- More detailed reports are shown with the count of the total, passed, and failed test cases with their execution time.
In Selenium4, a new method getScreenshotAs() is introduced which helps in capturing a screenshot of the element. Basic process to capture remains the same, find the webelement on DOM and use the method to capture the screenshot.
Also, another method getFullPageScreenshotAs() was used to capture only the screenshot of the visible current page. Previously, it worked on firefox driver. Now, in selenium 4, it takes a screenshot of the entire page, not dependent on whether the page is visible or not.
What is deprecated in Selenium 4?
FindsBy interface which is present in org.openqa.selenium.internal package implemented by the RemoteWebDriver class. The methods in it are findElement(By), findElements(By) where you can use By Class.
New methods are now added as a replacement of classes under package org.openqa.selenium.interactions.
moveToElement(onElement).click() is replaced by click(WebElement). This helps in clicking on specific elements.
moveToElement(onElement).clickAndHold() is replaced by clickAndHold(WebElement). This helps in clicking on a specific element without a release.
moveToElement(onElement).contextClick() is replaced by contextClick(WebElement). This helps in right clicking on specific elements.
moveToElement(element).doubleClick() is replaced by doubleClick(WebElement). This helps in double clicking on specific elements.
release() method moved to Action class from org.openqa.selenium.interactions.ButtonReleaseAction. This helps in release of click and hold.
3. Fluent Wait
The methods in the fluentwait such as withTimeout() and pollingEvery() have been modified.
3.1. Fluentwait in Selenium 3
3.2. FluentWait in Selenium 4
TimeUnit is replaced with Duration
4. Driver Constructors
Options replace the capabilities objects. Option Object is to be created for the driver class.
ChromeDriver ChromeOptions replaced ChromeDriver Capabilities.
InternetExplorerDriver InternetExplorerOptions replaced InternetExplorerDriver Capabilities.
SafariDriver SafariOptions replaced SafariDriver Capabilities.
EdgeDriver EdgeOptions replaced EdgeDriver Capabilities.
Multiple frameworks for automation are available for a tester to choose from but Selenium always seems to be a widely used framework. The new features are attractive for every QA engineer. In my opinion, the features that are added will act as a boom for QAs who believe in the left-shift paradigm.
Selenium 4 will be quite promising as it helps in making the test process simpler. One of the crucial enhancements are to influence containers by docker which was priorly performed by users to set up the machines and to scale-up, the grid can also be deployed on Kubernetes.
For more information, you can read on https://www.selenium.dev/downloads/.