org.alfresco.webdrone
Class WebDroneImpl

java.lang.Object
  extended by org.alfresco.webdrone.WebDroneImpl
All Implemented Interfaces:
WebDrone

public class WebDroneImpl
extends Object
implements WebDrone

An Alfresco web browser simulator that uses Selenium WebDriver as a base with added helper methods that are specific to Alfresco site and version.

Since:
1.0
Author:
Michael Suzuki

Constructor Summary
WebDroneImpl(org.openqa.selenium.WebDriver driver, AlfrescoVersion alfrescoVersion)
          Constructor with default time set to 2000 milliseconds.
WebDroneImpl(org.openqa.selenium.WebDriver driver, AlfrescoVersion alfrescoVersion, long defaultWaitTime, long maxPageRenderWaitTime)
          The main constructor
 
Method Summary
 Object executeJavaScript(String js)
          Injects java script directly to the page to invoke a change on the page's java script
protected  void finalize()
          Clean up WebDrone.
 org.openqa.selenium.WebElement find(org.openqa.selenium.By by)
          Helper method to find a WebElement.
 List<org.openqa.selenium.WebElement> findAll(org.openqa.selenium.By by)
          Helper method to find all WebElement on HTML page
 org.openqa.selenium.WebElement findAndWait(org.openqa.selenium.By criteria)
          Helper method to find and return a slow loading WebElement.
 org.openqa.selenium.WebElement findAndWait(org.openqa.selenium.By by, long limit)
          Helper method to find a WebElement with a time limit in milliseconds.
 org.openqa.selenium.WebElement findAndWait(org.openqa.selenium.By by, long limit, long interval)
          Helper method to find a WebElement with a time limit in milliseconds.
 org.openqa.selenium.WebElement findAndWaitById(String id)
          Helper method to find and return a slow loading WebElement by id.
 List<org.openqa.selenium.WebElement> findAndWaitForElements(org.openqa.selenium.By criteria)
          Helper method to find and return a slow loading collection of WebElement.
 List<org.openqa.selenium.WebElement> findAndWaitForElements(org.openqa.selenium.By criteria, long waitTime)
          Helper method to find and return a slow loading collection of WebElement.
 org.openqa.selenium.WebElement findById(String id)
          Helper method to find a WebElement by id using the WebDroneProperties to resolve the key value of the id.
 AlfrescoVersion getAlfrescoVersion()
          Gets the AlfrescoVersion that is used.
 Set<org.openqa.selenium.Cookie> getCookies()
          Extract cookie information
 HtmlPage getCurrentPage()
          Gets the current page in the form of a page object based on the Alfresco site type.
 String getCurrentUrl()
          Get the URL displayed on the browser.
 long getDefaultWaitTime()
           
 org.openqa.selenium.WebDriver getDriver()
           
 String getElement(String key)
          Gets the HTML element id value for the given key.
 long getMaxPageRenderWaitTime()
           
 String getPageSouce()
          The HTML source code of the page viewed.
 File getScreenShot()
          Grabs a screen shot of what the WebDriver is currently viewing.
 String getTitle()
          Title of the page.
 boolean isChromeBrowser()
          Checks to see if driver used is chrome.
 boolean isHtmlUnit()
          Checks to see if driver used is HtmlUnit.
 boolean isReady()
           
 boolean isRenderComplete(long waitTime)
          Verify if loading of the page is complete using java script to validate state of the HTML DOM.
 void mouseOver(org.openqa.selenium.WebElement element)
          Recreating the action of hovering over a particular HTML element on a page.
 void navigateTo(String url)
          Navigate the browser to given URL.
 void quit()
          End Browser session.
 void refresh()
          Acts as a refresh page action similar to F5 key.
 void setDefaultWaitTime(long defaultWaitTime)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WebDroneImpl

public WebDroneImpl(org.openqa.selenium.WebDriver driver,
                    AlfrescoVersion alfrescoVersion)
Constructor with default time set to 2000 milliseconds.

Parameters:
driver - WebDriver the browser behaviour
alfrescoVersion - AlfrescoVersion version

WebDroneImpl

public WebDroneImpl(org.openqa.selenium.WebDriver driver,
                    AlfrescoVersion alfrescoVersion,
                    long defaultWaitTime,
                    long maxPageRenderWaitTime)
The main constructor

Parameters:
driver - WebDriver the browser behaviour
alfrescoVersion - AlfrescoVersion version
defaultWaitTime - time to wait in milliseconds
maxPageRenderWaitTime - maximum time to wait for page to render
Method Detail

isReady

public boolean isReady()
Specified by:
isReady in interface WebDrone
Returns:
true if the instance is ready for browser requests, otherwise false.

quit

public void quit()
Description copied from interface: WebDrone
End Browser session.

Specified by:
quit in interface WebDrone

navigateTo

public void navigateTo(String url)
Description copied from interface: WebDrone
Navigate the browser to given URL.

Specified by:
navigateTo in interface WebDrone
Parameters:
url - String URL

getCurrentPage

public HtmlPage getCurrentPage()
Description copied from interface: WebDrone
Gets the current page in the form of a page object based on the Alfresco site type. If site type is of Share then the page returned will be a SharePage object.

Specified by:
getCurrentPage in interface WebDrone
Returns:
HtmlPage page object of current view

find

public org.openqa.selenium.WebElement find(org.openqa.selenium.By by)
Helper method to find a WebElement.

Specified by:
find in interface WebDrone
Parameters:
by - By criteria to identify HTML element
Returns:
WebElement HTML element

findById

public org.openqa.selenium.WebElement findById(String id)
Helper method to find a WebElement by id using the WebDroneProperties to resolve the key value of the id.

Specified by:
findById in interface WebDrone
Parameters:
id - the html element id
Returns:
WebElement HTML element

findAll

public List<org.openqa.selenium.WebElement> findAll(org.openqa.selenium.By by)
Helper method to find all WebElement on HTML page

Specified by:
findAll in interface WebDrone
Parameters:
by - By criteria to identify HTML element
Returns:
WebElement HTML element

findAndWait

public org.openqa.selenium.WebElement findAndWait(org.openqa.selenium.By by,
                                                  long limit)
Helper method to find a WebElement with a time limit in milliseconds. During the wait period it will check for the element every 100 millisecond.

Specified by:
findAndWait in interface WebDrone
Parameters:
by - By criteria to search by
millisecond - time limit
Returns:
WebElement HTML element

findAndWait

public org.openqa.selenium.WebElement findAndWait(org.openqa.selenium.By by,
                                                  long limit,
                                                  long interval)
Helper method to find a WebElement with a time limit in milliseconds. During the wait period it will check for the element every 100 millisecond.

Specified by:
findAndWait in interface WebDrone
Parameters:
by - By criteria to search by
limit - time limit
interval - polling frequency
Returns:
WebElement HTML element

isRenderComplete

public boolean isRenderComplete(long waitTime)
Verify if loading of the page is complete using java script to validate state of the HTML DOM.

Specified by:
isRenderComplete in interface WebDrone
Parameters:
waitTime - max time to look for an element
Returns:
true if page has been loaded

findAndWaitById

public org.openqa.selenium.WebElement findAndWaitById(String id)
Helper method to find and return a slow loading WebElement by id.

Specified by:
findAndWaitById in interface WebDrone
Parameters:
id - String identifier
Returns:
WebElement HTML element

findAndWait

public org.openqa.selenium.WebElement findAndWait(org.openqa.selenium.By criteria)
Helper method to find and return a slow loading WebElement.

Specified by:
findAndWait in interface WebDrone
Parameters:
criteria - By search criteria
Returns:
WebElement HTML element

findAndWaitForElements

public List<org.openqa.selenium.WebElement> findAndWaitForElements(org.openqa.selenium.By criteria,
                                                                   long waitTime)
Helper method to find and return a slow loading collection of WebElement.

Specified by:
findAndWaitForElements in interface WebDrone
Parameters:
criteria - By search criteria
waitTime - milliseconds to wait
Returns:
Collection of WebElement HTML elements

findAndWaitForElements

public List<org.openqa.selenium.WebElement> findAndWaitForElements(org.openqa.selenium.By criteria)
Helper method to find and return a slow loading collection of WebElement.

Specified by:
findAndWaitForElements in interface WebDrone
Parameters:
criteria - By search criteria
Returns:
Collection of WebElement HTML elements

setDefaultWaitTime

public void setDefaultWaitTime(long defaultWaitTime)

getDefaultWaitTime

public long getDefaultWaitTime()

mouseOver

public void mouseOver(org.openqa.selenium.WebElement element)
Recreating the action of hovering over a particular HTML element on a page.

Specified by:
mouseOver in interface WebDrone
Parameters:
element - WebElement target

getElement

public final String getElement(String key)
Description copied from interface: WebDrone
Gets the HTML element id value for the given key.

Specified by:
getElement in interface WebDrone
Parameters:
key - String HTML element id
Returns:
String value of key

getCurrentUrl

public String getCurrentUrl()
Description copied from interface: WebDrone
Get the URL displayed on the browser.

Specified by:
getCurrentUrl in interface WebDrone
Returns:
String URL

executeJavaScript

public Object executeJavaScript(String js)
Injects java script directly to the page to invoke a change on the page's java script

Specified by:
executeJavaScript in interface WebDrone
Parameters:
js - String script
Returns:
Object reponse of the javascript

getTitle

public String getTitle()
Description copied from interface: WebDrone
Title of the page.

Specified by:
getTitle in interface WebDrone

getAlfrescoVersion

public AlfrescoVersion getAlfrescoVersion()
Description copied from interface: WebDrone
Gets the AlfrescoVersion that is used.

Specified by:
getAlfrescoVersion in interface WebDrone
Returns:
AlfrescoVersion

getPageSouce

public String getPageSouce()
The HTML source code of the page viewed.

Returns:
String of current HTML source

getScreenShot

public final File getScreenShot()
Grabs a screen shot of what the WebDriver is currently viewing. This is only possible on WebDriver that are UI based browser.

Specified by:
getScreenShot in interface WebDrone
Returns:
File screen image of the page

toString

public String toString()
Overrides:
toString in class Object

finalize

protected void finalize()
                 throws Throwable
Clean up WebDrone.

Overrides:
finalize in class Object
Throws:
Throwable

refresh

public void refresh()
Description copied from interface: WebDrone
Acts as a refresh page action similar to F5 key.

Specified by:
refresh in interface WebDrone

getMaxPageRenderWaitTime

public long getMaxPageRenderWaitTime()

getDriver

public org.openqa.selenium.WebDriver getDriver()

isChromeBrowser

public boolean isChromeBrowser()
Checks to see if driver used is chrome.

Returns:
true if chrome browser

isHtmlUnit

public boolean isHtmlUnit()
Checks to see if driver used is HtmlUnit.

Returns:
true if chrome browser

getCookies

public Set<org.openqa.selenium.Cookie> getCookies()
Extract cookie information

Parameters:
drone - WebDrone
Returns:
String value of cookies


Copyright © 2013. All Rights Reserved.