In this year 2020, Selenium community is bringing lots of new features / enhancements to the users.
In this post, we will discuss all the enhancements available so far in selenium 4 and will see if those changes impacting to our existing script or not!
No more JSON Wire Protocol – only W3C
As per the selenium contributors, the main reason of Selenium 4 update is complete implementation of W3C
Now no more JSON Wire protocol as a middle layer, this means selenium scripts need not to be encode or decode while sending requests to browser drivers.
This makes the selenium scripts stable, may even fasten the execution and also we will not get much compatibility issues with the selenium library and browser drivers.
Note – This change doesn’t affect to existing scripts, as most of the popular browser drivers already implemented W3C protocol.
Relative locator strategy
A friendly way of locating elements relative to other near by elements.
An element can be identified based on tagName along with methods like above(), below(), near(), toLeftOf() & toRightOf()
These methods accept By locator / WebElement as parameters
e.g – let’s say we have to find Password field on the login screen –
driver.findElement(withTagName("input")
.above(By.name("signIn"))
.below(By.name("userName")))
.sendKeys("myPassword");
Note – this might not affect your existing script, but in case you want to upgrade your script if you need to, you can use as mentioned above, you can refer to selenium relative locator
Support ‘Chrome DevTools’
When right click on element / browser > inspect, we get the chrome devtools window which has the tabs as –
Elements [HTML DOM], Console [for executing JS], Network [all API or network calls], Sources, Security etc
Selenium ChromiumDriver provides different methods to perform actions on those tabs, like
- Monitor / validate network responses
- Emulate network conditions like speed, offline /online
- Play with cookies
- Emulate/mock geolocation
- Capturing logs
Note: you can create a devtools session and perform the above operations
ChromeDriver driver = new ChromeDriver(); DevTools devTools = driver.getDevTools(); devTools.createSession();
or, you can use
driver.executeCdpCommand(String CommandNames, map<String, String> arguments);
cdp – chrome debugging protocol
Selenium GRID
One major improvement of GRID is to work with Docker to spin up containers.
- GRID now can communicate with HTTPS protocol over internet.
- Grid configuration files now can be written in TOML.
- Now supports IPV6 addresses
Grid can be configured in any of the following ways
- As standalone
- Hub & node
- Distributed
- Dockers
For more details, refer Selenium Grid4
ChromeDriver & EdgeDriver extending ChromiumDriver
public class ChromeDriver / EdgeDriver extends ChromiumDriver extends RemoteWebDriver
ChromiumDriver
introduced to create a connection with the “Chrome DevTools”, so Chromium based browsers like ChromeDriver & EdgeDriver has the ability to handle the chrome devtools in the script.
Screenshot
Selenium 4 provides taking
- Screenshot for full page [available for FireFoxDriver]
- screenshot for a particular element[s]
- If you are taking screenshot for a parent element, then all the child elements also appear on the screenshot
Note: if you are using any other way to take screenshot of an element, then you can replace your existing code with this ready made method with selenium 4.
Window handling
Now with Selenium 4, we can
Minimize window –
driver.manage().window().minimize();
Note: we can perform the user actions in selenium even keeping the browser minimised.
Note – refer Selenium Window interface
New Tab –
driver.switchTo().newWindow(WindowType.TAB).get(”url");
New window –
driver.switchTo().newWindow(WindowType.WINDOW).get(url);
Note – refer newWindow()
Element Size & Position
getSize() & getPosition() methods are replaced by getRect()
Example Usage –
getPosition().getX() -> getRect().getX()
getSize().getHeight() -> getRect(). getHeight()
Note – this might impact your existing script if you have used the getSize() or getPosition().
No support for Opera browser
Native support for Opera browser & PhantomJS has been removed.
it is recommended to use Chrome browser and consider the same will be working for Opera browser as both the browsers has the same chromium engine.
Selenium IDE
More improvements done [from applitools team] to selenium IDE to make it stable.
- Now available as browser extension for both Chrome & Firefox browser.
- Existing IDE with xpi extension, will no longer work for firefox browser
- New UI for better experience
- Test case reuse, Improved test script export to different languages.
- Supports control flow to write tests with while, if conditions.
Refer https://www.selenium.dev/selenium-ide/ for more information about this extension.
Selenium documentation
Selenium community now came up with improved documentation and it keeps adding more stuff time to time, so you can refer to this below link
https://www.selenium.dev/documentation/en/getting_started/
For all the above features / enhancements / changes to selenium 4, we will be discussing in detail, so stay tuned to youtube.com/qavbox
Selenium Java change-log, refer https://github.com/SeleniumHQ/selenium/blob/trunk/java/CHANGELOG
4 Comments