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 class  LoggingSeleniumWebDriver.Builder
    LoggingSeleniumWebDriver constructor 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
    LoggerList loggerList
    List of Logger instances to log output to.
    org.openqa.selenium.WebDriver originalWebDriver
    Raw WebDriver instance 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
    LoggingSeleniumWebDriver addLogger​(Logger logger)
    Add another Logger instance to the list of loggers to output to.
    LoggingSeleniumWebDriver attachWebDriverInstance​(org.openqa.selenium.WebDriver driver)
    Re-assigns active WebDriver instance to keep consistent logging over multiple browser instances.
    void close()
    WebDriver native method, but with logging.
    LoggingSeleniumWebDriver detachWebDriverInstance()
    Used before attachWebDriverInstance() method to disconnect and change WebDriver instance for consistent logging over multiple browser instances.
    org.openqa.selenium.WebElement findElement​(org.openqa.selenium.By by)
    WebDriver native method, but with logging.
    java.util.List<org.openqa.selenium.WebElement> findElements​(org.openqa.selenium.By by)
    WebDriver native method, but with logging.
    void get​(java.lang.String url)
    WebDriver native method, but with logging.
    java.lang.String getCurrentUrl()
    WebDriver native method, but with logging.
    java.lang.String getPageSource()
    WebDriver native method, but with logging.
    java.lang.String getTitle()
    WebDriver native method, but with logging.
    java.lang.String getWindowHandle()
    WebDriver native method, but with logging.
    java.util.Set<java.lang.String> getWindowHandles()
    WebDriver native method, but with logging.
    void log​(java.lang.String message)
    Push a (TestFlowLogLevel.INFO) message to the log.
    void logDebug​(java.lang.String message)
    Pushes a log message with DEBUG log level to registered Logger instances.
    void logException​(java.lang.Exception e)
    Pushes a log message with EXCEPTION log level to registered Logger instances.
    void logExecutionStep​(java.lang.String message)
    Pushes a log message with EXECUTION_STEP log level to registered Logger instances.
    void logInfo​(java.lang.String message)
    Pushes a log message with INFO log level to registered Logger instances.
    void logVerificationFailed​(java.lang.String message)
    Pushes a log message with FAILED_VERIFICATION log level to registered Logger instances.
    void logVerificationPassed​(java.lang.String message)
    Pushes a log message with PASSED_VERIFICATION log level to registered Logger instances.
    void logVerificationProblem​(java.lang.String message)
    Pushes a log message with VERIFICATION_PROBLEM log level to registered Logger instances.
    org.openqa.selenium.WebDriver.Options manage()
    WebDriver native method, but with logging.
    org.openqa.selenium.WebDriver.Navigation navigate()
    WebDriver native method, but with logging.
    void pauseLogging()
    Suppresses logging until the resumeLogging() method is called.
    void quit()
    WebDriver native method, but with logging.
    void resumeLogging()
    Resumes logging after logging has been paused by the pauseLogging() method.
    LoggingSeleniumWebDriver setMinimumLogLevel​(LogLevel logLevel)
    Sets minimum log level to enable more or less verbose logging.
    org.openqa.selenium.WebDriver.TargetLocator switchTo()
    WebDriver native 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

      public LoggerList loggerList
      List of Logger instances to log output to.
    • originalWebDriver

      public org.openqa.selenium.WebDriver originalWebDriver
      Raw WebDriver instance 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 LoggingSeleniumWebDriverException
      Re-assigns active WebDriver instance to keep consistent logging over multiple browser instances. Note: You must use detachWebDriverInstance before this method to avoid throwing exception.
      Parameters:
      driver - The new WebDriver instance to use.
      Returns:
      Returns a new instance for chained command structure.
      Throws:
      LoggingSeleniumWebDriverException - when not using detachWebDriverInstance before this.
    • setMinimumLogLevel

      public LoggingSeleniumWebDriver setMinimumLogLevel​(LogLevel logLevel)
      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

      public LoggingSeleniumWebDriver detachWebDriverInstance()
      Used before attachWebDriverInstance() method to disconnect and change WebDriver instance for consistent logging over multiple browser instances.
      Returns:
      Returns itself to enable chained commands
    • addLogger

      public LoggingSeleniumWebDriver addLogger​(Logger logger)
      Add another Logger instance to the list of loggers to output to.
      Parameters:
      logger - Any type of Logger instance 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:
      log in interface LoggingSeleniumComponent
      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 registered Logger instances.
      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 registered Logger instances.
      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 registered Logger instances.
      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 registered Logger instances.
      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 registered Logger instances.
      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 registered Logger instances.
      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 registered Logger instances.
      Parameters:
      message - The message to output in the log
    • pauseLogging

      public void pauseLogging()
      Suppresses logging until the resumeLogging() method is called.
      Specified by:
      pauseLogging in interface LoggingSeleniumComponent
    • resumeLogging

      public void resumeLogging()
      Resumes logging after logging has been paused by the pauseLogging() method.
      Specified by:
      resumeLogging in interface LoggingSeleniumComponent
    • get

      public void get​(java.lang.String url)
      WebDriver native method, but with logging.
      Specified by:
      get in interface org.openqa.selenium.WebDriver
      Parameters:
      url - The URL to navigate to
    • getCurrentUrl

      public java.lang.String getCurrentUrl()
      WebDriver native method, but with logging.
      Specified by:
      getCurrentUrl in interface org.openqa.selenium.WebDriver
      Returns:
      The current browser URL
    • getTitle

      public java.lang.String getTitle()
      WebDriver native method, but with logging.
      Specified by:
      getTitle in interface org.openqa.selenium.WebDriver
      Returns:
      The current browser tab title
    • findElements

      public java.util.List<org.openqa.selenium.WebElement> findElements​(org.openqa.selenium.By by)
      WebDriver native method, but with logging.
      Specified by:
      findElements in interface org.openqa.selenium.SearchContext
      Specified by:
      findElements in interface org.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)
      WebDriver native method, but with logging.
      Specified by:
      findElement in interface org.openqa.selenium.SearchContext
      Specified by:
      findElement in interface org.openqa.selenium.WebDriver
      Parameters:
      by - Selenium element identifier
      Returns:
      First matching element
    • getPageSource

      public java.lang.String getPageSource()
      WebDriver native method, but with logging.
      Specified by:
      getPageSource in interface org.openqa.selenium.WebDriver
      Returns:
      Current browser page source
    • close

      public void close()
      WebDriver native method, but with logging.
      Specified by:
      close in interface org.openqa.selenium.WebDriver
    • quit

      public void quit()
      WebDriver native method, but with logging.
      Specified by:
      quit in interface org.openqa.selenium.WebDriver
    • getWindowHandles

      public java.util.Set<java.lang.String> getWindowHandles()
      WebDriver native method, but with logging.
      Specified by:
      getWindowHandles in interface org.openqa.selenium.WebDriver
      Returns:
      Window handles
    • getWindowHandle

      public java.lang.String getWindowHandle()
      WebDriver native method, but with logging.
      Specified by:
      getWindowHandle in interface org.openqa.selenium.WebDriver
      Returns:
      Window handle
    • switchTo

      public org.openqa.selenium.WebDriver.TargetLocator switchTo()
      WebDriver native method, but with logging.
      Specified by:
      switchTo in interface org.openqa.selenium.WebDriver
      Returns:
      Locator
    • manage

      public org.openqa.selenium.WebDriver.Options manage()
      WebDriver native method, but with logging.
      Specified by:
      manage in interface org.openqa.selenium.WebDriver
      Returns:
      Options entity