@Test public void testSimpleSamlLoginWithAddShadowUserOnLoginFalse() throws Exception { // Deleting marissa@test.org from simplesamlphp because previous SAML authentications automatically // create a UAA user with the email address as the username. deleteUser(SAML_ORIGIN, testAccounts.getEmail()); IdentityProvider provider = IntegrationTestUtils.createIdentityProvider(SAML_ORIGIN, false, baseUrl, serverRunning); String clientId = "app-addnew-false"+ new RandomValueStringGenerator().generate(); String redirectUri = "http://nosuchhostname:0/nosuchendpoint"; BaseClientDetails client = createClientAndSpecifyProvider(clientId, provider, redirectUri); String firstUrl = "/oauth/authorize?" + "client_id=" + clientId + "&response_type=code" + "&redirect_uri=" + URLEncoder.encode(redirectUri, "UTF-8"); webDriver.get(baseUrl + firstUrl); webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]")); webDriver.findElement(By.name("username")).clear(); webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName()); webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword()); webDriver.findElement(By.xpath("//input[@value='Login']")).click(); // We need to verify the last request URL through the performance log because the redirect // URI does not exist. When the webDriver follows the non-existent redirect URI it receives a // connection refused error so webDriver.getCurrentURL() will remain as the SAML IdP URL. List<LogEntry> logEntries = webDriver.manage().logs().get(LogType.PERFORMANCE).getAll(); List<String> logMessages = logEntries.stream().map(logEntry -> logEntry.getMessage()).collect(Collectors.toList()); assertThat(logMessages, hasItem(containsString(redirectUri + "?error=access_denied&error_description=SAML+user+does+not+exist.+You+can+correct+this+by+creating+a+shadow+user+for+the+SAML+user."))); }
private List<LogEntry> getLogEntries(String logType, Level logLevel) { try { return driver.getWebDriver().manage().logs().get(logType).filter(logLevel); } catch (UnsupportedOperationException ignore) { return emptyList(); } }
@Test public void captureLogcat() { // inspect available log types Set<String> logtypes = driver.manage().logs().getAvailableLogTypes(); System.out.println("suported log types: " + logtypes.toString()); // [logcat, bugreport, server, client] // print first and last 10 lines of logs LogEntries logs = driver.manage().logs().get("logcat"); System.out.println("First and last ten lines of log: "); StreamSupport.stream(logs.spliterator(), false).limit(10).forEach(System.out::println); System.out.println("..."); StreamSupport.stream(logs.spliterator(), false).skip(logs.getAll().size() - 10).forEach(System.out::println); // wait for more logs try { Thread.sleep(5000); } catch (Exception ign) {} // pause to allow visual verification // demonstrate that each time get logs, we only get new logs // which were generated since the last time we got logs LogEntries secondCallToLogs = driver.manage().logs().get("logcat"); System.out.println("\nFirst ten lines of next log call: "); StreamSupport.stream(secondCallToLogs.spliterator(), false).limit(10).forEach(System.out::println); Assert.assertNotEquals(logs.iterator().next(), secondCallToLogs.iterator().next()); } }
public LogEntries get(String logType) { return new LogEntries(Collections.emptyList()); }
@Override public Set<JsErrorLog> getJSErrorLogs() { LogEntries logEntries = webDriver.manage().logs().get(LogType.BROWSER); return StreamSupport.stream(logEntries.spliterator(), false) .filter(ONLY_SEVERE_ERRORS) .map(LOG_ENTRY_TO_JS_ERROR) .collect(Collectors.toCollection(() -> new TreeSet<>(Ordering.natural()))); }
public LogEntries getLogs(String logType) { if (logType == null || !logTypeToEntriesMap.containsKey(logType)) { return new LogEntries(Collections.emptyList()); } return logTypeToEntriesMap.get(logType); }
@Override public Set<JsErrorLog> getJSErrorLogs() { LogEntries logEntries = webDriver.manage().logs().get(LogType.BROWSER); return StreamSupport.stream(logEntries.spliterator(), false) .filter(ONLY_SEVERE_ERRORS) .map(LOG_ENTRY_TO_JS_ERROR) .collect(Collectors.toCollection(() -> new TreeSet<>(Ordering.natural()))); }
@Beta public List<LogEntry> toJson() { return getAll(); } }
public static LogEntries combine(LogEntries... entries) { return new LogEntries( Stream.of(entries) .map(LogEntries::getAll) .flatMap(Collection::stream) .sorted(LOG_ENTRY_TIMESTAMP_COMPARATOR) .collect(Collectors.toList())); } }
for (LogEntry entry : driver.manage().logs().get("javascript").filter(Level.ALL)) { ++messages; test(!StringUtils.isEmpty(entry.getMessage()));
private StringBuilder formatedBrowserLogs() { StringBuilder logEntries = new StringBuilder(); SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (LogEntry logEntry : getBrowserLog().getAll()) { logEntries.append(logEntry.getLevel()).append(": ") .append(sdfDate.format(logEntry.getTimestamp())).append(": ") .append(logEntry.getMessage()).append(System.lineSeparator()); } return logEntries; }
public LogEntries get(String logType) { if (LogType.CLIENT.equals(logType) && logTypesToInclude.contains(logType)) { Collection<LogEntry> entries = loggingHandler.getRecords(); loggingHandler.flush(); return new LogEntries(entries); } return new LogEntries(Collections.emptyList()); }
default List<String> console() { return driver().manage().logs().get("browser").getAll().stream() .map(log -> log.getMessage() .replace(" (undefined:undefined)", "") .replace(" (:)", "") .replace("\n anonymous (:1)", "")) .collect(toList()); }
LogEntries toLogEntries() { List<LogEntry> list = new ArrayList<LogEntry>(); for (Entry entry : entries) { list.add(entry.toLogEntry()); } return new LogEntries(list); } }
default List<String> console() { return driver().manage().logs().get("browser").getAll().stream() .map(log -> log.getMessage() .replace(" (undefined:undefined)", "") .replace(" (:)", "") .replace("\n anonymous (:1)", "")) .collect(toList()); }
public LogEntries get(String logType) { Iterable<LogEntry> toReturn = getLocalLogs(logType); localLogs.remove(logType); return new LogEntries(toReturn); }
@Override protected void failed(Throwable e, Description description) { List<LogEntry> logs = Browser.getCurrentDriver().manage().logs().get("browser").getAll(); System.err.println("Browser's console:"); if (logs.isEmpty()) { System.err.println("<EMPTY>"); } else { for (LogEntry log : logs) { System.err.println(" - " + log.getMessage().replace(" (undefined:undefined)", "")); } } } }
public LogEntries get(String logType) { return new LogEntries(getLocalLogs(logType)); }
/** * Gets the log entries from the browser that have the given logging level * or higher. * * @param level * the minimum severity of logs included * @return log entries from the browser */ protected List<LogEntry> getLogEntries(Level level) { return driver.manage().logs().get(LogType.BROWSER).getAll().stream() .filter(logEntry -> logEntry.getLevel().intValue() >= level .intValue()) // we always have this error .filter(logEntry -> !logEntry.getMessage() .contains("favicon.ico")) .collect(Collectors.toList()); }
public LogEntries get(String logType) { if (LogType.CLIENT.equals(logType)) { LoggingHandler loggingHandler = LoggingHandler.getInstance(); List<LogEntry> entries = loggingHandler.getRecords(); loggingHandler.flush(); return new LogEntries(entries); } return new LogEntries(Lists.<LogEntry>newArrayList()); }