Selenium 4: New Features And Improvements

Profile picture for user arilio666

Selenium 4

  • Selenium core is obsolete.
  • Selenium Rc APIs modified to leg-RC(legacy package)
  • Eradicating thread-safety bugs and perfect support for docker selenium 4 will introduce the most stable selenium grid.
  • As part of this release, request tracing and logging docker support have been modified for automation engineers to get a great hold of nasty bugs.

New Protocol

  • W3C recommendations document for selenium web driver is now available, which provides a clear picture of how selenium APIs work.
  • This will encourage compatibility over different software implementations of web driver API.
  • JSON wire protocol will no longer be used.
  • The test will directly communicate without any encoding and decoding of API requests.

New plugin system: Any browser vendor will now easily plug into new selenium IDE.

New CLI runner: It is now based entirely on Nodejs and not an old HTML-based runner.

Webdriver Playback: New selenium IDE will be based entirely on web driver.

Parallel Execution: The new CLI runner will also support parallel test case executions and provide the time taken for several tests passed and failed.

Improved Selenium Grid:

  • Compared to the previous version of the selenium grid, which was hard to set up and rigid in scaling.
  • The new grid comes with docker support.
  • This will help testers use the containers and not the heavy virtual machines.

The grid can now be deployed in three modes:

  1. Standalone
  2. Hub and node
  3. Fully distributed

New Relative Locators:

New locators which located dom elements based on relative has been introduced.

To left of
To right of
Above
Below

Improved Window/Tab Management:

The previous selenium version was a hassle to switch between tabs where we needed to create a new driver object and then perform switch operation.
Now in selenium 4, this is hassle-free.
It now comes with a new API called newWindow and gives us the option to mention the window type, whether it is a tab or a new window.

New Window:

driver.get("https://www.programsbuzz.com/");
driver.switchTo().newWindow(WindowType.WINDOW);
driver.navigate().to("http://autopract.com/#/home/fashion");

New Tab:

driver.get("https://www.programsbuzz.com/");
driver.switchTo().newWindow(WindowType.TAB);
driver.navigate().to("http://autopract.com/#/home/fashion");

Desired Capabilities Deprecation:

  • Desired Capabilities are used in selenium to define the test environment for the execution.
  • In version 4, capabilities are now replaced with options.
  • This means we have to create a new object called options, set the requirements of the test and pass the object to the driver.

Some of the options objects are as follows:

Firefox – FirefoxOptions
Chrome – ChromeOptions
Internet Explorer (IE) – InternetExplorerOptions
Microsoft Edge – EdgeOptions
Safari – SafariOptions

Actions Class:

  • In selenium actions class are responsible for double click, click, left and right-click, etc.
  • Selenium 4 has tweaked some of the new methods for it.
  1. click(WebElement): Replaced instead of  moveToElement(onElement).click() which is used to click certain webelements.
  2. clickAndHold(WebElement): Replaced instead of moveToElement(onElement).clickAndHold() which is used to move to certain element and click and hold it.
  3. contextClick(WebElement): Replaced instead of moveToElement(onElement).contextClick() which performs right click.
  4. doubleClick(WebElement): Replaced instead of moveToElement(element).doubleClick().
  5. release(): This was already a part of the button release action class, which was later in selenium 4 moved to actions class.

Conclusion:

Compared to the previous version of selenium, this update looks promising with many features and improvements they brought to life.