org.seleniuminspector
Class ElementInspector

java.lang.Object
  extended by org.seleniuminspector.ElementInspector
Direct Known Subclasses:
DocumentInspector, ElementByExpressionInspector, ElementByLocatorInspector, ElementByReferenceInspector, SubElementInspector, WindowInspector

public abstract class ElementInspector
extends java.lang.Object

The purpose of ElementInspector is to provide easy means for inspecting client-side DOM elements in Selenium functional tests. An instance of ElementInspector is bound to a specific DOM node that is specified during the element's creation.


Constructor Summary
ElementInspector()
           
 
Method Summary
 java.lang.String adaptColorString(java.lang.String color)
           
 java.lang.String adaptFontWeightString(java.lang.String fontWeight)
           
 java.lang.String asSeleniumLocator()
           
 void assertAttribute(java.lang.String attributeName, java.lang.String expectedAttributeValue)
           
 void assertAttributeStartsWith(java.lang.String attributeName, java.lang.String expectedStringStart)
           
 void assertContainsText(java.lang.String expectedContainedText)
           
 void assertElementExists()
           
 void assertElementExists(boolean exists)
           
 void assertExpressionEquals(java.lang.String expression, boolean expectedValue)
           
 void assertExpressionEquals(java.lang.String expression, int expectedValue)
           
 void assertExpressionEquals(java.lang.String expression, int expectedValue, int allowedError)
           
 void assertExpressionEquals(java.lang.String expression, java.lang.String expectedValue)
           
 void assertExpressionStartsWith(java.lang.String expression, java.lang.String expectedStringStart)
           
 void assertHeight(int height)
           
 void assertHeight(int height, int allowedError)
           
 void assertNodeName(java.lang.String expectedNodeName)
           
 void assertPosition(int x, int y)
           
 void assertPosition(java.awt.Point position)
           
 void assertSize(java.awt.Dimension dimension)
           
 void assertSize(int width, int height)
           
 void assertStyle(java.lang.String styleDeclaration)
          Checks whether all of the CSS properties specified in the "style" parameter are actually applied to the inspected element.
 void assertSubtext(int startPos, int endPos, java.lang.String expectedText)
           
 void assertText(java.lang.String expectedText)
           
 void assertVisible(boolean visible)
           
 void assertWidth(int width)
           
 void assertWidth(int width, int allowedError)
           
 java.lang.String attribute(java.lang.String attributeName)
           
 java.lang.String calculateStyleProperty(java.lang.String propertyName)
           
 java.util.List<ElementInspector> childNodes()
           
 java.util.List<ElementInspector> childNodesByName(java.lang.String nodeName)
           
 java.lang.String className()
           
 void click()
           
 void clickAndWait()
           
 void clickAndWait(LoadingMode loadingMode)
           
 void doubleClick()
           
 void dragAndDrop(int moveX, int moveY)
           
 boolean elementExists()
           
protected static java.lang.String escapeStringForJS(java.lang.String str)
           
protected static java.lang.String escapeStringForJSAndQuote(java.lang.String str)
           
 boolean evalBooleanExpression(java.lang.String elementExpression)
           
 java.lang.String evalExpression(java.lang.String elementExpression)
           
 int evalIntExpression(java.lang.String elementExpression)
           
protected  java.lang.String evalSeleniumInspectorExpression(java.lang.String expression)
           
protected  java.lang.String executeSeleniumCommand(java.lang.String command, java.lang.String locator, java.lang.String[] params)
           
 void fireEvent(java.lang.String eventName)
          Fires event with the specified name over this element.
protected  void fireEvent(java.lang.String eventName, boolean checkElementExistence)
           
 ElementInspector firstChild()
           
 void focus()
           
abstract  java.lang.String getElementReferenceExpression()
           
protected  java.util.List<ElementInspector> getElementsByScript(java.lang.String listRetrievalScript)
           
 java.util.List<ElementInspector> getElementsByTagName(java.lang.String tagName)
          Executes the JavaScript getElementsByTagName(tagName) function, and returns a list of corresponding element inspectors.
protected  com.thoughtworks.selenium.Selenium getSelenium()
           
 boolean hasChildNodes()
           
 java.lang.String id()
           
 boolean isCommentNode()
           
 boolean isDocumentNode()
           
 boolean isTextNode()
           
 boolean isVisible()
           
 void keyDown(char character)
           
 void keyDown(int keyCode)
           
 void keyPress(char character)
           
 void keyPress(int keyCode)
           
 void keyUp(char character)
           
 void keyUp(int keyCode)
           
 ElementInspector lastChild()
           
 void mouseDown()
           
 void mouseMove()
           
 void mouseOut()
           
 void mouseOver()
           
 void mouseUp()
           
 ElementInspector nextSibling()
           
 java.lang.String nodeName()
           
 java.lang.String nodeValue()
           
 ElementInspector parentNode()
           
 java.awt.Point position()
           
 ElementInspector previousSibling()
           
 java.awt.Rectangle rectangle()
           
 void selectByLabel(java.lang.String label)
           
 java.lang.String[] selectOptions()
           
 void setCursorPosition(int position)
           
 java.awt.Dimension size()
           
protected  void sleep(long millis)
           
 ElementInspector subElement(java.lang.String subElementPath)
          Returns an ElementInspector object for a sub-element defined by the path relative to the element represented by this ElementInspector.
 java.lang.String text()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElementInspector

public ElementInspector()
Method Detail

getSelenium

protected com.thoughtworks.selenium.Selenium getSelenium()

asSeleniumLocator

public java.lang.String asSeleniumLocator()
Returns:
a selenium inspector string that can be used in the ordinary methods of Selenium object.

getElementReferenceExpression

public abstract java.lang.String getElementReferenceExpression()
Returns:
expression that evaluates to the inspected element. This expression is evaluated by the Selenium.getEval method and it is executed in context of the "selenium" object, not the tested window. Use "window" to refer to the tested window.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

evalSeleniumInspectorExpression

protected java.lang.String evalSeleniumInspectorExpression(java.lang.String expression)

elementExists

public boolean elementExists()
Returns:
true if the element referred to by this element inspector really exists in browser's DOM

childNodes

public java.util.List<ElementInspector> childNodes()

childNodesByName

public java.util.List<ElementInspector> childNodesByName(java.lang.String nodeName)

getElementsByTagName

public java.util.List<ElementInspector> getElementsByTagName(java.lang.String tagName)
Executes the JavaScript getElementsByTagName(tagName) function, and returns a list of corresponding element inspectors.


getElementsByScript

protected java.util.List<ElementInspector> getElementsByScript(java.lang.String listRetrievalScript)

subElement

public ElementInspector subElement(java.lang.String subElementPath)
Returns an ElementInspector object for a sub-element defined by the path relative to the element represented by this ElementInspector. Note that element path is NOT specified as XPath, but rather as a path in the format "tagName/subTagName/subSubTagName/etc"; tag name indexes are also allowed, e.g. "tbody/tr[3]/td[0]/input". This path is relative to the element that this ElementInspector is associated with.


hasChildNodes

public boolean hasChildNodes()

firstChild

public ElementInspector firstChild()

lastChild

public ElementInspector lastChild()

nextSibling

public ElementInspector nextSibling()

previousSibling

public ElementInspector previousSibling()

parentNode

public ElementInspector parentNode()

evalExpression

public java.lang.String evalExpression(java.lang.String elementExpression)
Parameters:
elementExpression - The property of the element, or function call over the element, or a chain of properties/function calls that should be evaluated, e.g. "checked", "style.width", or "_getSelectedItems().length"
Returns:
the evaluated value
See Also:
evalBooleanExpression(java.lang.String), evalIntExpression(java.lang.String)

evalBooleanExpression

public boolean evalBooleanExpression(java.lang.String elementExpression)
Parameters:
elementExpression - The property of the element, or function call over the element, or a chain of properties/function calls that should be evaluated, e.g. "checked", "_getContent().isVisible()"
Returns:
the result of expression evaluation converted to boolean value according to JavaScript rules
See Also:
evalExpression(java.lang.String)

evalIntExpression

public int evalIntExpression(java.lang.String elementExpression)
Parameters:
elementExpression - The property of the element, or function call over the element, or a chain of properties/function calls that should be evaluated, e.g. "checked", "_getContent().isVisible()"
Returns:
the result of expression evaluation converted to int
See Also:
evalExpression(java.lang.String)

executeSeleniumCommand

protected java.lang.String executeSeleniumCommand(java.lang.String command,
                                                  java.lang.String locator,
                                                  java.lang.String[] params)

nodeName

public java.lang.String nodeName()
Returns:
evaluates "nodeName" property of the inspected element. It returns the lower-case tag name for tag nodes, "#text" for text node, "#comment" for comment nodes, and "#document" for document nodes.

isTextNode

public boolean isTextNode()

isCommentNode

public boolean isCommentNode()

isDocumentNode

public boolean isDocumentNode()

nodeValue

public java.lang.String nodeValue()
Returns:
evaluates "nodeValue" property of the inspected element

id

public java.lang.String id()
Returns:
element id

text

public java.lang.String text()

attribute

public java.lang.String attribute(java.lang.String attributeName)

className

public java.lang.String className()

calculateStyleProperty

public java.lang.String calculateStyleProperty(java.lang.String propertyName)

isVisible

public boolean isVisible()

size

public java.awt.Dimension size()

position

public java.awt.Point position()

rectangle

public java.awt.Rectangle rectangle()

fireEvent

public void fireEvent(java.lang.String eventName)
Fires event with the specified name over this element.

Parameters:
eventName - name of the event that should be fired. Event name should start with "on" prefix, e.g. "onclick", "onkeypress", etc.

fireEvent

protected void fireEvent(java.lang.String eventName,
                         boolean checkElementExistence)

click

public void click()

clickAndWait

public void clickAndWait()

clickAndWait

public void clickAndWait(LoadingMode loadingMode)

doubleClick

public void doubleClick()

mouseDown

public void mouseDown()

mouseUp

public void mouseUp()

mouseOver

public void mouseOver()

mouseMove

public void mouseMove()

mouseOut

public void mouseOut()

dragAndDrop

public void dragAndDrop(int moveX,
                        int moveY)

focus

public void focus()

keyDown

public void keyDown(char character)

keyDown

public void keyDown(int keyCode)

keyUp

public void keyUp(char character)

keyUp

public void keyUp(int keyCode)

keyPress

public void keyPress(char character)

keyPress

public void keyPress(int keyCode)

setCursorPosition

public void setCursorPosition(int position)

selectOptions

public java.lang.String[] selectOptions()

selectByLabel

public void selectByLabel(java.lang.String label)

assertElementExists

public void assertElementExists()

assertElementExists

public void assertElementExists(boolean exists)

assertExpressionEquals

public void assertExpressionEquals(java.lang.String expression,
                                   java.lang.String expectedValue)

assertExpressionEquals

public void assertExpressionEquals(java.lang.String expression,
                                   int expectedValue)

assertExpressionEquals

public void assertExpressionEquals(java.lang.String expression,
                                   int expectedValue,
                                   int allowedError)

assertExpressionEquals

public void assertExpressionEquals(java.lang.String expression,
                                   boolean expectedValue)

assertExpressionStartsWith

public void assertExpressionStartsWith(java.lang.String expression,
                                       java.lang.String expectedStringStart)

assertAttribute

public void assertAttribute(java.lang.String attributeName,
                            java.lang.String expectedAttributeValue)

assertAttributeStartsWith

public void assertAttributeStartsWith(java.lang.String attributeName,
                                      java.lang.String expectedStringStart)

assertNodeName

public void assertNodeName(java.lang.String expectedNodeName)

assertText

public void assertText(java.lang.String expectedText)

assertSubtext

public void assertSubtext(int startPos,
                          int endPos,
                          java.lang.String expectedText)

assertContainsText

public void assertContainsText(java.lang.String expectedContainedText)

assertStyle

public void assertStyle(java.lang.String styleDeclaration)
Checks whether all of the CSS properties specified in the "style" parameter are actually applied to the inspected element. Note that the "style" parameter should not necessarily include all of the style declarations applied to the element -- it just should include declarations that need to be checked. If at least one of the style property declarations passed in the "style" parameter doesn't match the element's current style, this method will fail with an appropriate message.

This method doesn't just check the value of the element's "style" property, but check's element's computed style including the entire CSS cascade applied to the element.

Note also that not all of the complex css properties can be checked directly with this method. As a solution you might need to split the complex declaration into several subproperty declarations, e.g. you might need to specify "font-size: 12pt; font-family: Arial; font-weight: bold" instead of "font: 12px Arial bold".

Parameters:
styleDeclaration - CSS attribute declarations

assertVisible

public void assertVisible(boolean visible)

assertWidth

public void assertWidth(int width)

assertWidth

public void assertWidth(int width,
                        int allowedError)

assertHeight

public void assertHeight(int height)

assertHeight

public void assertHeight(int height,
                         int allowedError)

assertPosition

public void assertPosition(java.awt.Point position)

assertPosition

public void assertPosition(int x,
                           int y)

assertSize

public void assertSize(java.awt.Dimension dimension)

assertSize

public void assertSize(int width,
                       int height)

adaptColorString

public java.lang.String adaptColorString(java.lang.String color)

adaptFontWeightString

public java.lang.String adaptFontWeightString(java.lang.String fontWeight)

escapeStringForJSAndQuote

protected static java.lang.String escapeStringForJSAndQuote(java.lang.String str)

escapeStringForJS

protected static java.lang.String escapeStringForJS(java.lang.String str)

sleep

protected void sleep(long millis)


Copyright © 1998-2009 TeamDev Ltd. All Rights Reserved.