testerra
testerra copied to clipboard
Always log Browser's console messages/errors on failed test
Implement reading console log messages that comes from the browser when a test failed.
Proposal
public List<String> getJavaScriptLog() {
List<String> list = new LinkedList<>();
LogEntries logEntries = this.getWebDriver().manage().logs().get(LogType.BROWSER);
for (LogEntry entry : logEntries) {
list.add(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
}
return list;
}
With Selenium 4 we get native support of Chrome DevTools: https://www.selenium.dev/documentation/webdriver/bidirectional/chrome_devtools/.