org.unitils.selenium
Class WebDriverModule

java.lang.Object
  extended by org.unitils.selenium.WebDriverModule
All Implemented Interfaces:
org.unitils.core.Module

public class WebDriverModule
extends Object
implements org.unitils.core.Module

This module creates new WebDrivers.

Since:
1.0.0
Author:
Jeroen Horemans, Thomas De Rycke, Willemijn Wouters

Field Summary
protected static String BASE_URL_KEY
          property Unitils.properties: defines the base url.
protected static String BROWSER_NAME_KEY
          property Unitils.properties: defines the browser.
protected static String CHROME_BINARY_KEY
          property Unitils.properties: defines the location of the chrome binary.
protected static String CHROME_DRIVER_KEY
          property Unitils.properties: defines the location of the chrome driver.
protected static String DOWNLOADPATH
          property Unitils.properties: defines the folder where all the downloads are saved.
protected static String FILETYPE
          property Unitils.properties: defines all the downloadable types.
protected static String FIREFOX_BINARY_KEY
          property Unitils.properties: defines the location of the firefox binary.
protected static String IE_BINARY_KEY
          property Unitils.properties: defines location of the IE binary.
protected static String LIST_AUTOMATICALLY_DOWNLOAD
          default value FILETYPE.
protected static String LOGGING_FILE_PROP
          property Unitils.properties: all the info should be logged into a file?
protected static String LOGGINGPROP_BROWSER
          property Unitils.properties: should the browser info from selenium be logged?
protected static String LOGGINGPROP_CLIENT
          property Unitils.properties: should the client info from selenium be logged?
protected static String LOGGINGPROP_CONSOLE_ENABLED
          property Unitils.properties: defines if unitils-selenium should log the selenium logs in the console.
protected static String LOGGINGPROP_DRIVER
          property Unitils.properties: should the driver info from selenium be logged?
protected static String LOGGINGPROP_IE
          property Unitils.properties: all the IE info must be logged?
protected static String LOGGINGPROP_PERFORMANCE
          property Unitils.properties: should the performance info from selenium be logged?
protected static String LOGGINGPROP_PROFILER
          property Unitils.properties: should the profiler info from selenium be logged?
protected static String LOGGINGPROP_SERVER
          property Unitils.properties: should the server info from selenium be logged?
protected static String PACKAGENAME
          base package unitils-selenium.
protected static String PROXY_HOST_KEY
          property Unitils.properties: defines the proxy.
protected static String REMOTE_CAPABILITIES
           
protected static String REMOTE_URL_KEY
           
static String TARGETSUREFIREREPORTS
          location surefirereports.
 
Constructor Summary
WebDriverModule()
           
 
Method Summary
 void afterInit()
           
protected  void checkChromeDriver(String bit, ClassLoader classLoader)
          This method checks if the location of the chrome driver is already in the system.
protected  void checkFirefoxDriver()
          This method checks if their is a system property 'webdriver.firefox.bin' and checks if it exists.
protected  void checkIEDriver(String bit, ClassLoader classLoader)
          This method checks if there is a system property 'webdriver.ie.driver' and checks if the location exists.
 boolean checkIfDriverIsAlreadyInSystem(String systemProp, String driver, String systemVarDriver)
          Check if the system variable already exists in the system and check if the variable is a valid location.
 boolean checkIfDriverPropertyExistsInUnitilsProperties(String key, String driver, String systemKey)
          Check if the key exists in the unitils.properties and check if the value for that key is a valid location.
 String copyDriverIntoNewTempFile(URL url, String name)
          Copies the driver into a new temp file.
protected static String createLogNewDriver(String systemVarDriver, String absPath)
          logmessage: The driver in unitils-selenium is used.
protected static String getAbsoluteDownloadPath(String path)
          Checks if the file exists and returns the absolute path of the location.
protected  Object getElement(org.openqa.selenium.WebDriver webdriver, Class<?> type)
          This is the actual method that creates an object of the correct type and initialises all the elements.
 org.unitils.core.TestListener getTestListener()
           
 void init(Properties configuration)
           
 void initBaseUrl(Object testObject)
          All the elements with the @BaseUrlString will be initialised with the base url value of the unitils.properties.
 void initElements(Object testObject)
          * Searches all the fields with the WebPage annotation and sets the correct elements.
 void initWebDriver(Object testObject)
          Initialises the webdriver.
protected  void killWebDriver(Object testObject)
          All the webdrivers (all the fields with the TestWebDriver of the testObject will be killed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKAGENAME

protected static final String PACKAGENAME
base package unitils-selenium.

See Also:
Constant Field Values

BROWSER_NAME_KEY

protected static final String BROWSER_NAME_KEY
property Unitils.properties: defines the browser.

See Also:
Constant Field Values

REMOTE_CAPABILITIES

protected static final String REMOTE_CAPABILITIES
See Also:
Constant Field Values

BASE_URL_KEY

protected static final String BASE_URL_KEY
property Unitils.properties: defines the base url.

See Also:
Constant Field Values

REMOTE_URL_KEY

protected static final String REMOTE_URL_KEY
See Also:
Constant Field Values

PROXY_HOST_KEY

protected static final String PROXY_HOST_KEY
property Unitils.properties: defines the proxy.

See Also:
Constant Field Values

DOWNLOADPATH

protected static final String DOWNLOADPATH
property Unitils.properties: defines the folder where all the downloads are saved.

See Also:
Constant Field Values

FILETYPE

protected static final String FILETYPE
property Unitils.properties: defines all the downloadable types.

See Also:
Constant Field Values

LIST_AUTOMATICALLY_DOWNLOAD

protected static final String LIST_AUTOMATICALLY_DOWNLOAD
default value FILETYPE.

See Also:
Constant Field Values

FIREFOX_BINARY_KEY

protected static final String FIREFOX_BINARY_KEY
property Unitils.properties: defines the location of the firefox binary.

See Also:
Constant Field Values

IE_BINARY_KEY

protected static final String IE_BINARY_KEY
property Unitils.properties: defines location of the IE binary.

See Also:
Constant Field Values

CHROME_DRIVER_KEY

protected static final String CHROME_DRIVER_KEY
property Unitils.properties: defines the location of the chrome driver.

See Also:
Constant Field Values

CHROME_BINARY_KEY

protected static final String CHROME_BINARY_KEY
property Unitils.properties: defines the location of the chrome binary.

See Also:
Constant Field Values

LOGGINGPROP_CONSOLE_ENABLED

protected static final String LOGGINGPROP_CONSOLE_ENABLED
property Unitils.properties: defines if unitils-selenium should log the selenium logs in the console.

See Also:
Constant Field Values

LOGGINGPROP_PERFORMANCE

protected static final String LOGGINGPROP_PERFORMANCE
property Unitils.properties: should the performance info from selenium be logged?

See Also:
Constant Field Values

LOGGINGPROP_BROWSER

protected static final String LOGGINGPROP_BROWSER
property Unitils.properties: should the browser info from selenium be logged?

See Also:
Constant Field Values

LOGGINGPROP_CLIENT

protected static final String LOGGINGPROP_CLIENT
property Unitils.properties: should the client info from selenium be logged?

See Also:
Constant Field Values

LOGGINGPROP_DRIVER

protected static final String LOGGINGPROP_DRIVER
property Unitils.properties: should the driver info from selenium be logged?

See Also:
Constant Field Values

LOGGINGPROP_PROFILER

protected static final String LOGGINGPROP_PROFILER
property Unitils.properties: should the profiler info from selenium be logged?

See Also:
Constant Field Values

LOGGINGPROP_SERVER

protected static final String LOGGINGPROP_SERVER
property Unitils.properties: should the server info from selenium be logged?

See Also:
Constant Field Values

LOGGING_FILE_PROP

protected static final String LOGGING_FILE_PROP
property Unitils.properties: all the info should be logged into a file?

See Also:
Constant Field Values

LOGGINGPROP_IE

protected static final String LOGGINGPROP_IE
property Unitils.properties: all the IE info must be logged?

See Also:
Constant Field Values

TARGETSUREFIREREPORTS

public static final String TARGETSUREFIREREPORTS
location surefirereports.

See Also:
Constant Field Values
Constructor Detail

WebDriverModule

public WebDriverModule()
Method Detail

init

public void init(Properties configuration)
Specified by:
init in interface org.unitils.core.Module

afterInit

public void afterInit()
Specified by:
afterInit in interface org.unitils.core.Module

initWebDriver

public void initWebDriver(Object testObject)
Initialises the webdriver. The method searches if there are fields with the TestWebDriver and uses the browser choice (in unitils.properties) to create the driver.

Parameters:
testObject - : the testobject.

getAbsoluteDownloadPath

protected static String getAbsoluteDownloadPath(String path)
Checks if the file exists and returns the absolute path of the location. If the location isn't found than an empty string will be returned.

Parameters:
path - : the relative or absolute path of a file.
Returns:
String

killWebDriver

protected void killWebDriver(Object testObject)
All the webdrivers (all the fields with the TestWebDriver of the testObject will be killed.

Parameters:
testObject - : the testobject.

initBaseUrl

public void initBaseUrl(Object testObject)
All the elements with the @BaseUrlString will be initialised with the base url value of the unitils.properties.

Parameters:
testObject - : the testobject.

initElements

public void initElements(Object testObject)
* Searches all the fields with the WebPage annotation and sets the correct elements.

Parameters:
testObject - : the testobject.

checkChromeDriver

protected void checkChromeDriver(String bit,
                                 ClassLoader classLoader)
This method checks if the location of the chrome driver is already in the system. If this is not the case than the method will look if CHROME_DRIVER_KEY is defined in the unitils.properties. If there isn't a valid location in the system or in the unitils.properties than this method will use the driver that is added with unitils.selenium.

Parameters:
bit - : should be 32 or 64
classLoader - : the classloader used by this class.

checkFirefoxDriver

protected void checkFirefoxDriver()
This method checks if their is a system property 'webdriver.firefox.bin' and checks if it exists. Otherwise it will check the unitils.properties if their is a property FIREFOX_BINARY_KEY in the unitils.properties.


checkIEDriver

protected void checkIEDriver(String bit,
                             ClassLoader classLoader)
This method checks if there is a system property 'webdriver.ie.driver' and checks if the location exists. If this doesn't exist than he looks if you've defined another IE driver ( IE_BINARY_KEY in your unitils.properties. The last option is that it uses the driver that is given by unitils-selenium.

Parameters:
bit - : should be 32 or 64
classLoader - : the classloader used by this class.

checkIfDriverIsAlreadyInSystem

public boolean checkIfDriverIsAlreadyInSystem(String systemProp,
                                              String driver,
                                              String systemVarDriver)
Check if the system variable already exists in the system and check if the variable is a valid location.

Parameters:
systemProp - : the location of the driver in the system.
driver - : the name of the driver.
systemVarDriver - : the name of the system property.
Returns:
boolean

checkIfDriverPropertyExistsInUnitilsProperties

public boolean checkIfDriverPropertyExistsInUnitilsProperties(String key,
                                                              String driver,
                                                              String systemKey)
Check if the key exists in the unitils.properties and check if the value for that key is a valid location.

Parameters:
key - : the key to find the correct driver location in the unitils.properties.
driver - : the type of driver.
systemKey - : the system key where the module should set the new location of the driver.
Returns:
boolean

copyDriverIntoNewTempFile

public String copyDriverIntoNewTempFile(URL url,
                                        String name)
Copies the driver into a new temp file.

Parameters:
url - : the location of the driver.
name - : the name of the driver.
Returns:
String

getElement

protected Object getElement(org.openqa.selenium.WebDriver webdriver,
                            Class<?> type)
This is the actual method that creates an object of the correct type and initialises all the elements.

Parameters:
webdriver - : should be of type WebDriver
type: - the class that should be initialised.
Returns:
Object

getTestListener

public org.unitils.core.TestListener getTestListener()
Specified by:
getTestListener in interface org.unitils.core.Module

createLogNewDriver

protected static String createLogNewDriver(String systemVarDriver,
                                           String absPath)
logmessage: The driver in unitils-selenium is used.

Parameters:
systemVarDriver - : the system key of the driver.
absPath - : the value of the system key of the driver.
Returns:
String


Copyright © 2015. All Rights Reserved.