private void dumpLog() throws Exception { Logs log = driver.manage().logs(); LogEntries entries = log.get(LogType.BROWSER); // System.out.println(entries); List<LogEntry> list = entries.getAll(); boolean fail = false; for (int i = 0; i < list.size(); i++) { LogEntry e = list.get(i); System.out.println(e); if (e.getLevel().getName().equals("SEVERE") && e.getMessage().indexOf("Uncaught ") != -1 && e.getMessage().indexOf(" Error:") != -1) { System.out.println("*** Uncaught Error ***"); fail = true; } } if (fail) throw new Exception("Unhandled Exception! Check console log for details"); }
protected void dumpBrowserLogs(String testName) { try { Logs logs = webdriver.manage().logs(); for(String type : logs.getAvailableLogTypes()) { String fileName = testName + "_" + type; List<LogEntry> allLogs = logs.get(type).getAll(); if (allLogs.size() > 0) { WEBDRIVER_LOGS_DIR_PATH.mkdirs(); writeLines(new File(WEBDRIVER_LOGS_DIR_PATH, fileName), allLogs); } } } catch (Exception e) { logger.error("Cannot dumpBrowserLogs('" + testName + "')", e); } }
public SeleniumTestResult(WebDriver d, SeleniumTest test, Throwable cause, LoggingPreferences ___lp___) { this.status = false; this.internalTestRes = test.internalTestRs; Logs logs = d.manage().logs(); for (String s : LOG_TYPES_SET) { if(!logs.getAvailableLogTypes().contains(s))continue; LogEntries logEntries = logs.get(s); if(logEntries!=null && !logEntries.getAll().isEmpty()) { this.logs.put(s, new SerializableLogEntries(logEntries.getAll())); } } List<LogEntry> entries = new ArrayList<LogEntry>(); entries.add(new LogEntry(Level.ALL, new Date().getTime(), cause.getMessage())); entries.add(new LogEntry(Level.ALL, new Date().getTime(), ExceptionUtils.getStackTrace(cause))); this.logs.put("gatf", new SerializableLogEntries(entries)); }
public SeleniumTestResult(WebDriver d, SeleniumTest test, LoggingPreferences ___lp___) { this.status = true; this.internalTestRes = test.internalTestRs; Logs logs = d.manage().logs(); for (String s : LOG_TYPES_SET) { if(!logs.getAvailableLogTypes().contains(s))continue; LogEntries logEntries = logs.get(s); if(logEntries!=null && !logEntries.getAll().isEmpty()) { this.logs.put(s, new SerializableLogEntries(logEntries.getAll())); } } }
public SeleniumException(WebDriver d, Throwable cause, SeleniumTest test) { super(cause); Map<String, SerializableLogEntries> lg = new HashMap<String, SerializableLogEntries>(); Logs logs = d.manage().logs(); for (String s : d.manage().logs().getAvailableLogTypes()) { LogEntries logEntries = logs.get(s); if(!logEntries.getAll().isEmpty()) { lg.put(s, new SerializableLogEntries(logEntries.getAll())); } } List<LogEntry> entries = new ArrayList<LogEntry>(); entries.add(new LogEntry(Level.ALL, new Date().getTime(), cause.getMessage())); entries.add(new LogEntry(Level.ALL, new Date().getTime(), ExceptionUtils.getStackTrace(cause))); lg.put("gatf", new SerializableLogEntries(entries)); }
@Test public void getAvailableLogTypes() { WebDriver driver = new ChromeDriver(); driver.get("http://ticketfly.com"); Options manage = driver.manage(); Logs logs = manage.logs(); Set<String> availableLogTypes = logs.getAvailableLogTypes(); System.out.println(availableLogTypes); availableLogTypes.stream().forEach(logType -> { System.out.println("logType=" + logType); LogEntries logEntries = logs.get(logType); List<LogEntry> all = logEntries.getAll(); all.forEach(entry -> { System.out.println(entry.getLevel()); System.out.println(entry.getMessage()); System.out.println(entry.getTimestamp()); System.out.println(entry.toMap()); System.out.println(entry); }); List<LogEntry> filter = logEntries.filter(Level.SEVERE); System.out.println("After filtering"); filter.forEach(System.out::println); System.out.println("Done"); }); }
@Override public List<String> getSeleniumLog(Session session) { List<String> result = new ArrayList(); Logs logs = session.getDriver().manage().logs(); for (String logType : logs.getAvailableLogTypes()) { LogEntries logEntries = logs.get(logType); result.add("********************" + logType + "********************\n"); for (LogEntry logEntry : logEntries) { result.add(new Date(logEntry.getTimestamp()) + " : " + logEntry.getLevel() + " : " + logEntry.getMessage() + "\n"); } } return result; }
public void clearlogs(String logType) { Logs logs = manage().logs(); logs.get(logType); }
@Override public Logs logs() { return options.logs(); }
@Override public Logs logs() { return delegate.logs(); }
@Override public Logs logs() { throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); }
@Override public Logs logs() { return new DelegatorLogs(); }
@Override public Logs logs() { return null; }
/** * Gets the {@link Logs} interface used to fetch different types of logs. * <p> * <p>To set the logging preferences {@link LoggingPreferences}. * * @return A Logs interface. */ @Beta Logs logs();