Scaling Selendroid by using the Selenium Grid

Prerequisites

Steps to use selendroid together with the Selenium Grid on a local machine:

  1. Download selenium-server-standalone from the Selenium Project
  2. Download selendroid-standalone
  3. Download selendroid-test-app
  4. Download selendroid-grid-plugin
  5. copy all the artifacts into the folder where the selenium-server-standalone is stored.

Start all servers

First, the selendroid-standalone should be started (more details you find here):

java -jar selendroid-standalone-0.17.0-with-dependencies.jar -app selendroid-test-app-0.17.0.apk -port 5555

Now you can start the Grid with the selendroid-grid-plugin that contains the proxy io.selendroid.grid.SelendroidSessionProxy and a simple capability matcher io.selendroid.grid.SelendroidCapabilityMatcher.

Command to start the server on Mac & Unix:

java -Dfile.encoding=UTF-8 -cp "selendroid-grid-plugin-0.17.0.jar:selenium-server-standalone-2.45.0.jar" org.openqa.grid.selenium.GridLauncher -capabilityMatcher io.selendroid.grid.SelendroidCapabilityMatcher -role hub -host 127.0.0.1 -port 4444

Command to start the server on Windows:

java -Dfile.encoding=UTF-8 -cp "selendroid-grid-plugin-0.17.0.jar;selenium-server-standalone-2.45.0.jar" org.openqa.grid.selenium.GridLauncher -capabilityMatcher io.selendroid.grid.SelendroidCapabilityMatcher -role hub -host 127.0.0.1 -port 4444

Registering nodes to this grid can be done using this registration request (file name selendroid-nodes-config.json):

{
  "capabilities": [{
      "browserName": "selendroid",
      "maxInstances": 1,
      "aut": "io.selendroid.testapp:0.17.0"
  }, {
      "browserName": "android",
      "maxInstances": 1
  }],
  "configuration": {
      "maxSession": 1,
      "register": true,
      "hubHost": "localhost",
      "hubPort": 4444,
      "remoteHost": "http://localhost:5555",
      "proxy": "io.selendroid.grid.SelendroidSessionProxy"
  }
}

This configuration describes in the section capabilities two browsers that are available on the node machine. The first one selendroid is able to run tests agains the app under test (aut) io.selendroid.testapp. The second one android can run mobile web tests. The important thing is not to mix both entries, otherwise forwarding the session to the selendroid-standalone will fail. You can find details about how capabilities are used in selendroid here.

The node registration can be done by sending the node config to the hub using curl:

curl -H "Content-Type: application/json" -X POST --data @selendroid-nodes-config.json http://localhost:4444/grid/register

Now you can verify in the Selenium Grid console, that the node has been added to the grid hub.

Run a Test

When defining desired capabilities, please verify that they are present in the grid hub and they match to the capablities of the selendroid-standalone server. Otherwise you will get an error that the session could not be forwarded.

@Test()
public void testShouldBeAbleToRegisterAnUser() throws Exception {
  SelendroidCapabilities capa =
      new SelendroidCapabilities(
          "io.selendroid.testapp:0.17.0");
  WebDriver driver = new SelendroidDriver(capa);
  driver.findElement(By.id("startUserRegistration")).click();

  // Enter user name
  WebElement username = driver.findElement(By.id("inputUsername"));
  username.sendKeys("johndoe");
  driver.quit();
}