Selenium - capture browser logs

  • 2 Replies
  • 1254 Views
Selenium - capture browser logs
« on: July 19, 2016, 17:20:14 pm »
Is there a method to capture all browser logs while running selenium automated tests ?

Re: Selenium - capture browser logs
« Reply #1 on: July 20, 2016, 16:04:48 pm »
Use the following classes and set up logging before running your tests:

Code
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
LoggingPreferences logPreferences = new LoggingPreferences();
logPreferences.enable(LogType.BROWSER, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPreferences);
driver = new ChromeDriver(capabilities);

After the test runs have completed, you can extract the logs like so:
Code
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
for (LogEntry logEntry : logEntries) {
    System.out.println(logEntry.getTimestamp()) + ", " + logEntry.getLevel() + ", " + logEntry.getMessage());
}

Re: Selenium - capture browser logs
« Reply #2 on: July 21, 2016, 18:42:02 pm »
nice
thanks again Dimitri!

 

Sitemap 1 2 3 4 5 6 7 8