Skip to content

seleniumhq-community/htmlunit-remote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central

HtmlUnit Remote

HtmlUnit Remote is a driver service for HtmlUnitDriver that enables you to acquire driver sessions from Selenium 4 Grid.

Background

To eliminate behavioral differences between local and remote configurations, the Selenium Foundation framework always acquires browser sessions from a Grid instance, managing its own local grid instance when not configured to use an existing instance. Selenium 3 Grid could be configured to supply HtmlUnitDriver sessions, supported by special-case handling within the Node server itself. This handling was not carried over into Selenium 4 Grid, which was completely re-engineered with new architecture and vastly expanded capabilities.

The lack of HtmlUnitDriver support in Selenium 4 Grid necessitated reconfiguring the Selenium Foundation project unit tests from using this Java-only managed artifact to using a standard browser like Chrome, an external dependency that requires additional resources and imposes additional risks of failure.

The driver service implemented by HtmlUnit Remote enables Selenium 4 Grid to supply HtmlUnitDriver sessions.

Implementation Details

HtmlUnit Remote provides the following elements:

  • HtmlUnitDriverInfo - This class informs Selenium 4 Grid that HtmlUnitDriver is available and provides a method to create new driver instances.
  • HtmlUnitDriverService - This class manages a server that hosts instances of HtmlUnitDriver.
  • HtmlUnitDriverServer - This is the server class that hosts HtmlUnitDriver instances. It implements the W3C WebDriver protocol:
    • Create new driver sessions
    • Route driver commands to specified driver sessions
    • Package driver method results into HTTP responses

In operation, HtmlUnitDriverService is instantiated by Selenium 4 Grid node servers that are configured to support HtmlUnitDriver. Unlike other driver services, which launch a new process for each created driver session, HtmlUnitDriverService starts a single in-process server that hosts all of the driver sessions it creates.

Grid Configuration

[node]
detect-drivers = false
[[node.driver-configuration]]
display-name = "HtmlUnit"
stereotype = "{\"browserName\": \"htmlunit\"}"

[distributor]
slot-matcher = "org.openqa.selenium.htmlunit.remote.HtmlUnitSlotMatcher"

The selenium-server JAR doesn't include the HtmlUnitDriver artifacts; these need to be specified as extensions to the grid class path via the --ext option:

java -jar selenium-server-<version>.jar --ext htmlunit-remote-<version>-grid-extension.jar standalone --config htmlunit.toml

The grid-extension artifact provides all of the specifications and service providers required to enable Selenium 4 Grid to supply remote sessions of HtmlUnitDriver. This artifact combines htmlunit-remote with htmlunit3-driver, htmlunit, and all of their unique dependencies.

Written with StackEdit.