Skip to content

Instantly share code, notes, and snippets.

@freynaud
Created August 12, 2011 10:04
Show Gist options
  • Save freynaud/1141812 to your computer and use it in GitHub Desktop.
Save freynaud/1141812 to your computer and use it in GitHub Desktop.
{
"capabilities":
[
{
"browserName":"firefox",
"maxInstances":1
},
{
"browserName":"chrome",
"maxInstances":1
},
{
"browserName":"internet explorer",
"maxInstances":1
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy":"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
"maxSession":1,
"url":"http://ip:5555/wd/hub",
}
}
private void launchEverything() {
try {
GridHubConfiguration config = new GridHubConfiguration();
config.setPort(4444);
hub = new Hub(config);
URL hubURL = hub.getUrl();
hub.start();
JSONObject request = JSONConfigurationUtils.parseRegistrationRequest("localnode.json");
JSONObject jsonConfig = request.getJSONObject("configuration");
int port = jsonConfig.getInt("port");
RemoteControlConfiguration c = new RemoteControlConfiguration();
c.setPort(port);
node = new SeleniumServer(c);
node.boot();
URL registration = new URL("http://localhost:4444/grid/register");
registerToHub(registration, request.toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void registerToHub(URL registrationURL, String json) {
try {
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", registrationURL.toExternalForm());
r.setEntity(new StringEntity(json));
DefaultHttpClient client = new DefaultHttpClient();
HttpHost host = new HttpHost(registrationURL.getHost(), registrationURL.getPort());
HttpResponse response = client.execute(host, r);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Error sending the registration request.");
}
} catch (Exception e) {
throw new RuntimeException("Error sending the registration request.", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment