org.openqa.selenium.logging.LogEntry Java Examples
The following examples show how to use
org.openqa.selenium.logging.LogEntry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertOnly() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " number = 1;\n" + " console.assert(number % 2 === 0);\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("Assertion failed")); }
Example #2
Source File: RemoteLogs.java From selenium with Apache License 2.0 | 6 votes |
private LogEntries getRemoteEntries(String logType) { Object raw = executeMethod.execute(DriverCommand.GET_LOG, ImmutableMap.of(TYPE_KEY, logType)); if (!(raw instanceof List)) { throw new UnsupportedCommandException("malformed response to remote logs command"); } @SuppressWarnings("unchecked") List<Map<String, Object>> rawList = (List<Map<String, Object>>) raw; List<LogEntry> remoteEntries = new ArrayList<>(rawList.size()); for (Map<String, Object> obj : rawList) { remoteEntries.add(new LogEntry(LogLevelMapping.toLevel((String)obj.get(LEVEL)), (Long) obj.get(TIMESTAMP), (String) obj.get(MESSAGE))); } return new LogEntries(remoteEntries); }
Example #3
Source File: RemoteLogsTest.java From selenium with Apache License 2.0 | 6 votes |
@Test public void canGetLocalProfilerLogsIfNoRemoteProfilerLogSupport() { List<LogEntry> entries = new ArrayList<>(); entries.add(new LogEntry(Level.INFO, 0, "hello")); when(localLogs.get(LogType.PROFILER)).thenReturn(new LogEntries(entries)); when( executeMethod.execute( DriverCommand.GET_LOG, ImmutableMap.of(RemoteLogs.TYPE_KEY, LogType.PROFILER))) .thenThrow( new WebDriverException("IGNORE THIS LOG MESSAGE AND STACKTRACE; IT IS EXPECTED.")); LogEntries logEntries = remoteLogs.get(LogType.PROFILER); List<LogEntry> allLogEntries = logEntries.getAll(); assertThat(allLogEntries).hasSize(1); assertThat(allLogEntries.get(0).getMessage()).isEqualTo("hello"); }
Example #4
Source File: SeleniumTest.java From gatf with Apache License 2.0 | 6 votes |
public SeleniumTestResult(WebDriver d, SeleniumTest test, Throwable cause, LoggingPreferences ___lp___) { this.status = false; this.internalTestRes = test.getSession().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)); }
Example #5
Source File: JsonOutputTest.java From selenium with Apache License 2.0 | 6 votes |
@Test public void convertLogEntriesToJson() { long timestamp = new Date().getTime(); final LogEntry entry1 = new LogEntry(Level.OFF, timestamp, "entry1"); final LogEntry entry2 = new LogEntry(Level.WARNING, timestamp, "entry2"); LogEntries entries = new LogEntries(asList(entry1, entry2)); String json = convert(entries); JsonArray converted = new JsonParser().parse(json).getAsJsonArray(); JsonObject obj1 = converted.get(0).getAsJsonObject(); JsonObject obj2 = converted.get(1).getAsJsonObject(); assertThat(obj1.get("level").getAsString()).isEqualTo("OFF"); assertThat(obj1.get("timestamp").getAsLong()).isEqualTo(timestamp); assertThat(obj1.get("message").getAsString()).isEqualTo("entry1"); assertThat(obj2.get("level").getAsString()).isEqualTo("WARNING"); assertThat(obj2.get("timestamp").getAsLong()).isEqualTo(timestamp); assertThat(obj2.get("message").getAsString()).isEqualTo("entry2"); }
Example #6
Source File: RemoteLogsTest.java From selenium with Apache License 2.0 | 6 votes |
@Test public void canGetProfilerLogs() { List<LogEntry> entries = new ArrayList<>(); entries.add(new LogEntry(Level.INFO, 0, "hello")); when(localLogs.get(LogType.PROFILER)).thenReturn(new LogEntries(entries)); when( executeMethod.execute( DriverCommand.GET_LOG, ImmutableMap.of(RemoteLogs.TYPE_KEY, LogType.PROFILER))) .thenReturn(singletonList( ImmutableMap.of("level", Level.INFO.getName(), "timestamp", 1L, "message", "world"))); LogEntries logEntries = remoteLogs.get(LogType.PROFILER); List<LogEntry> allLogEntries = logEntries.getAll(); assertThat(allLogEntries).hasSize(2); assertThat(allLogEntries.get(0).getMessage()).isEqualTo("hello"); assertThat(allLogEntries.get(1).getMessage()).isEqualTo("world"); }
Example #7
Source File: TestLogger.java From AppiumTestDistribution with GNU General Public License v3.0 | 6 votes |
protected void startLogging(ITestResult iTestResult) throws IOException, InterruptedException { String methodName = iTestResult.getMethod().getMethodName(); String className = iTestResult.getTestClass() .getRealClass().getSimpleName(); if (isNativeAndroid()) { String udid = AppiumDeviceManager.getAppiumDevice().getDevice().getUdid(); List<LogEntry> logcat = AppiumDriverManager.getDriver().manage() .logs().get("logcat").filter(Level.ALL); logEntries.set(logcat); logFile = new File(System.getProperty("user.dir") + FileLocations.ADB_LOGS_DIRECTORY + udid + "__" + methodName + ".txt"); log_file_writer.set(new PrintWriter(logFile)); } if ("true".equalsIgnoreCase(System.getenv("VIDEO_LOGS"))) { IScreenRecord videoRecording = AppiumScreenRecordFactory.recordScreen(); videoRecording.startVideoRecording(className, methodName, methodName); } setDescription(iTestResult); }
Example #8
Source File: BrowserTest.java From kurento-java with Apache License 2.0 | 6 votes |
@FailedTest public static void storeBrowsersLogs() { List<String> lines = new ArrayList<>(); for (String browserKey : browserLogs.keySet()) { for (LogEntry logEntry : browserLogs.get(browserKey)) { lines.add(logEntry.toString()); } File file = new File(getDefaultOutputFile("-" + browserKey + "-console.log")); try { FileUtils.writeLines(file, lines); } catch (IOException e) { log.error("Error while writing browser log to a file", e); } } }
Example #9
Source File: Edition088_Debugging_Aids.java From appiumpro with Apache License 2.0 | 6 votes |
@Override protected void failed(Throwable e, Description desc) { // print appium logs LogEntries entries = driver.manage().logs().get("server"); System.out.println("======== APPIUM SERVER LOGS ========"); for (LogEntry entry : entries) { System.out.println(new Date(entry.getTimestamp()) + " " + entry.getMessage()); } System.out.println("================"); // print source System.out.println("======== APP SOURCE ========"); System.out.println(driver.getPageSource()); System.out.println("================"); // save screenshot String testName = desc.getMethodName().replaceAll("[^a-zA-Z0-9-_\\.]", "_"); File screenData = driver.getScreenshotAs(OutputType.FILE); try { File screenFile = new File(SCREEN_DIR + "/" + testName + ".png"); FileUtils.copyFile(screenData, screenFile); System.out.println("======== SCREENSHOT ========"); System.out.println(screenFile.getAbsolutePath()); System.out.println("================"); } catch (IOException ign) {} }
Example #10
Source File: DynamicDependencyIT.java From flow with Apache License 2.0 | 6 votes |
private void testErrorCase(String caseName, String errorMessageSnippet) { open(); if (hasClientUnknownIssue()) { return; } findElement(By.id(caseName)).click(); String statusText = findElement(By.id("new-component")).getText(); Assert.assertEquals("Div updated for " + caseName, statusText); List<LogEntry> entries = getLogEntries(Level.SEVERE); Assert.assertEquals(2, entries.size()); Assert.assertThat(entries.get(0).getMessage(), Matchers.containsString(errorMessageSnippet)); Assert.assertThat(entries.get(1).getMessage(), Matchers.containsString("could not be loaded")); }
Example #11
Source File: WebComponentsIT.java From flow with Apache License 2.0 | 6 votes |
@Test public void testPolyfillLoaded() { open(); if (BrowserUtil.isIE(getDesiredCapabilities())) { // Console logs are not available from IE11 return; } LogEntries logs = driver.manage().logs().get("browser"); if (logs != null) { Optional<LogEntry> anyError = StreamSupport .stream(logs.spliterator(), true) .filter(entry -> entry.getLevel().intValue() > Level.INFO .intValue()) .filter(entry -> !entry.getMessage() .contains("favicon.ico")) .filter(entry -> !entry.getMessage() .contains("sockjs-node")) .filter(entry -> !entry.getMessage() .contains("[WDS] Disconnected!")) .findAny(); anyError.ifPresent(entry -> Assert.fail(entry.getMessage())); } }
Example #12
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertString() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " number = 1;\n" + " console.assert(number % 2 === 0, 'the # is not even');\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("Assertion failed: the # is not even")); }
Example #13
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertObject() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " number = 1;\n" + " console.assert(number % 2 === 0, {number: number, errorMsg: 'the # is not even'});\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage() .contains("Assertion failed: ({number: 1.0, errorMsg: \"the # is not even\"})")); }
Example #14
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertObjects() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " number = 1;\n" + " console.assert(number % 2 === 0, {number: number}, {errorMsg: 'the # is not even'});\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage() .contains("Assertion failed: ({number: 1.0}) ({errorMsg: \"the # is not even\"})")); }
Example #15
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertParams() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " console.assert(false, 'the word is %s', 'foo');\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage() .contains("Assertion failed: the word is foo")); }
Example #16
Source File: WebDriverServerLogEnricher.java From justtestlah with Apache License 2.0 | 6 votes |
@SuppressWarnings("squid:S4784") private void appendWebDriverLog(WebDriver driver) { for (String logType : logTypes) { for (LogEntry log : driver.manage().logs().get(logType)) { DateFormat formatter = new SimpleDateFormat("HH:mm:ss.SSS"); String message = log.getMessage(); // filter out messages related to fetching the log if (!message.matches(REGEXP_FILTER)) { SERVER_LOG .atInfo() .addArgument(() -> logType) .addArgument(() -> formatter.format(log.getTimestamp())) .addArgument(() -> log.getMessage()) .log("{} {} {}"); } } } }
Example #17
Source File: JsUtility.java From Selenium-Foundation with Apache License 2.0 | 6 votes |
/** * Propagate the specified web driver exception, extracting encoded JavaScript exception if present * * @param driver A handle to the currently running Selenium test window. * @param exception web driver exception to propagate * @return nothing (this method always throws the specified exception) * @since 17.4.0 */ public static RuntimeException propagate(final WebDriver driver, final WebDriverException exception) { Throwable thrown = exception; // if exception is a WebDriverException (not a sub-class) if (JS_EXCEPTIONS.contains(exception.getClass().getName())) { // extract serialized exception object from message thrown = extractException(exception, exception.getMessage()); // if driver spec'd and no serialized exception found if ((driver != null) && (thrown.equals(exception))) { // get browser log entries LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER); // for each log entry for (LogEntry logEntry : logEntries.filter(Level.WARNING)) { // extract serialized exception object from message thrown = extractException(exception, logEntry.getMessage()); // done if serialized exception found if (!thrown.equals(exception)) break; } } } // throw resolved exception as unchecked throw UncheckedThrow.throwUnchecked(thrown); }
Example #18
Source File: APPIUMCloudActionProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
@Override public String getLog( DeviceWebDriver webDriver ) { try { LogEntries logEntries = webDriver.manage().logs().get( "driver" ); if ( logEntries != null ) { StringBuilder logBuilder = new StringBuilder(); for ( LogEntry logEntry : logEntries ) logBuilder.append( dateFormat.format( new Date( logEntry.getTimestamp() ) ) ).append( ": " ).append( logEntry.getMessage() ).append( "\r\n" ); logBuilder.toString(); } return null; } catch ( Exception e ) { log.info( "Could not generate device logs" ); return null; } }
Example #19
Source File: BROWSERSTACKCloudActionProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
@Override public String getLog( DeviceWebDriver webDriver ) { try { LogEntries logEntries = webDriver.manage().logs().get( LogType.BROWSER ); if ( logEntries != null ) { StringBuilder logBuilder = new StringBuilder(); for ( LogEntry logEntry : logEntries ) logBuilder.append( dateFormat.format( new Date( logEntry.getTimestamp() ) ) ).append( ": " ).append( logEntry.getMessage() ).append( "\r\n" ); logBuilder.toString(); } return null; } catch ( Exception e ) { log.info( "Could not generate device logs" ); return null; } }
Example #20
Source File: SAUCELABSCloudActionProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
@Override public String getLog( DeviceWebDriver webDriver ) { try { LogEntries logEntries = webDriver.manage().logs().get( LogType.BROWSER ); if ( logEntries != null ) { StringBuilder logBuilder = new StringBuilder(); for ( LogEntry logEntry : logEntries ) logBuilder.append( dateFormat.format( new Date( logEntry.getTimestamp() ) ) ).append( ": " ).append( logEntry.getMessage() ).append( "\r\n" ); logBuilder.toString(); } return null; } catch ( Exception e ) { log.info( "Could not generate device logs" ); return null; } }
Example #21
Source File: SELENIUMCloudActionProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
@Override public String getLog( DeviceWebDriver webDriver ) { try { LogEntries logEntries = webDriver.manage().logs().get( LogType.BROWSER ); if ( logEntries != null ) { StringBuilder logBuilder = new StringBuilder(); for ( LogEntry logEntry : logEntries ) logBuilder.append( dateFormat.format( new Date( logEntry.getTimestamp() ) ) ).append( ": " ).append( logEntry.getMessage() ).append( "\r\n" ); return logBuilder.toString(); } return null; } catch ( Exception e ) { log.info( "Could not generate device logs" ); return null; } }
Example #22
Source File: LogEntryLogger.java From blueocean-plugin with MIT License | 6 votes |
private static void recordLogEntry(LogEntry entry) { String time; String level; String text; try { // handle messages written by @jenkins-cd/js-logging Map<String, Object> messageJson = jsonMapper.readValue(entry.getMessage(), typeRef); Map<String, Object> message = (Map<String, Object>) messageJson.get("message"); time = String.valueOf(message.get("timestamp")); level = String.valueOf(message.get("level")); text = String.valueOf(message.get("text")); } catch (IOException e) { // handle messages written natively by console.error|warn|log|debug time = String.valueOf(entry.getTimestamp()); level = String.valueOf(entry.getLevel()); text = entry.getMessage(); } logger.info(String.format("%s - %s - %s", time, level, text)); }
Example #23
Source File: SerializableLogEntries.java From gatf with Apache License 2.0 | 5 votes |
public SerializableLogEntries(List<LogEntry> entries) { List<SerializableLogEntry> mutableEntries = new ArrayList<SerializableLogEntry>(); for (LogEntry e : entries) { mutableEntries.add(new SerializableLogEntry(e.getLevel(), e.getTimestamp(), e.getMessage())); } this.entries = Collections.unmodifiableList(mutableEntries); }
Example #24
Source File: BrowserLogManager.java From vividus with Apache License 2.0 | 5 votes |
public static Set<LogEntry> getFilteredLog(WebDriver driver, Collection<BrowserLogLevel> logLevelsToInclude) { LogEntries log = getLog(driver); return logLevelsToInclude.stream() .map(BrowserLogLevel::getLevel) .flatMap(level -> filter(log, level)) .collect(Collectors.toCollection(LinkedHashSet::new)); }
Example #25
Source File: SeleniumProvider.java From enmasse with Apache License 2.0 | 5 votes |
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; }
Example #26
Source File: RemoteLogsTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void canGetClientLogs() { List<LogEntry> entries = new ArrayList<>(); entries.add(new LogEntry(Level.SEVERE, 0, "hello")); when(localLogs.get(LogType.CLIENT)).thenReturn(new LogEntries(entries)); LogEntries logEntries = remoteLogs.get(LogType.CLIENT); assertThat(logEntries.getAll()).hasSize(1); assertThat(logEntries.getAll().get(0).getMessage()).isEqualTo("hello"); // Client logs should not retrieve remote logs. verifyNoMoreInteractions(executeMethod); }
Example #27
Source File: PERFECTOCloudActionProvider.java From xframium-java with GNU General Public License v3.0 | 5 votes |
@Override public String getLog( DeviceWebDriver webDriver ) { if ( webDriver.getDevice().getOs().equalsIgnoreCase( "IOS" ) || webDriver.getDevice().getOs().equalsIgnoreCase( "ANDROID" ) ) { Map<String, Object> pars = new HashMap<>(); pars.put("tail", 1000); return (String) webDriver.executeScript("mobile:device:log", pars); } else { try { LogEntries logEntries = webDriver.manage().logs().get( LogType.BROWSER ); if ( logEntries != null ) { StringBuilder logBuilder = new StringBuilder(); for ( LogEntry logEntry : logEntries ) logBuilder.append( dateFormat.format( new Date( logEntry.getTimestamp() ) ) ).append( ": " ).append( logEntry.getMessage() ).append( "\r\n" ); return logBuilder.toString(); } return null; } catch ( Exception e ) { log.info( "Could not generate device logs", e ); return null; } } }
Example #28
Source File: PerSessionLogHandler.java From selenium with Apache License 2.0 | 5 votes |
/** * Returns the server log for the given session id. * * @param sessionId The session id. * @return The available server log entries for the session. * @throws IOException If there was a problem reading from file. */ public synchronized LogEntries getSessionLog(SessionId sessionId) throws IOException { List<LogEntry> entries = new ArrayList<>(); for (LogRecord record : records(sessionId)) { if (record.getLevel().intValue() >= serverLogLevel.intValue()) entries.add(new LogEntry(record.getLevel(), record.getMillis(), record.getMessage())); } return new LogEntries(entries); }
Example #29
Source File: ReportingWebDriverEventListener.java From dropwizard-experiment with MIT License | 5 votes |
private static void saveLogs(String filename, WebDriver driver) { StringBuffer logs = new StringBuffer(); for (LogEntry entry : driver.manage().logs().get(LogType.BROWSER)) { logs.append(Instant.ofEpochMilli(entry.getTimestamp())) .append(": ") .append(entry.getMessage()) .append("\n"); } try { Files.write(logs, new File(filename + ".txt"), Charsets.UTF_8); } catch (IOException e) { log.error("Unable to save logs from test failure.", e); } }
Example #30
Source File: WebDriverService.java From cerberus-source with GNU General Public License v3.0 | 5 votes |
@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; }