damian-jobaline edited this page Jun 8, 2014 · 15 revisions
Clone this wiki locally


This tutorial shows how to enhance grid functionality by creating a custom proxy to control the grid nodes. the default proxies shipped with grid2 ( org.openqa.grid.selenium.proxy.SeleniumRemoteProxy for selenium1 org.openqa.grid.selenium.proxy.WebDriverRemoteProxy for webdriver ) have the minimal functionality for grid to work. They will keep track of the running tests, assign new tests to the node if they can, and clear the tests that have timed out. If you want more functionality, you need to create a grid plugin.

The tutorial will explain how you can enhance a WebDriverRemoteProxy to keep track of how many tests have ran already on the node the proxy controls, and will display that number on the grid console.

The grid is composed of 2 pieces:

  • the hub keeps track of what runs where.That's where all the information about the grid system is available and where the custom proxies will live.
  • the nodes running the tests.

Creating a plugin means :

  • create the logic for the new proxy and package it as a jar.Load that jar when starting the hub.
  • when starting a node, specify the the new proxy has to be used.

Creating the plugin:

Create new java project

To create a new grid plugin, no need to checkout selenium from the source. The plugin is a separate jar, no need to recompile selenium.

Create a new java project from scratch, and put the selenium server jar in the classpath.I use maven in the demo project but it will work just as well without it.

If you're using maven your pom will look like pom.xml

The new proxy code incrementing the total test counter.

Create a new java class extending WebDriverRemoteProxy. Make the class implement TestSessionListener. This interface give you access to hooks triggered before a test starts and after a test finishes.source

Implement the beforeSession method to increment the total test counter.TestCounterWebDriverProxy.java

Displaying the value of the total test counter in the console.

The html generated by the HtmlRenderer associated with the proxy will define what is displayed on the grid console. Override the getHtmlRender() method to change it. Create a new renderer that will display the value of the total test counter. TotalTestAwareHtmlRenderer

builder.append("this proxy ran ").append(proxy.getTotalTests()).append(" already.<br>");

Package the new plugin

Create a jar containing the 2 classes of the new plugin: the proxy and the renderer With Maven:

~/workspace/grid-plugin-tutorial$ mvn isntall will create a grid-plugin-tutorial-0.0.1-SNAPSHOT.jar Copy that jar in the folder where you downloaded selenium-server-standalone.jar

Launching everything

the hub

you need to add the newly created plugin to the hub classpath before starting it :

~/workspace$ java -cp "grid-plugin-tutorial-0.0.1-SNAPSHOT.jar:selenium-server-standalone-2.5.0.jar" org.openqa.grid.selenium.GridLauncher -role hub

If this command does not work for you, please try separating the jars of the classpath using a semicolon (;) instead of a colon (:).

a node

When registering the node, you need to let the hub know that the node needs to be represented by the new proxy on the hub instead of the default one.Assuming you start everything locally :

java -jar selenium-server-standalone-2.5.0.jar -role wd -proxy org.openqa.demo.TestCounterWebDriverProxy -hubHost localhost


http://localhost:4444/grid/console will now show the total number of tests the node ran. console