Wednesday, July 1, 2015

SELENIUM : READ BROWSER CONSOLE LOG


Initialize driver with logging preferences.




DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
driver = new ChromeDriver(caps);
Now analyze log using below code:
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);

for (LogEntry entry : logEntries) {
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
//do something useful with the data
}

No comments:

Post a Comment