The first-ever release of Selenium WebDriver 1.0 in 2007 has indented a lasting footprint in web automated testing. And through the years, the contributions of the Selenium project (WebDriver, Grid, and IDE) have truly transformed the way that we do quality assurance.
Fast forward to the ‘drop-in’ release of Selenium 4 and Selenium 4.1, this article narrows down the top 5 changes you need to know for WebDriver, IDE, and Grid.
Selenium WebDriver 4
Cross-browser testing has received an efficiency boost from the updates in Selenium’s architecture.
The WebDriver APIs have removed the support for the legacy protocol and are fully compliant with the W3C Standardization. Allowing browsers and test scripts to communicate straight to the targeted browsers, users no longer have to go through the JSON wire protocol to encode and decode API requests.
For those that still have the ChromeDriver and GeckoDriver browser drivers in use, this standardization will not cause any effects since they have already supported the W3C protocols.
To reassure you, using the W3C WebDriver will not cause any harm to existing users. The main changes only evolve around Capabilities and the Actions class.
Adding and deleting WebDriver APIs
FindsByID, FindsByCss or related FindsBy* (findElementBy) interfaces have been removed and replaced with ‘By’ instance.
- Relative Locators or Friendly Locators. Names such as above(), below(), toLeftOf(), toRightOf() and near() look to provide an easier way to spot elements that are close to the other DOM elements.As opposed to this, Selenium 4 also introduced new elements such as:
- Exceptions set to understand test failures. ‘ElementClickInterceptedError’, ‘InsecureCertificateError’, ‘InvalidCoordinatesError’, and ‘NoSuchCookieError’ classes are included in /lib/error.
- Chrome Debugging/DevTools Protocol (CDP) integration. Cross-language APIs are still under development to extend coverage for requirements like log captures or geolocation mocking
Sample code snippet to open a new window
// Opens a new window and switches to new window
// Opens Katalon Academy homepage in the newly opened window
Sample code snippet to open a new tab within the same window
// Opens a new tab in existing window
// Opens Katalon Download page in the newly opened tab
- Emulate different network conditions. The Network.emulateNetworkConditions command helps compare the average loading time by scripting tests that emulate a range of network speed (slow and normal) and connection type (BLUETOOTH, 2G, 3G, 4G, WIFI, etc.).
The following are the updates Selenium 4 has added to Selenium:
- Revived UI
- Plug-ins to fully support Chrome, Firefox, or any other web extension plugins
- Parallel testing by switching from being HTML-based to running on a NodeJs platform with the “Selenium-side-runner” CLI runner
- Improve scripts written using “while” and “if” conditions
- Backup element selector and updated locator strategies to create more stable tests
Selenium Grid 4
Taking pointers and learning from the success of the Zalenium and Selenoid projects, Selenium Grid most notable change is being able to:
- Implemented a GraphQL model for a new UI to better query and manage Grid
- Support deploying on Kubernetes-based infrastructures
- Less maintenance work with standalone Firefox server to get Docker images
- On-demand Docker containers spin-ups without setting up virtual machines
The release of Selenium Grid 4.1 can be read in detail here.