version 1.0

com.actimind.actiwate.testing.html.util
Class HTMLUtil

java.lang.Object
  extended bycom.actimind.actiwate.testing.html.util.HTMLUtil

public class HTMLUtil
extends java.lang.Object

Utility methods for HTML elements


Constructor Summary
HTMLUtil()
           
 
Method Summary
static boolean containsText(java.lang.String htmlText, java.lang.String expectedText)
          Returns true if html text contains specified text.
static java.lang.String describeElement(org.w3c.dom.html.HTMLElement element)
          Makes human readable description of HTML element.
static java.lang.String describeNode(org.w3c.dom.Node node)
          Makes human readable description of document node.
static void describeNode(java.lang.StringBuffer buffer, org.w3c.dom.Node node)
           
static java.lang.String getTextWithin(org.w3c.dom.html.HTMLElement element, boolean normalize)
          Returns text within element: concatenates all text nodes within element and returns them as single string object.
static java.lang.String normalize(java.lang.String stringToNormalize)
          Normalizes specified string.
static boolean normalizedEquals(org.w3c.dom.html.HTMLElement element, java.lang.String expectedTextInElement)
          Returns true if element's text equals to specified text after normalization.
static boolean normalizedEquals(java.lang.String actualText, java.lang.String expectedText)
          Returns true if actual text equals to expected text after normalization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLUtil

public HTMLUtil()
Method Detail

getTextWithin

public static java.lang.String getTextWithin(org.w3c.dom.html.HTMLElement element,
                                             boolean normalize)
Returns text within element: concatenates all text nodes within element and returns them as single string object.

Parameters:
element - element to retrieve text from
normalize - if true then text will be normalized before being returned
Returns:
text within element or null if element is null

normalize

public static java.lang.String normalize(java.lang.String stringToNormalize)
Normalizes specified string. Converts characters: '\t', '\r', '\n', '0xa0' (nbsp) to single space, collapses sequence of spaces to one space and trims resulted string.

Parameters:
stringToNormalize - string to normalize
Returns:
normalized string

containsText

public static boolean containsText(java.lang.String htmlText,
                                   java.lang.String expectedText)
Returns true if html text contains specified text. HTML text will be normalized before actual comparing.

Parameters:
htmlText - an html text: text retrived from html element
expectedText - text expected to be contained in html text
Returns:
true if normalized htmlText contains expectedText

normalizedEquals

public static boolean normalizedEquals(org.w3c.dom.html.HTMLElement element,
                                       java.lang.String expectedTextInElement)
Returns true if element's text equals to specified text after normalization.

Parameters:
element - element to search test in
expectedTextInElement - text expected to be in element
Returns:
true if element's normalized text equals to expected text and false otherwise

normalizedEquals

public static boolean normalizedEquals(java.lang.String actualText,
                                       java.lang.String expectedText)
Returns true if actual text equals to expected text after normalization.

Parameters:
actualText - actual text
expectedText - expected text
Returns:
true if actual text equals to expected text after normalization and false otherwise

describeElement

public static java.lang.String describeElement(org.w3c.dom.html.HTMLElement element)
Makes human readable description of HTML element. So that someone could find it in HTML source.

Parameters:
element - HTML element
Returns:
HTML element description

describeNode

public static java.lang.String describeNode(org.w3c.dom.Node node)
Makes human readable description of document node. So that someone could find it in HTML source.

Parameters:
node - Document node
Returns:
Node description

describeNode

public static void describeNode(java.lang.StringBuffer buffer,
                                org.w3c.dom.Node node)


Copyright © 2007 Actimind, Inc. All Rights Reserved.