com.saucelabs.selenium.client.factory
Class SeleniumFactory

java.lang.Object
  extended by com.saucelabs.selenium.client.factory.SeleniumFactory

public class SeleniumFactory
extends Object

Factory of Selenium.

Compared to directly initializing DefaultSelenium, this additional indirection allows the build script or a CI server to control how you connect to the selenium. This makes it easier to run the same set of tests in different environments without modifying the test code.

This is analogous to how you connect to JDBC — you normally don't directly instantiate a specific driver, and instead you do DriverManager.getConnection(String).

Author:
Kohsuke Kawaguchi

Constructor Summary
SeleniumFactory()
           
 
Method Summary
 SeleniumFactory clone()
          Creates a clone of this factory that's identically configured.
static com.thoughtworks.selenium.Selenium create()
          Uses a driver specified by the 'SELENIUM_DRIVER' system property or the environment variable, and run the test against the domain specified in 'SELENIUM_STARTING_URL' system property or the environment variable.
static com.thoughtworks.selenium.Selenium create(String browserURL)
          Uses a driver specified by the 'SELENIUM_DRIVER' system property or the environment variable, and run the test against the specified domain.
static com.thoughtworks.selenium.Selenium create(String driverUri, String browserURL)
          Uses the specified driver and the test domain and create a driver instance.
 com.thoughtworks.selenium.Selenium createSelenium()
          Based on the current configuration, instantiate a Selenium driver and returns it.
 com.thoughtworks.selenium.Selenium createSelenium(String browserURL)
          Based on the current configuration, instantiate a Selenium driver and returns it.
 ClassLoader getClassLoader()
          Gets the classloader set by the setClassLoader(ClassLoader).
 Map<String,Object> getProperties()
          Returns the live map that stores the property values.
 Object getProperty(String key)
          Retrieves the value of the property previously set.
 String getUri()
          Gets the driver URI set by the setUri(String)
 SeleniumFactory setClassLoader(ClassLoader cl)
          Sets the classloader used for searching the driver.
 SeleniumFactory setProperty(String key, Object value)
          Sets other misc.
 SeleniumFactory setUri(String uri)
          Sets the URI of the Selenium driver.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SeleniumFactory

public SeleniumFactory()
Method Detail

create

public static com.thoughtworks.selenium.Selenium create()
Uses a driver specified by the 'SELENIUM_DRIVER' system property or the environment variable, and run the test against the domain specified in 'SELENIUM_STARTING_URL' system property or the environment variable.

If exists, the system property takes precedence over the environment variable.

This is just a convenient short-cut for new SeleniumFactory().createSelenium().


create

public static com.thoughtworks.selenium.Selenium create(String browserURL)
Uses a driver specified by the 'SELENIUM_DRIVER' system property or the environment variable, and run the test against the specified domain.

If exists, the system property takes precedence over the environment variable.

This is just a convenient short-cut for new SeleniumFactory().createSelenium(browserURL).

Parameters:
browserURL - See the parameter of the same name in DefaultSelenium.DefaultSelenium(String, int, String, String). This specifies the domain name in the format of "http://foo.example.com" where the test occurs.

create

public static com.thoughtworks.selenium.Selenium create(String driverUri,
                                                        String browserURL)
Uses the specified driver and the test domain and create a driver instance.

This is just a convenient short-cut for new SeleniumFactory().setUri(driverUri).createSelenium(browserURL).

Parameters:
driverUri - The URI indicating the Selenium driver to be instantiated.
browserURL - See the parameter of the same name in DefaultSelenium.DefaultSelenium(String, int, String, String). This specifies the domain name in the format of "http://foo.example.com" where the test occurs.

getUri

public String getUri()
Gets the driver URI set by the setUri(String)


setUri

public SeleniumFactory setUri(String uri)
Sets the URI of the Selenium driver.

Initially, the value of the 'SELENIUM_DRIVER' system property of the environment variable is read and set. The system property takes precedence over the environment variable.

Returns:
'this' instance to facilitate the fluent API pattern.

getClassLoader

public ClassLoader getClassLoader()
Gets the classloader set by the setClassLoader(ClassLoader).


setClassLoader

public SeleniumFactory setClassLoader(ClassLoader cl)
Sets the classloader used for searching the driver. Initially set to Thread.currentThread().getContextClassLoader() of the thread that instantiated this factory.

Returns:
'this' instance to facilitate the fluent API pattern.

setProperty

public SeleniumFactory setProperty(String key,
                                   Object value)
Sets other misc. driver-specific properties. Refer to the driver implementation for the valid properties and their expected types.

Returns:
'this' instance to facilitate the fluent API pattern.

getProperty

public Object getProperty(String key)
Retrieves the value of the property previously set.


getProperties

public Map<String,Object> getProperties()
Returns the live map that stores the property values. Convenient for bulk update operations.

Returns:
never null

clone

public SeleniumFactory clone()
Creates a clone of this factory that's identically configured.

Properties are only shallowly copied.

Overrides:
clone in class Object

createSelenium

public com.thoughtworks.selenium.Selenium createSelenium()
Based on the current configuration, instantiate a Selenium driver and returns it.

This version implicitly retrieves the 'browserURL' parameter and calls into createSelenium(String) by checking the 'SELENIUM_STARTING_URL' system property or the environment variable. The system property takes precedence over the environment variable.

Returns:
never null
Throws:
IllegalArgumentException - if the configuration is invalid, or the driver failed to instantiate.

createSelenium

public com.thoughtworks.selenium.Selenium createSelenium(String browserURL)
Based on the current configuration, instantiate a Selenium driver and returns it.

Returns:
never null
Throws:
IllegalArgumentException - if the configuration is invalid, or the driver failed to instantiate.


Copyright © 2010. All Rights Reserved.