com.thoughtworks.selenium
Class SeleneseTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by com.thoughtworks.selenium.SeleneseTestCase
All Implemented Interfaces:
junit.framework.Test

public class SeleneseTestCase
extends junit.framework.TestCase

Provides a JUnit TestCase base class that implements some handy functionality for Selenium testing (you are not required to extend this class).

This class adds a number of "verify" commands, which are like "assert" commands, but they don't stop the test when they fail. Instead, verification errors are all thrown at once during tearDown.

Author:
Nelson Sproul (nsproul@bea.com) Mar 13-06

Field Summary
protected  Selenium selenium
          Use this object to run all of your selenium tests
 
Constructor Summary
SeleneseTestCase()
           
SeleneseTestCase(java.lang.String name)
           
 
Method Summary
static void assertEquals(java.lang.Object s1, java.lang.Object s2)
          Like JUnit's Assert.assertEquals, but knows how to compare string arrays
static void assertEquals(java.lang.String[] s1, java.lang.String[] s2)
          Asserts that two string arrays have identical string contents
static void assertEquals(java.lang.String s1, java.lang.String s2)
          Like JUnit's Assert.assertEquals, but handles "regexp:" strings like HTML Selenese
static void assertEquals(java.lang.String s1, java.lang.String[] s2)
          Like JUnit's Assert.assertEquals, but joins the string array with commas, and handles "regexp:" strings like HTML Selenese
static void assertNotEquals(boolean b1, boolean b2)
          Asserts that two booleans are not the same
static void assertNotEquals(java.lang.Object obj1, java.lang.Object obj2)
          Asserts that two objects are not the same (compares using .equals())
 void checkForVerificationErrors()
          Asserts that there were no verification errors during the current test, failing immediately if any are found
 void clearVerificationErrors()
          Clears out the list of verification errors
 java.lang.String getText()
          Returns the body text of the current page
protected  boolean isCaptureScreetShotOnFailure()
           
 void pause(int millisecs)
          Sleeps for the specified number of milliseconds
 void runBare()
          Runs the bare test sequence, capturing a screenshot if a test fails
static boolean seleniumEquals(java.lang.Object expected, java.lang.Object actual)
          Compares two objects, but handles "regexp:" strings like HTML Selenese
static boolean seleniumEquals(java.lang.String expectedPattern, java.lang.String actual)
          Compares two strings, but handles "regexp:" strings like HTML Selenese
protected  void setCaptureScreetShotOnFailure(boolean captureScreetShotOnFailure)
           
 void setUp()
          Calls this.setUp(null)
 void setUp(java.lang.String url)
          Calls this.setUp with the specified url and a default browser.
 void setUp(java.lang.String url, java.lang.String browserString)
          Creates a new DefaultSelenium object and starts it using the specified baseUrl and browser string
 void tearDown()
          checks for verification errors and stops the browser
 void verifyEquals(boolean s1, boolean s2)
          Like assertEquals, but fails at the end of the test (during tearDown)
 void verifyEquals(java.lang.Object s1, java.lang.Object s2)
          Like assertEquals, but fails at the end of the test (during tearDown)
 void verifyEquals(java.lang.String[] s1, java.lang.String[] s2)
          Asserts that two string arrays have identical string contents (fails at the end of the test, during tearDown)
 void verifyFalse(boolean b)
          Like assertFalse, but fails at the end of the test (during tearDown)
 void verifyNotEquals(boolean s1, boolean s2)
          Like assertNotEquals, but fails at the end of the test (during tearDown)
 void verifyNotEquals(java.lang.Object s1, java.lang.Object s2)
          Like assertNotEquals, but fails at the end of the test (during tearDown)
 void verifyTrue(boolean b)
          Like assertTrue, but fails at the end of the test (during tearDown)
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

selenium

protected Selenium selenium
Use this object to run all of your selenium tests

Constructor Detail

SeleneseTestCase

public SeleneseTestCase()

SeleneseTestCase

public SeleneseTestCase(java.lang.String name)
Method Detail

setUp

public void setUp()
           throws java.lang.Exception
Calls this.setUp(null)

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception
See Also:
setUp(String)

runBare

public void runBare()
             throws java.lang.Throwable
Runs the bare test sequence, capturing a screenshot if a test fails

Overrides:
runBare in class junit.framework.TestCase
Throws:
java.lang.Throwable - if any exception is thrown

setUp

public void setUp(java.lang.String url)
           throws java.lang.Exception
Calls this.setUp with the specified url and a default browser. On Windows, the default browser is *iexplore; otherwise, the default browser is *firefox.

Parameters:
url - the baseUrl to use for your Selenium tests
Throws:
java.lang.Exception
See Also:
setUp(String, String)

setUp

public void setUp(java.lang.String url,
                  java.lang.String browserString)
           throws java.lang.Exception
Creates a new DefaultSelenium object and starts it using the specified baseUrl and browser string

Parameters:
url - the baseUrl for your tests
browserString - the browser to use, e.g. *firefox
Throws:
java.lang.Exception

verifyTrue

public void verifyTrue(boolean b)
Like assertTrue, but fails at the end of the test (during tearDown)


verifyFalse

public void verifyFalse(boolean b)
Like assertFalse, but fails at the end of the test (during tearDown)


getText

public java.lang.String getText()
Returns the body text of the current page


verifyEquals

public void verifyEquals(java.lang.Object s1,
                         java.lang.Object s2)
Like assertEquals, but fails at the end of the test (during tearDown)


verifyEquals

public void verifyEquals(boolean s1,
                         boolean s2)
Like assertEquals, but fails at the end of the test (during tearDown)


assertEquals

public static void assertEquals(java.lang.Object s1,
                                java.lang.Object s2)
Like JUnit's Assert.assertEquals, but knows how to compare string arrays


assertEquals

public static void assertEquals(java.lang.String s1,
                                java.lang.String s2)
Like JUnit's Assert.assertEquals, but handles "regexp:" strings like HTML Selenese


assertEquals

public static void assertEquals(java.lang.String s1,
                                java.lang.String[] s2)
Like JUnit's Assert.assertEquals, but joins the string array with commas, and handles "regexp:" strings like HTML Selenese


seleniumEquals

public static boolean seleniumEquals(java.lang.String expectedPattern,
                                     java.lang.String actual)
Compares two strings, but handles "regexp:" strings like HTML Selenese

Parameters:
expectedPattern -
actual -
Returns:
true if actual matches the expectedPattern, or false otherwise

seleniumEquals

public static boolean seleniumEquals(java.lang.Object expected,
                                     java.lang.Object actual)
Compares two objects, but handles "regexp:" strings like HTML Selenese

Returns:
true if actual matches the expectedPattern, or false otherwise
See Also:
seleniumEquals(String, String)

assertEquals

public static void assertEquals(java.lang.String[] s1,
                                java.lang.String[] s2)
Asserts that two string arrays have identical string contents


verifyEquals

public void verifyEquals(java.lang.String[] s1,
                         java.lang.String[] s2)
Asserts that two string arrays have identical string contents (fails at the end of the test, during tearDown)


verifyNotEquals

public void verifyNotEquals(java.lang.Object s1,
                            java.lang.Object s2)
Like assertNotEquals, but fails at the end of the test (during tearDown)


verifyNotEquals

public void verifyNotEquals(boolean s1,
                            boolean s2)
Like assertNotEquals, but fails at the end of the test (during tearDown)


assertNotEquals

public static void assertNotEquals(java.lang.Object obj1,
                                   java.lang.Object obj2)
Asserts that two objects are not the same (compares using .equals())


assertNotEquals

public static void assertNotEquals(boolean b1,
                                   boolean b2)
Asserts that two booleans are not the same


pause

public void pause(int millisecs)
Sleeps for the specified number of milliseconds


checkForVerificationErrors

public void checkForVerificationErrors()
Asserts that there were no verification errors during the current test, failing immediately if any are found


clearVerificationErrors

public void clearVerificationErrors()
Clears out the list of verification errors


tearDown

public void tearDown()
              throws java.lang.Exception
checks for verification errors and stops the browser

Overrides:
tearDown in class junit.framework.TestCase
Throws:
java.lang.Exception

isCaptureScreetShotOnFailure

protected boolean isCaptureScreetShotOnFailure()

setCaptureScreetShotOnFailure

protected void setCaptureScreetShotOnFailure(boolean captureScreetShotOnFailure)


Copyright © 2007. All Rights Reserved.