Selenium 4.0 alpha released - What to expect from the upcoming stable release!
Tags: selenium, testing, testsigma
Published: 2019-05-09 14:18:14

Selenium team has added Selenium 4.0 alpha to [mvnrepository][mvnrepo] two weeks back(24th April) and that has created a buzz in the Automation QA Community.

The QA fraternity had been eagerly waiting for some of the features proposed in this release. The most significant of them would be the [W3C Standardization][w3cwdstandards]. It would make the Framework much more stable and reduce some of the compatibility issues across different Web Browsers. Another beginner-friendly change that is coming with this major release is updated Documentation. After version 2, Selenium Documentation has not been thoroughly updated. The updated documentation would help the beginners, as well as the experienced, immensely.

We hope some of the drawbacks in the article [Pros and Cons of Selenium as an Automation Testing tool][prosnconsarticle] will be handled by Selenium 4. Let us look at some of the prominent changes that we can expect from this release. And if you dig in the right place, you can see the complete list of changes in CHANGELOG or CHANGES file - [Selenium Github Repo][seleniumrepo]

Note: This is not a complete list and I have deliberately omitted many of the underlying implementation and architectural changes that a regular QA Automation guy like me wouldn't have to deal with on a daily basis 😀

___
##Architectural Changes
###1. Now using W3C Protocol for Browser-driver Communications
The earlier versions of Selenium used JSON wire protocol which required encoding and decoding of the API. Whereas, Selenium 4 will now use standard W3C Protocol to communicate between the driver and the browser. The advantage is that W3C protocol doesn’t require encoding or decoding the API and the tests will be able to directly communicate with the Browser.

###2. Compliant with W3C WebDriver Specifications
Selenium 4 will be entirely compliant with W3C WebDriver standards and this will include the documentation as well. So, the updated documentation will cover detailed instructions for usage.

Also, The actions API has been revamped to conform with the WebDriver Spec.

###3. Removed support for few Browsers
The team will remove native support for Opera and PhantomJS going forward. Still, the users who need to test Opera can rely on Chrome since Opera is based on Chromium(which Chrome is forked from) and for PhantomJS users can use [Chrome or Firefox in headless mode][headlessexamplegit].
Selenium Server now no longer includes HtmlUnit by default.

###4. Optimized Selenium grid
Alpha version of new Grid Server supports "standalone", "hub",
"node", and completely distributed usage. Also, this new Grid Server can output logs in single-line JSON format to the stdout.

###5. Added limited support for Opentracing and Docker
Basic support for OpenTracing landed. Use the --ext flag to the new Grid Server to provide the classpath to an OpenTracing implementation.

Selenium 4 will introduce Basic support for using Docker containers with the new Grid Server. More information will be available once the official documentation is released.

___
Check out Testsigma to see how most of these things are already considered and made available to all our customers.

[__Try Testsigma Now!__][tssignup]


___
##API changes
###1. Changes to Window class
- All window manipulation commands are now supported - fullscreen() and minimize() methods will be added.
- Added driver.switchTo().parentFrame() - We can use it to go from the child frame to the parent frame directly.
- Added getRect() & setRect() and removed getSize() & getPosition() - The getRect() and serRect() methods retrieves and sets respectively, a rect describing the current top-level window's size and position. This will replace the getSize() and getPosition() methods(a change that's not too relevant in common usage)
- Added command to open a new window.

###2. Changes to Builder class
- Added "setChromeService", "setEdgeService", & "setFirefoxService" methods - setChromeService sets the service builders to use for managing the chromedriver child process when creating new Chrome sessions. The others do the same for their respective Browsers

###3. Changes to chrome.Driver
- Added sendDevToolsCommand() - The sendDevToolsCommand() method sends an arbitrary devtools command to the browser and returns a promise that will be resolved when the command has finished.
- Added setDownloadPath() - The setDownloadPath() method sends a DevTools command to change Chrome's download directory and returns a promise that will be resolved when the command has finished.

###4. Changes to firefox.Driver
- Added installAddon(path) - The installAddon() method installs a new addon within the current session. This function will return an "id" that can be used to uninstall the addon using uninstallAddon().
- Added uninstallAddon(id) - Uninstall the Addon using ID.
- Added addExtensions() - Add extension to the automation session easily.
- Added setPreference() - Add preferences to the session.

###5. Changes to Options/Capabilities Class
- Options class now extends Capabilities class for Chrome, Firefox, IE, Safari.
- Removed the Firefox.Profile class. All of its functionality is now provided directly by Firefox.Options.
- setProfile() now only accepts a path to an existing profile
- Removed static factory methods android(), ipad(), iphone(), opera(), phantomjs(), htmlunit(), and htmlunitwithjs(). Users can still manually configure capabilities for these, but their use is not recommended and they will no longer be surfaced in the API.

###6. Changes to Errors
- Added ElementClickInterceptedError - The Selenium code throws ElementClickInterceptedError when a click command cannot complete due to the click target being obscured by other elements on the page.
- Added InsecureCertificateError - The Selenium code throws InsecureCertificateError when a navigation event causes the browser to generate a certificate warning. An expired or invalid TLS certificate usually cause this.
- Added InvalidCoordinatesError - The Selenium code throws InvalidCoordinatesError when an interaction operation becomes invalid due to the passing of invalid coordinates.
- Added NoSuchCookieError - The Selenium code throws NoSuchCookieError when a named Cookie is missing in the cookie jar for the current document.
- Removed ElementNotVisibleError
- Removed InvalidElementCoordinatesError

###7. Changes to WebDriver
- Removed touchActions - TouchActions implements actions for touch enabled devices such as doubleTap(), singleTap(), flick(), longPress(), scroll() e.t.c. This might have been moved to Appium library but can be confirmed only once the complete documentation is available.

###8. Changes to Alerts
- Removed authenticateAs

###9. Others
- Revamped the actions API to conform with the WebDriver Spec
- Element screenshotting might be added
- Element screenshots are now possible.
- Deleted many of the deprecated methods and classes.

##Better and standard Documentation
One of the main issues that haunted the Selenium users was outdated documentation. The Selenium team had not updated the documentation since Selenium 2.0. With Selenium 4, they have updated Selenium's official documentation to explain the latest changes and it conforms to W3C Standards now.

##Footnote
While it's great to see the improvements, it would be a hassle for small and medium-sized teams to read through the API docs, analyze the changes, and rectify the tests broken by the updates due to the considerable changes.

Many of the above-discussed changes have already been implemented by us in [Testsigma][tsfeatures] prior to this release as per the feedback or request from our users. That's one of the reasons why cloud-based scriptless tools like Testsigma is more suitable for such teams.
With a cloud-based tool like Testsigma, the updates will be reviewed internally and applied to all the customer's tests automatically without any additional time, resources and efforts from the teams.

[__Signup to Testsigma for free!__][tssignup]


___
Originally published at [Testsigma Blog][selenium4article] on May 8, 2019.
[mvnrepo]:https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
[w3cwdstandards]:https://www.w3.org/TR/webdriver1/
[prosnconsarticle]:https://testsigma.com/blog/selenium-automation-testing-pros-cons/
[seleniumrepo]:https://github.com/SeleniumHQ/selenium
[tsfeatures]:https://testsigma.com/features
[tssignup]:https://testsigma.com/signup
[selenium4article]:https://testsigma.com/blog/selenium-4-automation-engineer-expect/
[headlessexamplegit]:https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/example/headless.js