LoggingSeleniumWebDriver - Java

2023-05-19

Background

A friend of mine contacted me asking for a logging framework for Selenium. The governance at his work was nagging him about the test automation not logging what it does - hence failing compliance in reporting how tests were made.

He was using Selenium in a Java environment. I remembered some logging libraries I'd created for .NET and Java for Selenium - simply wrapping any Selenium WebDriver (IWebDriver for C#) instance with a logging framework suitable for test automation.

I had a look at it, realized it needed some rework, but soon I had a working library going again. I pushed it to GitHub and uploaded it to maven central.

Usage

Usage is simple, but best described at the pages at GitHub.

Get from maven central

    
    <dependency> 
        <groupId>com.github.claremontqualitymanagement.LoggingSeleniumWebDriver</groupId> 
        <artifactId>LoggingSeleniumWebDriver</artifactId> 
        <version>1.0.1</version> 
    </dependency> 
            

Constructor from builder pattern

You may instantiate the wrapped driver in the classical way, or you may use the builder pattern.
    
    WebDriver driver = new LoggingSeleniumWebDriver.Builder()
        .attachWebDriverInstance(new ChromeDriver())
        .addLogger(new ConsoleLogger())
        .setMinimumLogLevel(LogLevel.DEBUG)
        .build();
    driver.get("https://mysite.com");
            

.NET/C# version

Also check out a similar library wrapping any C# based IWebDriver instance to make it a logging instance with extendible loggers.