An end-to-end documentation on Grid
Image Courtesy: Boloji.com
The Selenium Grid has many a configuration parameters that would help you to tweak its behaviour to suite your needs.
The good part of all this is that you don’t need to look for documentation else where. Its embedded as part of the selenium standalone uber jar.
To see the documentation related to the Selenium Hub, run :
java -jar selenium-server-standalone-3.141.59.jar -role hub -help
See here for the documentation of the Hub.
Lets see some of the most commonly used configuration parameters applicable for the Hub.
The selenium uber jar by default always uses the first Non Loopback ip4 that it finds.
Quoting the definition of Loopback address from Webopedia
Loopback address is a special IP number (127.0.0.1) that is designated for the software loopback interface of a machine. The loopback interface has no hardware associated with it, and it is not physically connected to a network. The loopback interface allows IT professionals to test IP software without worrying about broken or corrupted drivers or hardware.
Sometimes you may want to override this and provide the hostname to be used. You can do that as below :
java -jar selenium-server-standalone-3.141.59.jar -role hub \
-host 192.168.1.2 -port 8080
Since we provided a different host value, we would need to use the same value when spinning off a node. So the command would look like this :
java -jar selenium-server-standalone-3.141.59.jar -role node \
-hub http://192.168.1.2:8080/grid/register
The Selenium Hub by default always listens on port 4444
.In order to have the hub use a different port (say for e.g., 8080
) spawn the Hub as shown below:
java -jar selenium-server-standalone-3.141.59.jar -role hub -port 8080
Incase we feel that the command to start the hub is getting long, we can wrap up the configuration for the Hub via a JSON file as well.
So if we were to specify the host and the port in the JSON file, it could look like below :
{
"host": "192.168.1.2",
"port": 8080
}
Here’s the command :
java -jar selenium-server-standalone-3.141.59.jar -role hub \
-hubConfig hubconfig.json
Incase you would like to know what else can go within this JSON configuration file, take a look here
The Hub by default exposes the below end-points via servlets (For the sake of e.g., lets assume that the hub is running on localhost
and listening on 4444
port) :
Registration URL : http://localhost:4444/grid/register/ - This is the end-point to which a selenium node will talk to, when you spawn a node, as part of the node wiring in itself to the hub.
Client facing URL : http://localhost:444/wd/hub - This is the end-point to which your test cases will talk to, as part of utilising the Grid as the execution environment.
Hint : Remember using these two lines in your Java tests?
URL url = new URL("http://localhost:444/wd/hub");
RemoteWebDriver driver = new RemoteWebDriver(url, DesiredCapabilities.firefox());
org.openqa.grid.web.servlet.DisplayHelpServlet
[ This is an optional servlet and can be disabled ]org.openqa.grid.web.servlet.beta.ConsoleServlet
[ This is an optional servlet and can be disabled ]org.openqa.grid.web.servlet.ResourceServlet
[ This is an optional servlet and can be disabled ]org.openqa.grid.web.servlet.LifecycleServlet
[ This is an optional servlet and can be disabled ]org.openqa.grid.web.servlet.Grid1HeartbeatServlet
[ This is an optional servlet and can be disabled ]You can disable some of the servlets (the ones that are marked as optional). For e.g., if you wanted to disable the console servlet and the life cycle servlet, it can be done using the below command:
java -jar selenium-server-standalone-3.141.59.jar -role hub \
-withoutServlet org.openqa.grid.web.servlet.LifecycleServlet,\
org.openqa.grid.web.servlet.beta.ConsoleServlet
Talk2Grid is one library that internally consumes some of these URLs and exposes these information in a user friendly manner.
The Selenium hub logs can be redirected to a file.
For e.g., to enable debug level logs and redirect them to the file /logs/grid.log, use:
java -jar selenium-server-standalone-3.141.59.jar -role hub \
-log /logs/grid.log -debug true