com.unitedinternet.portal.selenium.utils.logging
Class HtmlResultFormatter

java.lang.Object
  extended by com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter
All Implemented Interfaces:
LoggingResultsFormatter

public class HtmlResultFormatter
extends java.lang.Object
implements LoggingResultsFormatter

Formats all logging events as HTML. Trying to bring the Selenium TestRunner result look-and-feel to Junit. Default formatter for logging. Be sure to pass an encoding-aware writer together with encoding name to the 2 parameters constuctor.

Author:
Robert Zimmermann $Id: HtmlResultFormatter.java 135 2009-01-15 20:37:36Z bobbyde $

Constructor Summary
HtmlResultFormatter(java.io.Writer myResultsWriter)
          Write results to the specified writer.
HtmlResultFormatter(java.io.Writer myResultsWriter, java.lang.String myResultFileEncoding)
          Write results with an arbitrary encoding.
 
Method Summary
 void booleanCommandLogEvent(LoggingBean loggingBean)
          Formats an selenium command which has an boolean result.
 void commandLogEvent(LoggingBean loggingBean)
          Formats an selenium command.
 void commentLogEvent(LoggingBean loggingBean)
          Format a comment.
 void footerLogEvent()
          Like formatHeader() but here after all commands have been formatted.
static java.lang.String generateEmptyColumns(int numColsToGenerate)
          Generate empty HTML columns.
 java.lang.String generateFilenameForAutomaticScreenshot(java.lang.String baseName)
          Generate an absolute filename for taking screenshots in case of an error (eg. timed out wait).
 java.lang.String getAutomaticScreenshotPath()
          Path to the (filesystem-)location where screenshot should be saved.
static java.text.SimpleDateFormat getFILENAME_DATETIME_FORMAT()
           
 java.lang.String getScreenShotBaseUri()
          Base URI to be linked to in the result.
 void headerLogEvent(TestMetricsBean metrics)
          Whatever the formatter wants to do before any command will be formatted.
 void methodLogEvent(LoggingBean loggingBean)
          Formats a Log Event for a complete Test Method.
static java.lang.String quoteHtml(java.lang.String unquoted)
           
 void setAutomaticScreenshotPath(java.lang.String automaticScreenshotPath)
          Automatic screenshots are taken if a Wait-timeout is detected.
static void setFILENAME_DATETIME_FORMAT(java.text.SimpleDateFormat newFormat)
           
 void setScreenShotBaseUri(java.lang.String screenShotBaseUri)
          Set a special uri for screenshots.
static java.lang.String timeStampForFileName()
          Generates a Date-Time String based on the current Time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HtmlResultFormatter

public HtmlResultFormatter(java.io.Writer myResultsWriter)
Write results to the specified writer. Note: encoding ISO-8859-1 is assumed It is recommended to use the 2-parameter constructor.

Parameters:
myResultsWriter - where results will be written in "ISO-8859-1" encoding

HtmlResultFormatter

public HtmlResultFormatter(java.io.Writer myResultsWriter,
                           java.lang.String myResultFileEncoding)
Write results with an arbitrary encoding. Be sure to create the writer with the correct encoding Note: resultFileEncoding is only used to set a corresponding meta-tag in the resulting HTML-file For Example: new BufferedWriter(new OutputStreamWriter(new FileOutputStream("myResultFile.html"), "UTF-8")

Parameters:
myResultsWriter - writer with resultFileEncoding set. See also Example above
myResultFileEncoding - any encoding supported by the running jvm
Method Detail

commentLogEvent

public void commentLogEvent(LoggingBean loggingBean)
Format a comment. Comments may be issued between commands by the loggingCommandProcessor, like a new method has been entered by the test.

Specified by:
commentLogEvent in interface LoggingResultsFormatter
Parameters:
loggingBean - loggingBean containing the comment to be logged.

headerLogEvent

public void headerLogEvent(TestMetricsBean metrics)
Whatever the formatter wants to do before any command will be formatted.

Specified by:
headerLogEvent in interface LoggingResultsFormatter
Parameters:
metrics - metrics gathered during test-run

footerLogEvent

public void footerLogEvent()
Like formatHeader() but here after all commands have been formatted.

Specified by:
footerLogEvent in interface LoggingResultsFormatter

commandLogEvent

public void commandLogEvent(LoggingBean loggingBean)
Formats an selenium command.

Specified by:
commandLogEvent in interface LoggingResultsFormatter
Parameters:
loggingBean - containing all informations for logging a selenium command

booleanCommandLogEvent

public void booleanCommandLogEvent(LoggingBean loggingBean)
Formats an selenium command which has an boolean result. Important: At this state no information whether an false or true result was or is expected by the test using this formatter. So an false result may be "green" for the test. Therefore all log-events here are logged as green. e.g. selenium commands like isElementPresent

Specified by:
booleanCommandLogEvent in interface LoggingResultsFormatter
Parameters:
loggingBean - containing all informations for logging a selenium command

getScreenShotBaseUri

public java.lang.String getScreenShotBaseUri()
Base URI to be linked to in the result. Screenshots may be linked with an http or similar prefix to be easier accessible in whatever reporting frontend is used later

Specified by:
getScreenShotBaseUri in interface LoggingResultsFormatter
Returns:
the current base-uri for screenshots

setScreenShotBaseUri

public void setScreenShotBaseUri(java.lang.String screenShotBaseUri)
Set a special uri for screenshots.

Specified by:
setScreenShotBaseUri in interface LoggingResultsFormatter
Parameters:
screenShotBaseUri - the new uri for screenshots

generateFilenameForAutomaticScreenshot

public java.lang.String generateFilenameForAutomaticScreenshot(java.lang.String baseName)
Generate an absolute filename for taking screenshots in case of an error (eg. timed out wait).

Specified by:
generateFilenameForAutomaticScreenshot in interface LoggingResultsFormatter
Parameters:
baseName - middle part of the name to be enhanced by whatever the implementation wants to
Returns:
absolute path for screenshot to be taken

getAutomaticScreenshotPath

public java.lang.String getAutomaticScreenshotPath()
Path to the (filesystem-)location where screenshot should be saved. Will be used by generateFilenameForAutomaticScreenshot()

Specified by:
getAutomaticScreenshotPath in interface LoggingResultsFormatter
Returns:
current location path

setAutomaticScreenshotPath

public void setAutomaticScreenshotPath(java.lang.String automaticScreenshotPath)
Automatic screenshots are taken if a Wait-timeout is detected. Default location is current working dir (".") If another (filesystem-)location is desired use this setter. Path to the (filesystem-)location where screenshot should be saved. Will be used by generateFilenameForAutomaticScreenshot()

Specified by:
setAutomaticScreenshotPath in interface LoggingResultsFormatter
Parameters:
automaticScreenshotPath - location (only path) to where screenshots should be saved

generateEmptyColumns

public static final java.lang.String generateEmptyColumns(int numColsToGenerate)
Generate empty HTML columns.

Parameters:
numColsToGenerate - num of columns to be generated
Returns:
generated, empty columns in one string

timeStampForFileName

public static final java.lang.String timeStampForFileName()
Generates a Date-Time String based on the current Time. To be used for and in filenames. TODO: maybe place this in LoggingUtils

Returns:
current date-time as string

methodLogEvent

public void methodLogEvent(LoggingBean loggingBean)
Formats a Log Event for a complete Test Method. The Logging Bean may contain several child beans holding the information of the single selenium commands.

Specified by:
methodLogEvent in interface LoggingResultsFormatter
Parameters:
loggingBean - containing all informations for logging a test method and its commands

quoteHtml

public static final java.lang.String quoteHtml(java.lang.String unquoted)

getFILENAME_DATETIME_FORMAT

public static java.text.SimpleDateFormat getFILENAME_DATETIME_FORMAT()

setFILENAME_DATETIME_FORMAT

public static void setFILENAME_DATETIME_FORMAT(java.text.SimpleDateFormat newFormat)


Copyright © 2009. All Rights Reserved.