Skip to content

Commit

Permalink
Provide a modern standalone selenium server.
Browse files Browse the repository at this point in the history
This moves us on to a forked version of Jetty (which others should
not rely on) and removes original RC support. However, if the emulator
servlet is detected on the classpath, it is loaded and used within
this server instance.

Build with:

  `buck build se3-server`
  • Loading branch information
shs96c committed Oct 7, 2015
1 parent 6d143b1 commit d1960f2
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .buckconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
leg-rc = //java/client/src/com/thoughtworks/selenium:legacy-selenium-client
rc-server = //java/server/src/org/openqa/selenium/server:rc
selenium-java = //java/client/src/org/openqa/selenium:selenium-java

se3-server = //java/server/src/org/openqa/selenium/remote/server:standalone-server
1 change: 1 addition & 0 deletions java/server/server.iml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<orderEntry type="library" name="commons-io" level="project" />
<orderEntry type="library" name="commons-logging" level="project" />
<orderEntry type="library" name="jcip-annotations" level="project" />
<orderEntry type="library" name="jcommander" level="project" />
<orderEntry type="library" name="jetty" level="project" />
<orderEntry type="library" name="jetty-for-rc" level="project" />
<orderEntry type="library" name="junit" level="project" />
Expand Down
28 changes: 28 additions & 0 deletions java/server/src/org/openqa/selenium/remote/server/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,31 @@ export_file(name = 'style',
src = '//javascript/remote:style',
out = 'style.css',
)

java_library(name = 'standalone-server-lib',
srcs = [
'CommandLineArgs.java',
'SeleniumServer.java',
],
deps = [
':server',
'//third_party/java/beust:jcommander',
'//third_party/java/jetty:jetty',
'//third_party/java/servlet:servlet-api',
],
)

java_binary(name = 'standalone-server',
main_class = 'org.openqa.selenium.remote.server.SeleniumServer',
deps = [
':standalone-server-lib',
'//java/client/src/org/openqa/selenium/chrome:chrome',
'//java/client/src/org/openqa/selenium/edge:edge',
'//java/client/src/org/openqa/selenium/firefox:firefox',
'//java/client/src/org/openqa/selenium/htmlunit:htmlunit',
'//java/client/src/org/openqa/selenium/ie:ie',
'//java/client/src/org/openqa/selenium/opera:opera',
'//java/client/src/org/openqa/selenium/safari:safari',
'//java/server/src/com/thoughtworks/selenium/webdriven:rc-emulation-servlet',
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.openqa.selenium.remote.server;

import com.beust.jcommander.Parameter;

/**
* Command line args for the selenium server.
*/
public class CommandLineArgs {
@Parameter(
names = {"--help", "-help", "-h"},
help = true,
hidden = true,
description = "This help.")
boolean help;

@Parameter(
names = "-browserTimeout",
description = "Number of seconds a browser is allowed to hang (0 means indefinite).")

This comment has been minimized.

Copy link
@lukeis

lukeis Oct 7, 2015

Member

what do you mean by hang?

As I've seen with trying to go through the various timeouts in Grid... these need to be very clearly defined. Is this the timeout from sending the command before receiving a response?

int browserTimeout;

@Parameter(
names = "-jettyThreads",
hidden = true)
int jettyThreads;

@Parameter(
names = {"-port"},
description = "The port number the selenium server should use.")
int port = 4444;

@Parameter(
names = "-timeout",
description = "Number of seconds we should allow a client to be idle (0 means indefinite).")

This comment has been minimized.

Copy link
@lukeis

lukeis Oct 7, 2015

Member

again something to add much more clarity to. client idle is the time between selenium commands received from the client (automation script)?

int timeout;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.openqa.selenium.remote.server;

This comment has been minimized.

Copy link
@lukeis

lukeis Oct 7, 2015

Member

I'd prefer starting new things in a "org.seleniumhq" package instead... but meh.


import com.beust.jcommander.JCommander;

import org.seleniumhq.jetty9.server.Connector;
import org.seleniumhq.jetty9.server.HttpConfiguration;
import org.seleniumhq.jetty9.server.HttpConnectionFactory;
import org.seleniumhq.jetty9.server.Server;
import org.seleniumhq.jetty9.server.ServerConnector;
import org.seleniumhq.jetty9.servlet.ServletContextHandler;
import org.seleniumhq.jetty9.util.thread.QueuedThreadPool;

import javax.servlet.Servlet;

/**
* Provides a server that can launch and manage selenium sessions.
*/
public class SeleniumServer {

private final int port;
private int threadCount;
private Server server;

public SeleniumServer(int port) {
this.port = port;
}

private void addRcSupport(ServletContextHandler handler) {
try {
Class<? extends Servlet> rcServlet = Class.forName(
"com.thoughtworks.selenium.webdriven.WebDriverBackedSeleniumServlet",
false,
getClass().getClassLoader())
.asSubclass(Servlet.class);
handler.addServlet(rcServlet, "/selenium-server/driver/");
} catch (ClassNotFoundException e) {
// Do nothing.
}
}

private void setThreadCount(int threadCount) {
this.threadCount = threadCount;
}

public void start() {
if (threadCount > 0) {
server = new Server(new QueuedThreadPool(threadCount));
} else {
server = new Server();
}

ServletContextHandler handler = new ServletContextHandler();

DefaultDriverSessions webdriverSessions = new DefaultDriverSessions();
handler.setAttribute(DriverServlet.SESSIONS_KEY, webdriverSessions);
handler.setContextPath("/");
handler.addServlet(DriverServlet.class, "/wd/hub/*");
addRcSupport(handler);

server.setHandler(handler);

HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");

ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
http.setPort(port);
http.setIdleTimeout(500000);

server.setConnectors(new Connector[]{http});

try {
server.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public static void main(String[] argv) {
CommandLineArgs args = new CommandLineArgs();
JCommander jCommander = new JCommander(args, argv);
jCommander.setProgramName("selenium-3-server");

if (args.help) {
StringBuilder message = new StringBuilder();
jCommander.usage(message);
System.err.println(message.toString());
return;
}

SeleniumServer server = new SeleniumServer(args.port);
server.setThreadCount(args.jettyThreads);
server.start();
}

}
1 change: 1 addition & 0 deletions third_party/java/beust/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ prebuilt_jar(
binary_jar = 'jcommander-1.48.jar',
source_jar = 'jcommander-1.48-sources.jar',
visibility = [
'//java/server/src/org/openqa/selenium/remote/server:standalone-server-lib',
'//third_party/java/testng:testng'
],
)
Expand Down
1 change: 1 addition & 0 deletions third_party/java/jetty/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ java_library(
],
visibility = [
'//java/client/test/org/openqa/selenium/environment:environment',
'//java/server/src/org/openqa/selenium/remote/server:standalone-server-lib',
'//java/server/src/org/openqa/grid:grid',
'//java/server/test/com/thoughtworks/selenium/webdriven:webdriven',
],
Expand Down

0 comments on commit d1960f2

Please sign in to comment.