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);
Selenium Webdriver is a great tool to automate web-based applications. But it does not support read and write operations on excel files.
Log4j is an audit logging framework that gives information about what has happened during execution. It offers the following advantages − Enables us to understand the application run. Log output can be saved that can be analyzed later. Helps in debugging, in case of test automation failures.
Enable logging in the driver you're 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);
Then, after running the test you can collect the logs (I'm only collecting the DRIVER logs, but you can do the same for any type of log)
Logs logs = driver.manage().logs();
LogEntries logEntries = logs.get(LogType.DRIVER);
for (LogEntry logEntry : logEntries) {
System.out.println(logEntry.getMessage());
}
Try
driver.manage().logs()
You will get Logs interface that has methods to get logs and log types. See Logs interface docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With