io.ddavison.selenium
Class AutomationTest

java.lang.Object
  extended by io.ddavison.selenium.AutomationTest

public class AutomationTest
extends Object

the base test that includes all Selenium 2 functionality that you will need to get you rolling.

Author:
ddavison

Field Summary
 org.openqa.selenium.interactions.Actions actions
           
 org.openqa.selenium.WebDriver driver
           
static org.apache.logging.log4j.Logger log
           
 
Constructor Summary
AutomationTest()
           
 
Method Summary
 AutomationTest check(org.openqa.selenium.By by)
          Check a checkbox, or radio button
 AutomationTest check(String css)
          Check a checkbox, or radio button
 AutomationTest click(org.openqa.selenium.By by)
          Click an element.
 AutomationTest click(String css)
          Click an element.
 AutomationTest closeWindow()
          Closes the current active window.
 AutomationTest closeWindow(String regex)
          Close an open window.
static String findFile(String filename)
           
 String get(String key)
          Get a variable from the data warehouse.

If the key is not set, then use get(String, String)
 String get(String key, String defaultValue)
          Get a variable from the data warehouse.
 String getAttribute(org.openqa.selenium.By by, String attribute)
          Get an attribute of an element
 String getAttribute(String css, String attribute)
          Get an attribute of an element
 String getText(org.openqa.selenium.By by)
          Get the text of an element.
 String getText(String css)
          Get the text of an element.
 AutomationTest goBack()
          Navigates the browser back one page.
 AutomationTest hoverOver(org.openqa.selenium.By by)
          Hover over an element.
 AutomationTest hoverOver(String css)
          Hover over an element.
 boolean isChecked(org.openqa.selenium.By by)
          Checks if the element is checked or not.
 boolean isChecked(String css)
          Checks if the element is checked or not.
 boolean isPresent(org.openqa.selenium.By by)
          Checks if the element is present or not.
 boolean isPresent(String css)
          Checks if the element is present or not.
 AutomationTest log(Object object)
          Log something as information
 AutomationTest logDebug(Object object)
          Log something as debug
 AutomationTest logError(Object object)
          Log something as an error
 AutomationTest logFatal(Object object)
          Log something as fatal
 AutomationTest logInfo(Object object)
          Log something as information
 AutomationTest logWarn(Object object)
          Log something as a warning
 AutomationTest navigateTo(String url)
          Navigates to an absolute or relative Url.
 AutomationTest selectOptionByText(org.openqa.selenium.By by, String text)
          Selects an option from a dropdown (<select> tag) based on the text displayed.
 AutomationTest selectOptionByText(String css, String text)
          Selects an option from a dropdown (<select> tag) based on the text displayed.
 AutomationTest selectOptionByValue(org.openqa.selenium.By by, String value)
          Selects an option from a dropdown (<select> tag) based on the value.
 AutomationTest selectOptionByValue(String css, String value)
          Selects an option from a dropdown (<select> tag) based on the value.
 AutomationTest setText(org.openqa.selenium.By by, String text)
          Clears the text from a text field, and sets it.
 AutomationTest setText(String css, String text)
          Clears the text from a text field, and sets it.
 AutomationTest store(String key, String value)
          Put a variable in the data warehouse.
 AutomationTest switchToDefaultContent()
          Switch back to the default content (the first window / frame that you were on before switching)
 AutomationTest switchToFrame(String idOrName)
          Switches to a frame or iframe.
 AutomationTest switchToWindow(String regex)
          Switch's to a window that is already in existance.
 void teardown()
           
 AutomationTest uncheck(org.openqa.selenium.By by)
          Uncheck a checkbox, or radio button.
 AutomationTest uncheck(String css)
          Uncheck a checkbox, or radio button
 AutomationTest validateAttribute(org.openqa.selenium.By by, String attr, String regex)
          Validates an attribute of an element.

Example:
<input type="text" id="test" />

.validateAttribute(css("input#test"), "type", "text") // validates that the "type" attribute equals "test"
 AutomationTest validateAttribute(String css, String attr, String regex)
          Validates an attribute of an element.

Example:
<input type="text" id="test" />

.validateAttribute("input#test", "type", "text") // validates that the "type" attribute equals "test"
 AutomationTest validateChecked(org.openqa.selenium.By by)
          Validate that a checkbox or a radio button is checked.
 AutomationTest validateChecked(String css)
          Validate that a checkbox or a radio button is checked.
 AutomationTest validateFalse(boolean condition)
          Validates that a specific condition is false
 AutomationTest validateNotPresent(org.openqa.selenium.By by)
          Validates that an element is not present.
 AutomationTest validateNotPresent(String css)
          Validates that an element is not present.
 AutomationTest validatePresent(org.openqa.selenium.By by)
          Validates that an element is present.
 AutomationTest validatePresent(String css)
          Validates that an element is present.
 AutomationTest validateText(org.openqa.selenium.By by, String text)
          Validate that the text of an element is correct.
 AutomationTest validateText(String css, String text)
          Validate that the text of an element is correct.
 AutomationTest validateTextNot(org.openqa.selenium.By by, String text)
          Validate that the text of an element is not matching text.
 AutomationTest validateTextNot(String css, String text)
          Validate that the text of an element is not matching text.
 AutomationTest validateTextNotPresent(String text)
          Validate that some text is nowhere on the page.
 AutomationTest validateTextPresent(String text)
          Validate that text is present somewhere on the page.
 AutomationTest validateTrue(boolean condition)
          Validates that a specific condition is true
 AutomationTest validateUnchecked(org.openqa.selenium.By by)
          Validate that a checkbox or a radio button is unchecked.
 AutomationTest validateUnchecked(String css)
          Validate that a checkbox or a radio button is unchecked.
 AutomationTest validateUrl(String regex)
          Validate the Url
 org.openqa.selenium.WebElement waitForElement(org.openqa.selenium.By by)
          Private method that acts as an arbiter of implicit timeouts of sorts..
 AutomationTest waitForWindow(String regex)
          Waits for a window to appear, then switches to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.logging.log4j.Logger log

driver

public org.openqa.selenium.WebDriver driver

actions

public org.openqa.selenium.interactions.Actions actions
Constructor Detail

AutomationTest

public AutomationTest()
Method Detail

findFile

public static String findFile(String filename)

teardown

public void teardown()

waitForElement

public org.openqa.selenium.WebElement waitForElement(org.openqa.selenium.By by)
Private method that acts as an arbiter of implicit timeouts of sorts.. sort of like a Wait For Ajax method.


click

public AutomationTest click(String css)
Click an element.

Parameters:
css - The css element to click.
Returns:
AutomationTest (for fluency)

click

public AutomationTest click(org.openqa.selenium.By by)
Click an element.

Parameters:
by - The element to click.
Returns:
AutomationTest (for fluency)

setText

public AutomationTest setText(String css,
                              String text)
Clears the text from a text field, and sets it.

Parameters:
css - The css element to set the text of.
text - The text that the element will have.
Returns:
AutomationTest (for fluency)

setText

public AutomationTest setText(org.openqa.selenium.By by,
                              String text)
Clears the text from a text field, and sets it.

Parameters:
by - The element to set the text of.
text - The text that the element will have.
Returns:
AutomationTest (for fluency)

hoverOver

public AutomationTest hoverOver(String css)
Hover over an element.

Parameters:
css - The css element to hover over.
Returns:
AutomationTest (for fluency)

hoverOver

public AutomationTest hoverOver(org.openqa.selenium.By by)
Hover over an element.

Parameters:
by - The element to hover over.
Returns:
AutomationTest (for fluency)

isChecked

public boolean isChecked(String css)
Checks if the element is checked or not.

Parameters:
css - The css selector for the checkbox
Returns:
this method is not meant to be used fluently.

Returns true if the element is checked. and false if it's not.

isChecked

public boolean isChecked(org.openqa.selenium.By by)
Checks if the element is checked or not.

Parameters:
by - The element
Returns:
this method is not meant to be used fluently.

Returns true if the element is checked. and false if it's not.

isPresent

public boolean isPresent(String css)
Checks if the element is present or not.

Parameters:
css - The css selector for the element
Returns:
this method is not meant to be used fluently.
true if the element is present. and false if it's not.

isPresent

public boolean isPresent(org.openqa.selenium.By by)
Checks if the element is present or not.

Parameters:
by - The element
Returns:
this method is not meant to be used fluently.
true if the element is present. and false if it's not.

getText

public String getText(String css)
Get the text of an element.
This is a consolidated method that works on input's, as select boxes, and fetches the value rather than the innerHTMl.

Parameters:
css - The css selector of the element
Returns:
AutomationTest (for fluency)

getText

public String getText(org.openqa.selenium.By by)
Get the text of an element.
This is a consolidated method that works on input's, as select boxes, and fetches the value rather than the innerHTMl.

Parameters:
by - The element to get the text from
Returns:
AutomationTest (for fluency)

getAttribute

public String getAttribute(String css,
                           String attribute)
Get an attribute of an element

Parameters:
css - The css element to get from
attribute - The attribute to get
Returns:
AutomationTest (for fluency)

getAttribute

public String getAttribute(org.openqa.selenium.By by,
                           String attribute)
Get an attribute of an element

Parameters:
by - The element to get from
attribute - The attribute to get
Returns:
AutomationTest (for fluency)

check

public AutomationTest check(String css)
Check a checkbox, or radio button

Parameters:
css - The css element to check
Returns:
AutomationTest (for fluency)

check

public AutomationTest check(org.openqa.selenium.By by)
Check a checkbox, or radio button

Parameters:
by - The element to check
Returns:
AutomationTest (for fluency)

uncheck

public AutomationTest uncheck(String css)
Uncheck a checkbox, or radio button

Parameters:
css - The css element to uncheck
Returns:
AutomationTest (for fluency)

uncheck

public AutomationTest uncheck(org.openqa.selenium.By by)
Uncheck a checkbox, or radio button.

Parameters:
by - The element to uncheck.
Returns:
AutomationTest (for fluency)

selectOptionByText

public AutomationTest selectOptionByText(String css,
                                         String text)
Selects an option from a dropdown (<select> tag) based on the text displayed.

Parameters:
css - The css selector for the element
text - The text that is displaying.
Returns:
AutomationTest (for fluency)
See Also:
selectOptionByValue(By, String)

selectOptionByText

public AutomationTest selectOptionByText(org.openqa.selenium.By by,
                                         String text)
Selects an option from a dropdown (<select> tag) based on the text displayed.

Parameters:
by - The element
text - The text that is displaying.
Returns:
AutomationTest (for fluency)
See Also:
selectOptionByValue(By, String)

selectOptionByValue

public AutomationTest selectOptionByValue(String css,
                                          String value)
Selects an option from a dropdown (<select> tag) based on the value.

Parameters:
css - The css selector for the element
value - The value attribute of the option.
Returns:
AutomationTest (for fluency)
See Also:
selectOptionByText(By, String)

selectOptionByValue

public AutomationTest selectOptionByValue(org.openqa.selenium.By by,
                                          String value)
Selects an option from a dropdown (<select> tag) based on the value.

Parameters:
by - The element
value - The value attribute of the option.
Returns:
AutomationTest (for fluency)
See Also:
selectOptionByText(By, String)

waitForWindow

public AutomationTest waitForWindow(String regex)
Waits for a window to appear, then switches to it.

Parameters:
regex - Regex enabled. Url of the window, or title.
Returns:
AutomationTest (for fluency)

switchToWindow

public AutomationTest switchToWindow(String regex)
Switch's to a window that is already in existance.

Parameters:
regex - Regex enabled. Url of the window, or title.
Returns:
AutomationTest (for fluency)

closeWindow

public AutomationTest closeWindow(String regex)
Close an open window.
If you have opened only 1 external window, then when you call this method, the context will switch back to the window you were using before.

If you had more than 2 windows displaying, then you will need to call switchToWindow(String) to switch back context.

Parameters:
regex - The title of the window to close (regex enabled). You may specify null to close the active window. If you specify null then the context will switch back to the initial window.
Returns:
AutomationTest (for fluency)

closeWindow

public AutomationTest closeWindow()
Closes the current active window. Calling this method will return the context back to the initial window.

Returns:
AutomationTest (for fluency)

switchToFrame

public AutomationTest switchToFrame(String idOrName)
Switches to a frame or iframe.

Parameters:
idOrName - The id or name of the frame.
Returns:
AutomationTest (for fluency)

switchToDefaultContent

public AutomationTest switchToDefaultContent()
Switch back to the default content (the first window / frame that you were on before switching)

Returns:
AutomationTest (for fluency)

validatePresent

public AutomationTest validatePresent(String css)
Validates that an element is present.

Parameters:
css - The css selector of the element
Returns:
AutomationTest (for fluency)

validatePresent

public AutomationTest validatePresent(org.openqa.selenium.By by)
Validates that an element is present.

Parameters:
by - The css selector of the element
Returns:
AutomationTest (for fluency)

validateNotPresent

public AutomationTest validateNotPresent(String css)
Validates that an element is not present.

Parameters:
css - The css selector for the element
Returns:
AutomationTest (for fluency)

validateNotPresent

public AutomationTest validateNotPresent(org.openqa.selenium.By by)
Validates that an element is not present.

Parameters:
by - The css selector of the element
Returns:
AutomationTest (for fluency)

validateText

public AutomationTest validateText(String css,
                                   String text)
Validate that the text of an element is correct.

Parameters:
css - The css element to validate the text of.
text - The text to validate.
Returns:
AutomationTest (for fluency)

validateText

public AutomationTest validateText(org.openqa.selenium.By by,
                                   String text)
Validate that the text of an element is correct.

Parameters:
by - The element to validate the text of.
text - The text to validate.
Returns:
AutomationTest (for fluency)

validateTextNot

public AutomationTest validateTextNot(String css,
                                      String text)
Validate that the text of an element is not matching text.

Parameters:
css - The css element to validate the text of.
text - The text to validate.
Returns:
AutomationTest (for fluency)

validateTextNot

public AutomationTest validateTextNot(org.openqa.selenium.By by,
                                      String text)
Validate that the text of an element is not matching text.

Parameters:
by - The element to validate the text of.
text - The text to validate.
Returns:
AutomationTest (for fluency)

validateTextPresent

public AutomationTest validateTextPresent(String text)
Validate that text is present somewhere on the page.

Parameters:
text - The text to ensure is on the page.
Returns:
AutomationTest (for fluency)

validateTextNotPresent

public AutomationTest validateTextNotPresent(String text)
Validate that some text is nowhere on the page.

Parameters:
text - The text to ensure is not on the page.
Returns:
AutomationTest (for fluency)

validateChecked

public AutomationTest validateChecked(String css)
Validate that a checkbox or a radio button is checked.

Parameters:
css - The css selector for the element
Returns:
AutomationTest (for fluency)

validateChecked

public AutomationTest validateChecked(org.openqa.selenium.By by)
Validate that a checkbox or a radio button is checked.

Parameters:
by - The css selector of the element
Returns:
AutomationTest (for fluency)

validateUnchecked

public AutomationTest validateUnchecked(String css)
Validate that a checkbox or a radio button is unchecked.

Parameters:
css - The css selector for the element
Returns:
AutomationTest (for fluency)

validateUnchecked

public AutomationTest validateUnchecked(org.openqa.selenium.By by)
Validate that a checkbox or a radio button is unchecked.

Parameters:
by - The element
Returns:
AutomationTest (for fluency)

validateAttribute

public AutomationTest validateAttribute(String css,
                                        String attr,
                                        String regex)
Validates an attribute of an element.

Example:
<input type="text" id="test" />

.validateAttribute("input#test", "type", "text") // validates that the "type" attribute equals "test"

Parameters:
css - The css selector of the element
attr - The attribute you'd like to validate
regex - What the attribute should be. (this method supports regex)
Returns:
AutomationTest (for fluency)

validateAttribute

public AutomationTest validateAttribute(org.openqa.selenium.By by,
                                        String attr,
                                        String regex)
Validates an attribute of an element.

Example:
<input type="text" id="test" />

.validateAttribute(css("input#test"), "type", "text") // validates that the "type" attribute equals "test"

Parameters:
by - The element
attr - The attribute you'd like to validate
regex - What the attribute should be. (this method supports regex)
Returns:
AutomationTest (for fluency)

validateUrl

public AutomationTest validateUrl(String regex)
Validate the Url

Parameters:
regex - Regular expression to match
Returns:
AutomationTest (for fluency)

validateTrue

public AutomationTest validateTrue(boolean condition)
Validates that a specific condition is true

Parameters:
condition - The condition that is expected to be true
Returns:
AutomationTest (for fluency)

validateFalse

public AutomationTest validateFalse(boolean condition)
Validates that a specific condition is false

Parameters:
condition - The condition that is expected to be false
Returns:
AutomationTest (for fluency)

goBack

public AutomationTest goBack()
Navigates the browser back one page. Same as driver.navigate().back()

Returns:
AutomationTest (for fluency)

navigateTo

public AutomationTest navigateTo(String url)
Navigates to an absolute or relative Url.

Parameters:
url - Use cases are:
navigateTo("/login") // navigate to a relative url. slash meaning start fresh from the base url.

navigateTo("path") // navigate to a relative url. will simply append "path" to the current url.

navigateTo("http://google.com") // navigates to an absolute url.
Returns:
AutomationTest (for fluency)

store

public AutomationTest store(String key,
                            String value)
Put a variable in the data warehouse.

Parameters:
key - The key to put.
value - The value to put.
Returns:
AutomationTest (for fluency)

get

public String get(String key)
Get a variable from the data warehouse.

If the key is not set, then use get(String, String)

Parameters:
key - The key to fetch.
Returns:
AutomationTest (for fluency)

get

public String get(String key,
                  String defaultValue)
Get a variable from the data warehouse.

Parameters:
key - The key to fetch.
defaultValue - The value to return if the variable is not set.
Returns:
AutomationTest (for fluency)

log

public AutomationTest log(Object object)
Log something as information

Parameters:
object - What to log.
Returns:
AutomationTest (for fluency)

logInfo

public AutomationTest logInfo(Object object)
Log something as information

Parameters:
object - What to log
Returns:
AutomationTest (for fluency)

logWarn

public AutomationTest logWarn(Object object)
Log something as a warning

Parameters:
object - What to log
Returns:
AutomationTest (for fluency)

logError

public AutomationTest logError(Object object)
Log something as an error

Parameters:
object - What to log
Returns:
AutomationTest (for fluency)

logDebug

public AutomationTest logDebug(Object object)
Log something as debug

Parameters:
object - What to log
Returns:
AutomationTest (for fluency)

logFatal

public AutomationTest logFatal(Object object)
Log something as fatal

Parameters:
object - What to log
Returns:
AutomationTest (for fluency)


Copyright © 2014. All rights reserved.