Class LoggingSeleniumWebDriver
java.lang.Object
com.zingtongroup.loggingseleniumwebdriver.LoggingSeleniumWebDriver
- All Implemented Interfaces:
LoggingSeleniumComponent,org.openqa.selenium.SearchContext,org.openqa.selenium.WebDriver
public class LoggingSeleniumWebDriver extends java.lang.Object implements org.openqa.selenium.WebDriver, LoggingSeleniumComponent
Wrapping class for any
WebDriver instance to make it output description of what actions are performed.
Create custom Logger class for custom logging.- Author:
- Jörgen Damberg
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLoggingSeleniumWebDriver.BuilderLoggingSeleniumWebDriverconstructor from builder pattern.Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window -
Field Summary
Fields Modifier and Type Field Description LoggerListloggerListList ofLoggerinstances to log output to.org.openqa.selenium.WebDriveroriginalWebDriverRawWebDriverinstance for non-logged interaction. -
Constructor Summary
Constructors Constructor Description LoggingSeleniumWebDriver()Simple constructor mainly for testing purposes.LoggingSeleniumWebDriver(org.openqa.selenium.WebDriver webDriver) -
Method Summary
Modifier and Type Method Description LoggingSeleniumWebDriveraddLogger(Logger logger)Add anotherLoggerinstance to the list of loggers to output to.LoggingSeleniumWebDriverattachWebDriverInstance(org.openqa.selenium.WebDriver driver)Re-assigns activeWebDriverinstance to keep consistent logging over multiple browser instances.voidclose()WebDrivernative method, but with logging.LoggingSeleniumWebDriverdetachWebDriverInstance()Used before attachWebDriverInstance() method to disconnect and changeWebDriverinstance for consistent logging over multiple browser instances.org.openqa.selenium.WebElementfindElement(org.openqa.selenium.By by)WebDrivernative method, but with logging.java.util.List<org.openqa.selenium.WebElement>findElements(org.openqa.selenium.By by)WebDrivernative method, but with logging.voidget(java.lang.String url)WebDrivernative method, but with logging.java.lang.StringgetCurrentUrl()WebDrivernative method, but with logging.java.lang.StringgetPageSource()WebDrivernative method, but with logging.java.lang.StringgetTitle()WebDrivernative method, but with logging.java.lang.StringgetWindowHandle()WebDrivernative method, but with logging.java.util.Set<java.lang.String>getWindowHandles()WebDrivernative method, but with logging.voidlog(java.lang.String message)Push a (TestFlowLogLevel.INFO) message to the log.voidlogDebug(java.lang.String message)Pushes a log message with DEBUG log level to registeredLoggerinstances.voidlogException(java.lang.Exception e)Pushes a log message with EXCEPTION log level to registeredLoggerinstances.voidlogExecutionStep(java.lang.String message)Pushes a log message with EXECUTION_STEP log level to registeredLoggerinstances.voidlogInfo(java.lang.String message)Pushes a log message with INFO log level to registeredLoggerinstances.voidlogVerificationFailed(java.lang.String message)Pushes a log message with FAILED_VERIFICATION log level to registeredLoggerinstances.voidlogVerificationPassed(java.lang.String message)Pushes a log message with PASSED_VERIFICATION log level to registeredLoggerinstances.voidlogVerificationProblem(java.lang.String message)Pushes a log message with VERIFICATION_PROBLEM log level to registeredLoggerinstances.org.openqa.selenium.WebDriver.Optionsmanage()WebDrivernative method, but with logging.org.openqa.selenium.WebDriver.Navigationnavigate()WebDrivernative method, but with logging.voidpauseLogging()Suppresses logging until the resumeLogging() method is called.voidquit()WebDrivernative method, but with logging.voidresumeLogging()Resumes logging after logging has been paused by the pauseLogging() method.LoggingSeleniumWebDriversetMinimumLogLevel(LogLevel logLevel)Sets minimum log level to enable more or less verbose logging.org.openqa.selenium.WebDriver.TargetLocatorswitchTo()WebDrivernative method, but with logging.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
loggerList
List ofLoggerinstances to log output to. -
originalWebDriver
public org.openqa.selenium.WebDriver originalWebDriverRawWebDriverinstance for non-logged interaction.
-
-
Constructor Details
-
LoggingSeleniumWebDriver
public LoggingSeleniumWebDriver(org.openqa.selenium.WebDriver webDriver) -
LoggingSeleniumWebDriver
public LoggingSeleniumWebDriver()Simple constructor mainly for testing purposes. If used, remember to attach a WebDriver instance with attachWebDriverInstance() and add some Logger using addLogger();
-
-
Method Details
-
attachWebDriverInstance
public LoggingSeleniumWebDriver attachWebDriverInstance(org.openqa.selenium.WebDriver driver) throws LoggingSeleniumWebDriverExceptionRe-assigns activeWebDriverinstance to keep consistent logging over multiple browser instances. Note: You must use detachWebDriverInstance before this method to avoid throwing exception.- Parameters:
driver- The newWebDriverinstance to use.- Returns:
- Returns a new instance for chained command structure.
- Throws:
LoggingSeleniumWebDriverException- when not using detachWebDriverInstance before this.
-
setMinimumLogLevel
Sets minimum log level to enable more or less verbose logging.- Parameters:
logLevel- LogLevel, for example from TestFlowLogLevel enum- Returns:
- Returns itself to enable chained commands
-
detachWebDriverInstance
Used before attachWebDriverInstance() method to disconnect and changeWebDriverinstance for consistent logging over multiple browser instances.- Returns:
- Returns itself to enable chained commands
-
addLogger
Add anotherLoggerinstance to the list of loggers to output to.- Parameters:
logger- Any type ofLoggerinstance implementing this interface.- Returns:
- Returns the same instance for chained command purposes.
-
log
public void log(java.lang.String message)Push a (TestFlowLogLevel.INFO) message to the log.- Specified by:
login interfaceLoggingSeleniumComponent- Parameters:
message- The message to output in the log
-
logDebug
public void logDebug(java.lang.String message)Pushes a log message with DEBUG log level to registeredLoggerinstances.- Parameters:
message- The message to output in the log
-
logException
public void logException(java.lang.Exception e)Pushes a log message with EXCEPTION log level to registeredLoggerinstances.- Parameters:
e- Exception to log before being handled.
-
logInfo
public void logInfo(java.lang.String message)Pushes a log message with INFO log level to registeredLoggerinstances.- Parameters:
message- The message to output in the log
-
logVerificationPassed
public void logVerificationPassed(java.lang.String message)Pushes a log message with PASSED_VERIFICATION log level to registeredLoggerinstances.- Parameters:
message- The message to output in the log
-
logVerificationProblem
public void logVerificationProblem(java.lang.String message)Pushes a log message with VERIFICATION_PROBLEM log level to registeredLoggerinstances.- Parameters:
message- The message to output in the log
-
logVerificationFailed
public void logVerificationFailed(java.lang.String message)Pushes a log message with FAILED_VERIFICATION log level to registeredLoggerinstances.- Parameters:
message- The message to output in the log
-
logExecutionStep
public void logExecutionStep(java.lang.String message)Pushes a log message with EXECUTION_STEP log level to registeredLoggerinstances.- Parameters:
message- The message to output in the log
-
pauseLogging
public void pauseLogging()Suppresses logging until the resumeLogging() method is called.- Specified by:
pauseLoggingin interfaceLoggingSeleniumComponent
-
resumeLogging
public void resumeLogging()Resumes logging after logging has been paused by the pauseLogging() method.- Specified by:
resumeLoggingin interfaceLoggingSeleniumComponent
-
get
public void get(java.lang.String url)WebDrivernative method, but with logging.- Specified by:
getin interfaceorg.openqa.selenium.WebDriver- Parameters:
url- The URL to navigate to
-
getCurrentUrl
public java.lang.String getCurrentUrl()WebDrivernative method, but with logging.- Specified by:
getCurrentUrlin interfaceorg.openqa.selenium.WebDriver- Returns:
- The current browser URL
-
getTitle
public java.lang.String getTitle()WebDrivernative method, but with logging.- Specified by:
getTitlein interfaceorg.openqa.selenium.WebDriver- Returns:
- The current browser tab title
-
findElements
public java.util.List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)WebDrivernative method, but with logging.- Specified by:
findElementsin interfaceorg.openqa.selenium.SearchContext- Specified by:
findElementsin interfaceorg.openqa.selenium.WebDriver- Parameters:
by- Selenium element identifier- Returns:
- List of matching elements
-
findElement
public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)WebDrivernative method, but with logging.- Specified by:
findElementin interfaceorg.openqa.selenium.SearchContext- Specified by:
findElementin interfaceorg.openqa.selenium.WebDriver- Parameters:
by- Selenium element identifier- Returns:
- First matching element
-
getPageSource
public java.lang.String getPageSource()WebDrivernative method, but with logging.- Specified by:
getPageSourcein interfaceorg.openqa.selenium.WebDriver- Returns:
- Current browser page source
-
close
public void close()WebDrivernative method, but with logging.- Specified by:
closein interfaceorg.openqa.selenium.WebDriver
-
quit
public void quit()WebDrivernative method, but with logging.- Specified by:
quitin interfaceorg.openqa.selenium.WebDriver
-
getWindowHandles
public java.util.Set<java.lang.String> getWindowHandles()WebDrivernative method, but with logging.- Specified by:
getWindowHandlesin interfaceorg.openqa.selenium.WebDriver- Returns:
- Window handles
-
getWindowHandle
public java.lang.String getWindowHandle()WebDrivernative method, but with logging.- Specified by:
getWindowHandlein interfaceorg.openqa.selenium.WebDriver- Returns:
- Window handle
-
switchTo
public org.openqa.selenium.WebDriver.TargetLocator switchTo()WebDrivernative method, but with logging.- Specified by:
switchToin interfaceorg.openqa.selenium.WebDriver- Returns:
- Locator
-
manage
public org.openqa.selenium.WebDriver.Options manage()WebDrivernative method, but with logging.- Specified by:
managein interfaceorg.openqa.selenium.WebDriver- Returns:
- Options entity
-