Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

Is it possible to obtain the logger somehow that Selenium WebDriver uses? I want to capture a transcript of all the commands that were issued (eg: open, wait, click, etc). In particular, I am looking for a java solution, as I am exporting the tests into JUnit.

I found this code on their website, however it displays nothing on standard out

    DesiredCapabilities caps = DesiredCapabilities.firefox(); 

    LoggingPreferences logs = new LoggingPreferences(); 

    logs.enable(LogType.DRIVER, Level.FINEST); 

    caps.setCapability(CapabilityType.LOGGING_PREFS, logs); 

    driver = new FirefoxDriver(caps);

1 Answer

0 votes
by (62.9k points)

To enable logging in the driver which you're currently using, select which log types you're interested in and the log level (I'm using FirefoxDriver, enabling all types of logs and collecting all log messages)

 

LoggingPreferences logs = new LoggingPreferences();

logs.enable(LogType.BROWSER, Level.ALL);

logs.enable(LogType.CLIENT, Level.ALL);

logs.enable(LogType.DRIVER, Level.ALL);

logs.enable(LogType.PERFORMANCE, Level.ALL);

logs.enable(LogType.PROFILER, Level.ALL);

logs.enable(LogType.SERVER, Level.ALL);

 

DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();

desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logs);

 

WebDriver driver = new FirefoxDriver(desiredCapabilities);

After running the test you can collect the logs, here, I'm solely collecting the DRIVER logs, but you could do this similarly for any type of logs)

 

Logs logs = driver.manage().logs();

LogEntries logEntries = logs.get(LogType.DRIVER);

 

for (LogEntry logEntry : logEntries) {

    System.out.println(logEntry.getMessage());

}

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...