org.openqa.selenium.server
Class SeleniumServer

java.lang.Object
  extended by org.openqa.selenium.server.SeleniumServer

public class SeleniumServer
extends java.lang.Object

Provides a server that can launch/terminate browsers and can receive remote Selenium commands over HTTP and send them on to the browser.

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:

  1. Client-Configured Proxy Requests: By configuring your browser to use the Selenium Server as an HTTP proxy, you can use the Selenium Server as a web proxy. This allows the server to create a virtual "/selenium-server" directory on every website that you visit using the proxy.
  2. Remote Browser Commands: If the browser goes to "/selenium-server/RemoteRunner.html?sessionId=1234" on any website via the Client-Configured Proxy, it will ask the Selenium Server for work to do, like this:
    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.
  3. Driver Commands: Clients may send commands to the Selenium Server over HTTP. Command requests should look like this:
    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:

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

The "null" session

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.

Author:
plightbo

Field Summary
static int DEFAULT_PORT
           
static int DEFAULT_TIMEOUT
           
static int timeoutInSeconds
           
 
Constructor Summary
SeleniumServer()
           
SeleniumServer(int port)
           
SeleniumServer(int port, boolean slowResources)
           
SeleniumServer(int port, boolean slowResources, boolean multiWindow)
          Prepares a Jetty server with its HTTP handlers.
 
Method Summary
 void addNewStaticContent(java.io.File directory)
           
static java.lang.String getDebugURL()
           
static int getDefaultPort()
           
static java.io.File getFirefoxProfileTemplate()
           
static java.lang.String getForcedBrowserMode()
           
 int getPort()
           
static int getPortDriversShouldContact()
           
 java.io.InputStream getResourceAsStream(java.lang.String path)
           
 org.mortbay.jetty.Server getServer()
          Exposes the internal Jetty server used by Selenium.
static int getTimeoutInSeconds()
           
 void handleHTMLRunnerResults(HTMLResultsListener listener)
           
static boolean isAlwaysProxy()
           
static boolean isDebugMode()
           
static boolean isForceProxyChain()
           
 boolean isMultiWindow()
           
static boolean isProxyInjectionMode()
           
static void log(java.lang.String logMessages)
           
static void main(java.lang.String[] args)
          Starts up the server on the specified port (or default if no port was specified) and then starts interactive mode if specified.
 void registerBrowserLauncher(java.lang.String sessionId, BrowserLauncher launcher)
          Registers a running browser with a specific sessionID
static boolean reusingBrowserSessions()
           
static void setDebugMode(boolean debugMode)
           
static void setDontInjectRegex(java.lang.String dontInjectRegex)
           
static void setForcedBrowserMode(java.lang.String s)
           
static void setForceProxyChain(boolean force)
           
 void setProxyInjectionMode(boolean proxyInjectionMode)
           
static void setReusingBrowserSessions(boolean reusingBrowserSessions)
           
static boolean shouldInject(java.lang.String path)
           
 void start()
          Starts the Jetty server
 void stop()
          Stops the Jetty server
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
See Also:
Constant Field Values

timeoutInSeconds

public static int timeoutInSeconds
Constructor Detail

SeleniumServer

public SeleniumServer(int port,
                      boolean slowResources,
                      boolean multiWindow)
               throws java.lang.Exception
Prepares a Jetty server with its HTTP handlers.

Parameters:
port - the port to start on
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.)
multiWindow - run the tests in the "multi-Window" layout, without using the embedded iframe
Throws:
java.lang.Exception - you know, just in case

SeleniumServer

public SeleniumServer(int port,
                      boolean slowResources)
               throws java.lang.Exception
Throws:
java.lang.Exception

SeleniumServer

public SeleniumServer(int port)
               throws java.lang.Exception
Throws:
java.lang.Exception

SeleniumServer

public SeleniumServer()
               throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Starts up the server on the specified port (or default if no port was specified) and then starts interactive mode if specified.

Parameters:
args - - either "-port" followed by a number, or "-interactive"
Throws:
java.lang.Exception - - you know, just in case.

getDefaultPort

public static int getDefaultPort()

getFirefoxProfileTemplate

public static java.io.File getFirefoxProfileTemplate()

addNewStaticContent

public void addNewStaticContent(java.io.File directory)

handleHTMLRunnerResults

public void handleHTMLRunnerResults(HTMLResultsListener listener)

start

public void start()
           throws java.lang.Exception
Starts the Jetty server

Throws:
java.lang.Exception

isForceProxyChain

public static boolean isForceProxyChain()

setForceProxyChain

public static void setForceProxyChain(boolean force)

stop

public void stop()
Stops the Jetty server


getPort

public int getPort()

isMultiWindow

public boolean isMultiWindow()

getServer

public org.mortbay.jetty.Server getServer()
Exposes the internal Jetty server used by Selenium. This lets users add their own webapp to the Selenium Server jetty instance. It is also a minor violation of encapsulation principles (what if we stop using Jetty?) but life is too short to worry about such things.

Returns:
the internal Jetty server, pre-configured with the /selenium-server context as well as the proxy server on /

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path)
                                        throws java.io.IOException
Throws:
java.io.IOException

registerBrowserLauncher

public void registerBrowserLauncher(java.lang.String sessionId,
                                    BrowserLauncher launcher)
Registers a running browser with a specific sessionID


isDebugMode

public static boolean isDebugMode()

setDebugMode

public static void setDebugMode(boolean debugMode)

isProxyInjectionMode

public static boolean isProxyInjectionMode()

isAlwaysProxy

public static boolean isAlwaysProxy()

getPortDriversShouldContact

public static int getPortDriversShouldContact()

setProxyInjectionMode

public void setProxyInjectionMode(boolean proxyInjectionMode)

getForcedBrowserMode

public static java.lang.String getForcedBrowserMode()

getTimeoutInSeconds

public static int getTimeoutInSeconds()

setForcedBrowserMode

public static void setForcedBrowserMode(java.lang.String s)

setDontInjectRegex

public static void setDontInjectRegex(java.lang.String dontInjectRegex)

reusingBrowserSessions

public static boolean reusingBrowserSessions()

shouldInject

public static boolean shouldInject(java.lang.String path)

getDebugURL

public static java.lang.String getDebugURL()

log

public static void log(java.lang.String logMessages)

setReusingBrowserSessions

public static void setReusingBrowserSessions(boolean reusingBrowserSessions)


Copyright © 2006 null. All Rights Reserved.