-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a modern standalone selenium server.
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
Showing
7 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
java/server/src/org/openqa/selenium/remote/server/CommandLineArgs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
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.
Sorry, something went wrong.
lukeis
Member
|
||
int timeout; | ||
} |
95 changes: 95 additions & 0 deletions
95
java/server/src/org/openqa/selenium/remote/server/SeleniumServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong.
lukeis
Member
|
||
|
||
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?