Created
February 4, 2016 22:18
-
-
Save mehmetg/32630591fdfe3b48cf10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The code below is a snippet. It won't run or compile unless integrated in the appropriate class | |
** This is only supported on recent versions Firefox and Chrome when used with recent versions of | |
** Firefox and Chrome driver. | |
*/ | |
import org.openqa.selenium.logging.LogEntries; | |
import org.openqa.selenium.logging.LogEntry; | |
import org.openqa.selenium.logging.LogType; | |
import org.openqa.selenium.logging.LoggingPreferences; | |
import org.openqa.selenium.remote.CapabilityType; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
//Recommended while initializing the driver. | |
public void updateLoggingCaps(DesiredCapabilities desiredCaps) { | |
LoggingPreferences logPrefs = new LoggingPreferences(); | |
logPrefs.enable(LogType.BROWSER, Level.ALL); | |
desiredCaps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); | |
} | |
//I'd recommend doing this on test failures only. | |
public void ExtractJSLogs(Webdriver driver) { | |
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER); | |
for (LogEntry entry : logEntries) { | |
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage()); | |
//you can write it to a file | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment