By default, Selenium Foundation acquires driver sessions from an instance of Selenium Grid. If you specify an existing instance in your configuration, sessions will be acquired from there. If this configuration setting is left undefined or specifies an inactive localhost
URL, Selenium Foundation will automatically launch a local Grid instance as specified by the local Grid configuration.
Stand-Alone Selenium Grid with local-grid-parent
In addition to providing a local Grid instance for running Selenium tests on your machine, this Selenium Foundation feature can be used to launch stand-alone instances that can be utilized in more conventional fashion by tests running on other machines. The easiest way to manage a stand-alone instance of Selenium Grid is via the Local Grid Parent utility. This utility leverages the capabilities of Selenium Foundation to configure and manage Selenium Grid instances.
To maximize flexibility, configurability, consistency, and control, the browser sessions dispensed by Selenium Foundation are provided by an instance of Selenium Grid. To use an existing Grid instance for session provisioning, specify its endpoint URL in the HUB_HOST
setting. By default, Selenium Foundation will launch a local Grid and acquire sessions from there.
The unit tests of this project acquire browser sessions from a local Grid instance that gets launched at the start of the test run and torn down when the run is complete. By default, the local Grid runs in "servlet container" mode, and only non-browser support feature tests are run. Profiles defined in the Gradle project file allows you to specify which browser to target with the corresponding unit tests. This aspect of the Selenium Foundation project provides a working example of how to configure for the local Grid feature, as detailed in the following sections.
The first place Selenium Foundation checks for the specification of driver plug-ins is in the System properties. You can set the selenium.grid.plugins
property to a file-separator-delimited one or more fully qualified driver plug-in class names for the browsers that should be supported by the local Grid:
-Dselenium.grid.plugins=com.nordstrom.automation.selenium.plugins.EdgePlugin
The set of drivers supported by the local Grid instance managed by Selenium Foundation is configured by specifying plug-ins for the corresponding drivers in a ServiceLoader provider configuration file. For example, here's the contents of the actual configuration file for the project unit tests:
com.nordstrom.automation.selenium.plugins.HtmlUnitPlugin
In addition to declaring driver plug-ins in the ServiceLoader provider configuration file, the Java project itself must declare the dependencies of the corresponding driver(s). These dependencies vary by the version of Selenium API you're using, and they're documented in the plug-in classes themselves. For example, here is the Maven dependency for the Selenium 3 version of HtmlUnitPlugin
:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.67.0</version>
</dependency>
Driver plug-ins encapsulate the specific details related to launching Selenium Grid nodes that support the corresponding drivers. Selenium Foundation provides driver plugin-ins for all of the major browsers. It also provides plug-ins for all of the major automation engines of the Appium
project.
In addition to specifying browser driver plug-ins in the ServiceLoader provider configuration file, you'll need to install the corresponding browsers and matching drivers. The process for installing browsers and drivers varies. Just follow the instruction provided by the driver vendor.
In addition to specifying Appium
driver plug-ins in the ServiceLoader provider configuration file, you'll need to install Appium
and its dependencies. With a conventional installation, Selenium Foundation can use your system configuration to locate the components that comprise an Appium
node. For non-standard installations, Selenium Foundation provides settings that enable you to supply explicit paths to these items.
Selenium Foundation gives you the ability to completely control the configuration of the Appium
Grid node that it uses to provide sessions for your tests, via the APPIUM_CLI_ARGS
setting. This setting can define multiple Appium
server arguments together, and can be declared multiple times when specified in the settings.properties file. These are presented to Selenium Foundation as a collection of values that it processes and passes on to 'Appium` when it launches the Grid node.
Although Selenium Foundation doesn't need the Java bindings for Appium
to launch the Grid node, you'll need to declare this dependency in your Java projects to acquire device-specific drivers like AndroidDriver or IOSDriver. Here are the Maven artifact coordinates that correspond to each version of the Selenium API:
Selenium 3 |
---|
<dependency> |
To enable the Local Grid
feature to support Selenium 3, the core configuration in SeleniumConfig
defines version-specific default values for several settings:
Setting | Property Name | s3 Default |
---|---|---|
GRID_LAUNCHER |
selenium.grid.launcher |
org.openqa.grid.selenium.GridLauncherV3 |
LAUNCHER_DEPS |
selenium.launcher.deps |
source |
HUB_PORT |
selenium.hub.port |
4445 |
HUB_CONFIG |
selenium.hub.config |
hubConfig-s3.json |
NODE_CONFIG |
selenium.node.config |
nodeConfig-s3.json |
- The
GRID_LAUNCHER
setting specifies the fully-qualified name of the main Java class for launching Grid servers. - The
LAUNCHER_DEPS
setting specifies a semicolon-delimited list of fully-qualified names of context classes for the dependencies of theGRID_LAUNCHER
class. - The
HUB_PORT
setting specifies the HTTP port assigned to the Grid hub server. This is only used if theHUB_HOST
setting is undefined. - Specifying
HUB_PORT
as0
directs Selenium Foundation to automatically select any available port. - The
HUB_CONFIG
setting specifies the configuration file for Grid hub servers. - The
NODE_CONFIG
setting specifies the configuration template used to build configurations for Grid node servers.
During the Local Grid start-up process, Selenium Foundation builds a driver-specific node configuration for each plug-in specified in the ServiceLoader provider configuration file:
- The Capabilities specification for the node is acquired from the driver plug-in.
- A base node configuration is built from this specification suitable for the target Selenium API version.
- Selenium Foundation determines if an associated modifier has been specified for the base configuration.
- The base configuration is merged with the configuration template specified by the
NODE_CONFIG
setting. - The resulting node configuration is written to disk (unless the target file already exists)
Once the configuration of the Local Grid
is resolved, Selenium Foundation commences to launch:
- Launch the Selenium Grid hub server:
- ... with the grid launcher class specified by the
GRID_LAUNCHER
setting - ... with dependency contexts specified by the
LAUNCHER_DEPS
setting - ... with the hub configuration specified by the
HUB_CONFIG
setting - ... specifying the IP address returned by
GridUtility.getLocalHost()
- ... listening to the port specified by the
HUB_PORT
setting
- ... with the grid launcher class specified by the
- Update the values of
HUB_HOST
andHUB_PORT
to reflect the grid hub server configuration. - For each plug-in specified in the ServiceLoader provider configuration file:
- Launch the driver-specific Selenium Grid node server:
for
RemoteWebDriver
plug-in
:- ... with the grid launcher class used to launch the grid hub server
- ... with additional dependency contexts specified by the plug-in
- ... propagating the values of System properties specified by the plug-in
- ... with the assembled driver-specific node configuration
- ... specifying the IP address returned by
GridUtility.getLocalHost()
- ... listening to the port returned by
PortProber.findFreePort()
for
Appium
plug-in
:- ... with
Node
executable specified by theNODE_BINARY_PATH
setting- ... searching the System configuration if unspecified
- ... with
Appium
main script specified by theAPPIUM_BINARY_PATH
setting- ... searching the global
Node
modules repository if unspecified
- ... searching the global
- ... with command-line arguments specified by the
APPIUM_CLI_ARGS
setting - ... with the assembled driver-specific node configuration
- ... specifying the IP address returned by
GridUtility.getLocalHost()
- ... listening to the port returned by
PortProber.findFreePort()
- ... with
- Launch the driver-specific Selenium Grid node server:
Written with StackEdit.