How to get browser logs

New generation checks


How to get browser logs

Selenide Advent Calendar
Day 16

Good evening!

We continue our Selenide Advent Calendar.
Today we will try to look into browser “developer tools”.
It may be useful if you want to know what errors happened during test run, or what requests your AUT sent.

Chromedriver suggests the following receipt.

1. Add a couple of lines before opening a browser:

LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
capabilities.setCapability("goog:loggingPrefs", logPrefs);

This capability was named “loggingPrefs” until some version of Chrome, and then was renamed to “goog:loggingPrefs”.
Not sure about other browsers.

Besides BROWSER and PERFORMANCE there are other types too, but I didn’t understand them.

2. Fetch the logs in the end of test:

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

void printLog(LogEntries entries) {"{} log entries found", entries.getAll().size());
    for (LogEntry entry : entries) {"{} {} {}",
        new Date(entry.getTimestamp()), entry.getLevel(), entry.getMessage()

3. This is how BROWSER logs look like:


Mon Dec 16 19:29:42 EET 2019 SEVERE http://localhost:9126/page/image/payment-promo-campaign-ozon.png - Failed to load resource: the server responded with a status of 404 (Not Found)
Mon Dec 16 19:49:14 EET 2019 INFO console-api 19:16 "start loading loans"
Mon Dec 16 19:49:14 EET 2019 INFO console-api 21:18 "loaded loans"

Here you can see all logs usually seen at “Developer Tools” -> “Console” tab. Including console.log messages and JavaScript errors.

4. And this is how PERFORMANCE logs look like:




Every record is a valid JSON. You can parse and analyze right in your test.

This is how the first record looks formatted:



  • It’s hard to understand those logs. Some additional analyzers might be needed.
  • We don’t see request body here.

What’s next?

Next time we will try other ways to get browser logs - including http statuses and request bodies.

Andrei Solntsev

The project is maintained by