@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."))); }
@Beta public List<LogEntry> toJson() { return getAll(); } }
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; }
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()); }
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()); }
@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)", "")); } } } }
/** * 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()); }
@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)", "")); } } } }
theBinaryDara[i] = (int) (theLongValue); final List<LogEntry> theAll = theDriver.manage().logs().get(LogType.BROWSER).getAll(); for (final LogEntry theEntry : theAll) { System.out.println(theEntry.getMessage());
try { List<LogEntry> entries = webdriver.manage().logs().get(type).getAll(); System.out.println(entries.size() + " " + type + " log entries found"); for (LogEntry entry : entries) {
void checkForErrors(WebDriver driver, JobConfig jobConfig) { if (jobConfig.checkForErrorsInLog) { LOG.debug("Checking for errors."); LogEntries logEntries; try { logEntries = driver.manage().logs().get(LogType.BROWSER); } catch (UnsupportedCommandException e) { logEntries = null; } if (logEntries != null && !logEntries.getAll().isEmpty() && logEntries.getAll().get(0).getLevel() == Level.SEVERE) { throw new WebDriverException(logEntries.getAll().get(0).getMessage()); } if (jobConfig.browser.isChrome()) { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { WebElement element = driver.findElement(By.className("error-code")); if (element != null && element.getText() != null) { element.getText(); throw new WebDriverException(element.getText()); } } catch (NoSuchElementException e) { //ignore } finally { driver.manage().timeouts().implicitlyWait(Browser.DEFAULT_IMPLICIT_WAIT_TIME_IN_SECONDS, TimeUnit.SECONDS); } } } } }
final List<LogEntry> theAll = theDriver.manage().logs().get(LogType.BROWSER).getAll(); for (final LogEntry theEntry : theAll) { final String theMessage = theEntry.getMessage();
final List<LogEntry> theAll = theDriver.manage().logs().get(LogType.BROWSER).getAll(); for (final LogEntry theEntry : theAll) { final String theMessage = theEntry.getMessage();
theDriver.get(theGeneratedFile.toURI().toURL().toString()); final List<LogEntry> theAll = theDriver.manage().logs().get(LogType.BROWSER).getAll(); if (1 > theAll.size()) { aRunNotifier.fireTestFailure(new Failure(theDescription, new RuntimeException("No console output from browser")));
theDriver.get(theGeneratedFile.toURI().toURL().toString()); final List<LogEntry> theAll = theDriver.manage().logs().get(LogType.BROWSER).getAll(); if (1 > theAll.size()) { aRunNotifier.fireTestFailure(new Failure(theDescription, new RuntimeException("No console output from browser")));
private void logErrors(String url, LogEntries logEntries) { if (logEntries.getAll().size() == 0) { TestLogging.log("********* No Severe Error on Browser Console *********", true); } else { for (LogEntry logEntry : logEntries) { if (logEntry.getLevel().equals(Level.SEVERE)) { TestLogging.log("URL: "+url); TestLogging.logWebStep("Time stamp: " + logEntry.getTimestamp() + ", " + "Log level: " + logEntry .getLevel() + ", Log message: " + logEntry.getMessage(), true); isJSErrorFound = true; } } assert !isJSErrorFound; } }
@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()); } }
private void logErrors(String event, WebElement element, LogEntries logEntries) { if (logEntries.getAll().size() == 0) { TestLogging.log("********* No Severe Error on Browser Console *********", true); } else { for (LogEntry logEntry : logEntries) { if (logEntry.getLevel().equals(Level.SEVERE)) { TestLogging.log("Sever Console Error on Browser "+event+" clicking " + "element: " +((HtmlElement)element).getBy()); TestLogging.logWebStep("Time stamp: " + logEntry.getTimestamp() + ", " + "Log level: " + logEntry .getLevel() + ", Log message: " + logEntry.getMessage(), true); isJSErrorFound = true; } } assert !isJSErrorFound; } }
try { writer = new PrintWriter(Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), String.format("driver-log-%s.txt", logType)).toFile().getAbsolutePath(), "UTF-8"); for (LogEntry line: driver.manage().logs().get(logType).getAll()) { writer.println(line.toString());