com.thoughtworks.selenium
Class HttpCommandProcessor

java.lang.Object
  extended by com.thoughtworks.selenium.HttpCommandProcessor
All Implemented Interfaces:
CommandProcessor

public class HttpCommandProcessor
extends java.lang.Object
implements CommandProcessor

Sends commands and retrieves results via HTTP.

Author:
Ben Griffiths, Jez Humble

Constructor Summary
HttpCommandProcessor(java.lang.String serverHost, int serverPort, java.lang.String browserStartCommand, java.lang.String browserURL)
          Specifies a server host/port, a command to launch the browser, and a starting URL for the browser.
HttpCommandProcessor(java.lang.String pathToServlet, java.lang.String browserStartCommand, java.lang.String browserURL)
          Specifies the URL to the CommandBridge servlet, a command to launch the browser, and a starting URL for the browser.
 
Method Summary
protected  void closeResources(java.net.HttpURLConnection conn, java.io.Writer wr, java.io.Reader rdr)
           
 java.lang.String doCommand(java.lang.String commandName, java.lang.String[] args)
           
 java.lang.String executeCommandOnServlet(java.lang.String command)
          Sends the specified command string to the bridge servlet
 boolean getBoolean(java.lang.String commandName, java.lang.String[] args)
           
 boolean[] getBooleanArray(java.lang.String commandName, java.lang.String[] args)
           
protected  java.lang.String getCommandResponseAsString(java.lang.String command)
           
protected  java.net.HttpURLConnection getHttpUrlConnection(java.net.URL urlForServlet)
           
protected  java.io.Reader getInputStreamReader(java.net.HttpURLConnection conn)
           
 java.lang.Number getNumber(java.lang.String commandName, java.lang.String[] args)
           
 java.lang.Number[] getNumberArray(java.lang.String commandName, java.lang.String[] args)
           
protected  java.io.Writer getOutputStreamWriter(java.net.HttpURLConnection conn)
           
 java.lang.String getRemoteControlServerLocation()
           
protected  int getResponseCode(java.net.HttpURLConnection conn)
           
 java.lang.String getString(java.lang.String commandName, java.lang.String[] args)
           
 java.lang.String[] getStringArray(java.lang.String commandName, java.lang.String[] args)
           
 boolean hasSessionInProgress()
           
static java.lang.String[] parseCSV(java.lang.String input)
          Convert backslash-escaped comma-delimited string into String array.
 void setExtensionJs(java.lang.String extensionJs)
          This should be invoked before start().
protected  void setSessionInProgress(java.lang.String result)
           
 void start()
           
 void start(java.lang.Object optionsObject)
          Wraps the version of start() that takes a String parameter, sending it the result of calling toString() on optionsObject, which will likely be a BrowserConfigurationOptions instance.
 void start(java.lang.String optionsString)
           
 void stop()
           
protected  java.lang.String throwAssertionFailureExceptionOrError(java.lang.String message)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpCommandProcessor

public HttpCommandProcessor(java.lang.String serverHost,
                            int serverPort,
                            java.lang.String browserStartCommand,
                            java.lang.String browserURL)
Specifies a server host/port, a command to launch the browser, and a starting URL for the browser.

Parameters:
serverHost - - the host name on which the Selenium Server resides
serverPort - - the port on which the Selenium Server is listening
browserStartCommand - - the command string used to launch the browser, e.g. "*firefox" or "c:\\program files\\internet explorer\\iexplore.exe"
browserURL - - the starting URL including just a domain name. We'll start the browser pointing at the Selenium resources on this URL,
extensionJs - - extension Javascript for this session e.g. "http://www.google.com" would send the browser to "http://www.google.com/selenium-server/core/RemoteRunner.html"

HttpCommandProcessor

public HttpCommandProcessor(java.lang.String pathToServlet,
                            java.lang.String browserStartCommand,
                            java.lang.String browserURL)
Specifies the URL to the CommandBridge servlet, a command to launch the browser, and a starting URL for the browser.

Parameters:
pathToServlet - - the URL of the Selenium Server Driver, e.g. "http://localhost:4444/selenium-server/driver/" (don't forget the final slash!)
browserStartCommand - - the command string used to launch the browser, e.g. "*firefox" or "c:\\program files\\internet explorer\\iexplore.exe"
browserURL - - the starting URL including just a domain name. We'll start the browser pointing at the Selenium resources on this URL,
extensionJs - - extension Javascript for this session
Method Detail

getRemoteControlServerLocation

public java.lang.String getRemoteControlServerLocation()
Specified by:
getRemoteControlServerLocation in interface CommandProcessor

doCommand

public java.lang.String doCommand(java.lang.String commandName,
                                  java.lang.String[] args)
Specified by:
doCommand in interface CommandProcessor

throwAssertionFailureExceptionOrError

protected java.lang.String throwAssertionFailureExceptionOrError(java.lang.String message)

executeCommandOnServlet

public java.lang.String executeCommandOnServlet(java.lang.String command)
Sends the specified command string to the bridge servlet


getHttpUrlConnection

protected java.net.HttpURLConnection getHttpUrlConnection(java.net.URL urlForServlet)
                                                   throws java.io.IOException
Throws:
java.io.IOException

getOutputStreamWriter

protected java.io.Writer getOutputStreamWriter(java.net.HttpURLConnection conn)
                                        throws java.io.IOException
Throws:
java.io.IOException

getInputStreamReader

protected java.io.Reader getInputStreamReader(java.net.HttpURLConnection conn)
                                       throws java.io.IOException
Throws:
java.io.IOException

getResponseCode

protected int getResponseCode(java.net.HttpURLConnection conn)
                       throws java.io.IOException
Throws:
java.io.IOException

getCommandResponseAsString

protected java.lang.String getCommandResponseAsString(java.lang.String command)
                                               throws java.io.IOException
Throws:
java.io.IOException

closeResources

protected void closeResources(java.net.HttpURLConnection conn,
                              java.io.Writer wr,
                              java.io.Reader rdr)

setExtensionJs

public void setExtensionJs(java.lang.String extensionJs)
This should be invoked before start().

Specified by:
setExtensionJs in interface CommandProcessor
Parameters:
extensionJs - the extra extension Javascript to include in this browser session.

start

public void start()
Specified by:
start in interface CommandProcessor

start

public void start(java.lang.String optionsString)
Specified by:
start in interface CommandProcessor

start

public void start(java.lang.Object optionsObject)
Wraps the version of start() that takes a String parameter, sending it the result of calling toString() on optionsObject, which will likely be a BrowserConfigurationOptions instance.

Specified by:
start in interface CommandProcessor
Parameters:
optionsObject -

setSessionInProgress

protected void setSessionInProgress(java.lang.String result)

stop

public void stop()
Specified by:
stop in interface CommandProcessor

hasSessionInProgress

public boolean hasSessionInProgress()

getString

public java.lang.String getString(java.lang.String commandName,
                                  java.lang.String[] args)
Specified by:
getString in interface CommandProcessor

getStringArray

public java.lang.String[] getStringArray(java.lang.String commandName,
                                         java.lang.String[] args)
Specified by:
getStringArray in interface CommandProcessor

parseCSV

public static java.lang.String[] parseCSV(java.lang.String input)
Convert backslash-escaped comma-delimited string into String array. As described in SRC-CDP spec section 5.2.1.2, these strings are comma-delimited, but commas can be escaped with a backslash "\". Backslashes can also be escaped as a double-backslash.

Parameters:
input - the unparsed string, e.g. "veni\, vidi\, vici,c:\\foo\\bar,c:\\I came\, I \\saw\\\, I conquered"
Returns:
the string array resulting from parsing this string

getNumber

public java.lang.Number getNumber(java.lang.String commandName,
                                  java.lang.String[] args)
Specified by:
getNumber in interface CommandProcessor

getNumberArray

public java.lang.Number[] getNumberArray(java.lang.String commandName,
                                         java.lang.String[] args)
Specified by:
getNumberArray in interface CommandProcessor

getBoolean

public boolean getBoolean(java.lang.String commandName,
                          java.lang.String[] args)
Specified by:
getBoolean in interface CommandProcessor

getBooleanArray

public boolean[] getBooleanArray(java.lang.String commandName,
                                 java.lang.String[] args)
Specified by:
getBooleanArray in interface CommandProcessor


Copyright © 2012. All Rights Reserved.