public class SeleniumServer extends Object implements SslCertificateGenerator
To run Selenium Server, run:
java -jar selenium-server-1.0-SNAPSHOT.jar [-port 4444] [-interactive] [-timeout 1800]
Where -port
specifies the port you wish to run the Server on (default is 4444).
Where -timeout
specifies the number of seconds that you allow data to wait all in
the communications queues before an exception is thrown.
Using the -interactive
flag will start the server in Interactive mode. In this mode
you can type remote Selenium commands on the command line (e.g. cmd=open&1=http://www.yahoo.com).
You may also interactively specify commands to run on a particular "browser session" (see below)
like this:
cmd=open&1=http://www.yahoo.com&sessionId=1234
The server accepts three types of HTTP requests on its port:
http://www.yahoo.com/selenium-server/driver/?seleniumStart=true&sessionId=1234
The driver will then reply with a command to run in the body of the HTTP response,
e.g. "|open|http://www.yahoo.com||". Once the browser is done with this request, the browser will
issue a new request for more work, this time reporting the results of the previous
command:
http://www.yahoo.com/selenium-server/driver/?commandResult=OK&sessionId=1234
The action list is listed in selenium-api.js. Normal actions like "doClick" will
return "OK" if clicking was successful, or some other error string if there was an error.
Assertions like assertTextPresent or verifyTextPresent will return "PASSED" if the assertion was
true, or some other error string if the assertion was false. Getters like "getEval" will return
the result of the get command. "getAllLinks" will return a comma-delimited list of links.
http://localhost:4444/selenium-server/driver/?commandRequest=|open|http://www.yahoo.com||&sessionId=1234
The Selenium Server will not respond to the HTTP request until the browser has
finished performing the requested command; when it does, it will reply with the result of the
command (e.g. "OK" or "PASSED") in the body of the HTTP response. (Note that
-interactive
mode also works by sending these HTTP requests, so tests using
-interactive
mode will behave exactly like an external client driver.)
There are some special commands that only work in the Selenium Server. These commands are:
getNewBrowserSession( browserString, startURL )
Creates a new "sessionId" number (based on the current time in milliseconds) and launches the browser specified in browserString. We will then browse directly to startURL + "/selenium-server/RemoteRunner.html?sessionId=###" where "###" is the sessionId number. Only commands that are associated with the specified sessionId will be run by this browser.
browserString may be any one of the following:
*firefox [absolute path]
- Automatically launch a new Firefox process using a
custom Firefox profile. This profile will be automatically configured to use the Selenium Server
as a proxy and to have all annoying prompts ("save your password?" "forms are insecure"
"make Firefox your default browser?" disabled. You may optionally specify an absolute path to
your firefox executable, or just say "*firefox". If no absolute path is specified, we'll look for
firefox.exe in a default location (normally c:\program files\mozilla firefox\firefox.exe), which
you can override by setting the Java system property firefoxDefaultPath
to the
correct path to Firefox.*iexplore [absolute path]
- Automatically launch a new Internet Explorer process
using custom Windows registry settings. This process will be automatically configured to use the
Selenium Server as a proxy and to have all annoying prompts ("save your password?"
"forms are insecure" "make Firefox your default browser?" disabled. You may optionally specify an
absolute path to your iexplore executable, or just say "*iexplore". If no absolute path is
specified, we'll look for iexplore.exe in a default location (normally c:\program files\internet
explorer\iexplore.exe), which you can override by setting the Java system property
iexploreDefaultPath
to the correct path to Internet Explorer./path/to/my/browser [other arguments]
- You may also simply specify the absolute
path to your browser executable, or use a relative path to your executable (which we'll try to
find on your path). Warning: If you specify your own custom browser, it's up to you to
configure it correctly. At a minimum, you'll need to configure your browser to use the Selenium
Server as a proxy, and disable all browser-specific prompting.
testComplete( )
Kills the currently running browser and erases the old browser session. If the current browser
session was not launched using getNewBrowserSession
, or if that session number
doesn't exist in the server, this command will return an error.
shutDown( )
Causes the server to shut itself down, killing itself and all running browsers along with it.
Example:
cmd=getNewBrowserSession&1=*firefox&2=http://www.google.com
Got result: 1140738083345
cmd=open&1=http://www.google.com&sessionId=1140738083345
Got result: OK
cmd=type&1=q&2=hello world&sessionId=1140738083345
Got result: OK
cmd=testComplete&sessionId=1140738083345
Got result: OK
If you open a browser manually and do not specify a session ID, it will look for commands using the "null" session. You may then similarly send commands to this browser by not specifying a sessionId when issuing commands.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_JETTY_THREADS |
Constructor and Description |
---|
SeleniumServer() |
SeleniumServer(boolean slowResources) |
SeleniumServer(boolean slowResources,
RemoteControlConfiguration configuration)
Prepares a Jetty server with its HTTP handlers.
|
SeleniumServer(RemoteControlConfiguration configuration) |
Modifier and Type | Method and Description |
---|---|
void |
addNewStaticContent(File directory) |
void |
boot() |
protected static void |
checkArgsSanity(RemoteControlConfiguration configuration) |
static org.apache.commons.logging.Log |
configureLogging(LoggingOptions options,
boolean debugMode) |
protected void |
createJettyServer(boolean slowResources) |
protected HttpContext |
createRootContextWithProxyHandler(RemoteControlConfiguration configuration) |
void |
deregisterBrowserSession(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
De-registers a previously registered running browser session
|
void |
generateSSLCertsForLoggingHosts()
pre-compute the 1-16 SSL relays+certs for the logging hosts.
|
RemoteControlConfiguration |
getConfiguration() |
int |
getJettyThreads()
Get the number of threads that the server will use to configure the embedded Jetty instance.
|
int |
getPort() |
InputStream |
getResourceAsStream(String path) |
Server |
getServer()
Exposes the internal Jetty server used by Selenium.
|
void |
handleHTMLRunnerResults(HTMLResultsListener listener) |
static void |
main(String[] args)
Starts up the server on the specified port (or default if no port was specified) and then
starts interactive mode if specified.
|
protected ProxyHandler |
makeProxyHandler(RemoteControlConfiguration configuration) |
protected void |
readUserCommands() |
void |
registerBrowserSession(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
Registers a running browser session
|
protected void |
runHtmlSuite() |
void |
start()
Starts the Jetty server
|
void |
stop()
Stops the Jetty server
|
public SeleniumServer(RemoteControlConfiguration configuration) throws Exception
Exception
public SeleniumServer(boolean slowResources, RemoteControlConfiguration configuration) throws Exception
slowResources
- should the webserver return static resources more slowly? (Note that this
will not slow down ordinary RC test runs; this setting is used to debug Selenese HTML
tests.)configuration
- Remote Control configuration. Cannot be null.Exception
- you know, just in casepublic static void main(String[] args) throws Exception
args
- - either "-port" followed by a number, or "-interactive"Exception
- - you know, just in case.public static org.apache.commons.logging.Log configureLogging(LoggingOptions options, boolean debugMode)
protected void createJettyServer(boolean slowResources)
protected HttpContext createRootContextWithProxyHandler(RemoteControlConfiguration configuration)
public void generateSSLCertsForLoggingHosts()
generateSSLCertsForLoggingHosts
in interface SslCertificateGenerator
protected ProxyHandler makeProxyHandler(RemoteControlConfiguration configuration)
public void addNewStaticContent(File directory)
public void handleHTMLRunnerResults(HTMLResultsListener listener)
public void stop()
public RemoteControlConfiguration getConfiguration()
public int getPort()
public Server getServer()
public InputStream getResourceAsStream(String path) throws IOException
IOException
public void registerBrowserSession(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
public void deregisterBrowserSession(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
public int getJettyThreads()
protected void runHtmlSuite()
protected void readUserCommands() throws IOException
IOException
protected static void checkArgsSanity(RemoteControlConfiguration configuration) throws Exception
Exception
Copyright © 2013. All rights reserved.