com.thoughtworks.selenium
Class HttpCommandProcessor

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

public class HttpCommandProcessor
extends Object
implements com.thoughtworks.selenium.CommandProcessor

Sends commands and retrieves results via HTTP.

Author:
Ben Griffiths, Jez Humble

Constructor Summary
HttpCommandProcessor(String serverHost, int serverPort, String browserStartCommand, String browserURL)
          Specifies a server host/port, a command to launch the browser, and a starting URL for the browser.
HttpCommandProcessor(String pathToServlet, String browserStartCommand, 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(HttpURLConnection conn, Writer wr, Reader rdr)
           
 String doCommand(String commandName, String[] args)
           
 String executeCommandOnServlet(String command)
          Sends the specified command string to the bridge servlet
 boolean getBoolean(String commandName, String[] args)
           
 boolean[] getBooleanArray(String commandName, String[] args)
           
protected  String getCommandResponseAsString(String command)
           
protected  HttpURLConnection getHttpUrlConnection(URL urlForServlet)
           
protected  Reader getInputStreamReader(HttpURLConnection conn)
           
 Number getNumber(String commandName, String[] args)
           
 Number[] getNumberArray(String commandName, String[] args)
           
protected  Writer getOutputStreamWriter(HttpURLConnection conn)
           
 String getRemoteControlServerLocation()
           
protected  int getResponseCode(HttpURLConnection conn)
           
 String getString(String commandName, String[] args)
           
 String[] getStringArray(String commandName, String[] args)
           
 boolean hasSessionInProgress()
           
static String[] parseCSV(String input)
          Convert backslash-escaped comma-delimited string into String array.
 void setExtensionJs(String extensionJs)
          This should be invoked before start().
protected  void setSessionInProgress(String result)
           
 void start()
           
 void start(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(String optionsString)
           
 void stop()
           
protected  String throwAssertionFailureExceptionOrError(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(String serverHost,
                            int serverPort,
                            String browserStartCommand,
                            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(String pathToServlet,
                            String browserStartCommand,
                            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 String getRemoteControlServerLocation()
Specified by:
getRemoteControlServerLocation in interface com.thoughtworks.selenium.CommandProcessor

doCommand

public String doCommand(String commandName,
                        String[] args)
Specified by:
doCommand in interface com.thoughtworks.selenium.CommandProcessor

throwAssertionFailureExceptionOrError

protected String throwAssertionFailureExceptionOrError(String message)

executeCommandOnServlet

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


getHttpUrlConnection

protected HttpURLConnection getHttpUrlConnection(URL urlForServlet)
                                          throws IOException
Throws:
IOException

getOutputStreamWriter

protected Writer getOutputStreamWriter(HttpURLConnection conn)
                                throws IOException
Throws:
IOException

getInputStreamReader

protected Reader getInputStreamReader(HttpURLConnection conn)
                               throws IOException
Throws:
IOException

getResponseCode

protected int getResponseCode(HttpURLConnection conn)
                       throws IOException
Throws:
IOException

getCommandResponseAsString

protected String getCommandResponseAsString(String command)
                                     throws IOException
Throws:
IOException

closeResources

protected void closeResources(HttpURLConnection conn,
                              Writer wr,
                              Reader rdr)

setExtensionJs

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

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

start

public void start()
Specified by:
start in interface com.thoughtworks.selenium.CommandProcessor

start

public void start(String optionsString)
Specified by:
start in interface com.thoughtworks.selenium.CommandProcessor

start

public void start(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 com.thoughtworks.selenium.CommandProcessor
Parameters:
optionsObject -

setSessionInProgress

protected void setSessionInProgress(String result)

stop

public void stop()
Specified by:
stop in interface com.thoughtworks.selenium.CommandProcessor

hasSessionInProgress

public boolean hasSessionInProgress()

getString

public String getString(String commandName,
                        String[] args)
Specified by:
getString in interface com.thoughtworks.selenium.CommandProcessor

getStringArray

public String[] getStringArray(String commandName,
                               String[] args)
Specified by:
getStringArray in interface com.thoughtworks.selenium.CommandProcessor

parseCSV

public static String[] parseCSV(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 Number getNumber(String commandName,
                        String[] args)
Specified by:
getNumber in interface com.thoughtworks.selenium.CommandProcessor

getNumberArray

public Number[] getNumberArray(String commandName,
                               String[] args)
Specified by:
getNumberArray in interface com.thoughtworks.selenium.CommandProcessor

getBoolean

public boolean getBoolean(String commandName,
                          String[] args)
Specified by:
getBoolean in interface com.thoughtworks.selenium.CommandProcessor

getBooleanArray

public boolean[] getBooleanArray(String commandName,
                                 String[] args)
Specified by:
getBooleanArray in interface com.thoughtworks.selenium.CommandProcessor


Copyright © 2012. All Rights Reserved.