com.thoughtworks.selenium
Class SeleneseTestBase

java.lang.Object
  extended by com.thoughtworks.selenium.SeleneseTestBase
Direct Known Subclasses:
SeleneseTestNgHelper

public class SeleneseTestBase
extends Object

Provides a 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 ([email protected]) Mar 13-06

Field Summary
protected  com.thoughtworks.selenium.Selenium selenium
          Use this object to run all of your selenium tests
protected  StringBuffer verificationErrors
           
 
Constructor Summary
SeleneseTestBase()
           
 
Method Summary
static void assertEquals(Object expected, Object actual)
          Like JUnit's Assert.assertEquals, but knows how to compare string arrays
static void assertEquals(String[] expected, String[] actual)
          Asserts that two string arrays have identical string contents
static void assertEquals(String expected, String actual)
          Like JUnit's Assert.assertEquals, but handles "regexp:" strings like HTML Selenese
static void assertEquals(String expected, String[] actual)
          Like JUnit's Assert.assertEquals, but joins the string array with commas, and handles "regexp:" strings like HTML Selenese
static void assertFalse(boolean condition)
           
static void assertFalse(String message, boolean condition)
           
static void assertNotEquals(boolean expected, boolean actual)
          Asserts that two booleans are not the same
static void assertNotEquals(Object expected, Object actual)
          Asserts that two objects are not the same (compares using .equals())
static void assertTrue(boolean condition)
           
static void assertTrue(String message, boolean condition)
           
 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
static void fail(String message)
           
protected  int getDefaultPort()
           
 String getText()
          Returns the body text of the current page
protected  boolean isCaptureScreenShotOnFailure()
           
static String join(String[] sa, char c)
           
 void pause(int millisecs)
          Sleeps for the specified number of milliseconds
protected  String runtimeBrowserString()
           
static boolean seleniumEquals(Object expected, Object actual)
          Compares two objects, but handles "regexp:" strings like HTML Selenese
static boolean seleniumEquals(String expectedPattern, String actual)
          Compares two strings, but handles "regexp:" strings like HTML Selenese
protected  void setCaptureScreenShotOnFailure(boolean captureScreetShotOnFailure)
           
 void setUp()
          Calls this.setUp(null)
 void setUp(String url)
          Calls this.setUp with the specified url and a default browser.
 void setUp(String url, String browserString)
          Creates a new DefaultSelenium object and starts it using the specified baseUrl and browser string.
 void setUp(String url, String browserString, int port)
          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 expected, boolean actual)
          Like assertEquals, but fails at the end of the test (during tearDown)
 void verifyEquals(Object expected, Object actual)
          Like assertEquals, but fails at the end of the test (during tearDown)
 void verifyEquals(String[] expected, String[] actual)
          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 expected, boolean actual)
          Like assertNotEquals, but fails at the end of the test (during tearDown)
 void verifyNotEquals(Object expected, Object actual)
          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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

selenium

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


verificationErrors

protected StringBuffer verificationErrors
Constructor Detail

SeleneseTestBase

public SeleneseTestBase()
Method Detail

setUp

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

Throws:
Exception
See Also:
setUp(String)

setUp

public void setUp(String url)
           throws 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:
Exception
See Also:
setUp(String, String)

runtimeBrowserString

protected String runtimeBrowserString()

setUp

public void setUp(String url,
                  String browserString)
           throws Exception
Creates a new DefaultSelenium object and starts it using the specified baseUrl and browser string. The port is selected as follows: if the server package's RemoteControlConfiguration class is on the classpath, that class' default port is used. Otherwise, if the "server.port" system property is specified, that is used - failing that, the default of 4444 is used.

Parameters:
url - the baseUrl for your tests
browserString - the browser to use, e.g. *firefox
Throws:
Exception
See Also:
setUp(String, String, int)

getDefaultPort

protected int getDefaultPort()

setUp

public void setUp(String url,
                  String browserString,
                  int port)
           throws Exception
Creates a new DefaultSelenium object and starts it using the specified baseUrl and browser string. The port is selected as follows: if the server package's RemoteControlConfiguration class is on the classpath, that class' default port is used. Otherwise, if the "server.port" system property is specified, that is used - failing that, the default of 4444 is used.

Parameters:
url - the baseUrl for your tests
browserString - the browser to use, e.g. *firefox
port - the port that you want to run your tests on
Throws:
Exception
See Also:
setUp(String, String, int)

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 String getText()
Returns the body text of the current page


verifyEquals

public void verifyEquals(Object expected,
                         Object actual)
Like assertEquals, but fails at the end of the test (during tearDown)


verifyEquals

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


assertEquals

public static void assertEquals(Object expected,
                                Object actual)
Like JUnit's Assert.assertEquals, but knows how to compare string arrays


assertEquals

public static void assertEquals(String expected,
                                String actual)
Like JUnit's Assert.assertEquals, but handles "regexp:" strings like HTML Selenese


assertEquals

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


seleniumEquals

public static boolean seleniumEquals(String expectedPattern,
                                     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(Object expected,
                                     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(String[] expected,
                                String[] actual)
Asserts that two string arrays have identical string contents


verifyEquals

public void verifyEquals(String[] expected,
                         String[] actual)
Asserts that two string arrays have identical string contents (fails at the end of the test, during tearDown)


join

public static String join(String[] sa,
                          char c)

verifyNotEquals

public void verifyNotEquals(Object expected,
                            Object actual)
Like assertNotEquals, but fails at the end of the test (during tearDown)


verifyNotEquals

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


assertNotEquals

public static void assertNotEquals(Object expected,
                                   Object actual)
Asserts that two objects are not the same (compares using .equals())


fail

public static void fail(String message)

assertTrue

public static void assertTrue(String message,
                              boolean condition)

assertTrue

public static void assertTrue(boolean condition)

assertFalse

public static void assertFalse(String message,
                               boolean condition)

assertFalse

public static void assertFalse(boolean condition)

assertNotEquals

public static void assertNotEquals(boolean expected,
                                   boolean actual)
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 Exception
checks for verification errors and stops the browser

Throws:
Exception

isCaptureScreenShotOnFailure

protected boolean isCaptureScreenShotOnFailure()

setCaptureScreenShotOnFailure

protected void setCaptureScreenShotOnFailure(boolean captureScreetShotOnFailure)


Copyright © 2012. All Rights Reserved.