Example usage for org.openqa.selenium.logging LogEntries iterator

List of usage examples for org.openqa.selenium.logging LogEntries iterator

Introduction

In this page you can find the example usage for org.openqa.selenium.logging LogEntries iterator.

Prototype

@Override
    public Iterator<LogEntry> iterator() 

Source Link

Usage

From source file:io.ddavison.conductor.LoggingTest.java

License:Open Source License

@Test
public void loggingTest() {
    LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
    Iterator<LogEntry> it = logEntries.iterator();
    assertNotNull(it);/*from w w  w  . j a  v a2  s . c o m*/
    assertNotNull(it.hasNext());
    LogEntry entry = null;

    // There should be 5 console-outputs
    // 1. "console.log("Simple log");"
    assertNotNull(it.hasNext());
    entry = it.next();
    System.out.println(entry);
    assertEquals(Level.INFO, entry.getLevel());
    assertTrue(entry.getMessage().endsWith("Simple log"));

    // 2. "console.debug("Debug log");"
    assertNotNull(it.hasNext());
    entry = it.next();
    System.out.println(entry);
    assertEquals(Level.FINE, entry.getLevel());
    assertTrue(entry.getMessage().endsWith("Debug log"));

    // 3. "console.warn("Warn log");"
    assertNotNull(it.hasNext());
    entry = it.next();
    System.out.println(entry);
    assertEquals(Level.WARNING, entry.getLevel());
    assertTrue(entry.getMessage().endsWith("Warn log"));

    // 4. "console.error("Error log");"
    assertNotNull(it.hasNext());
    entry = it.next();
    System.out.println(entry);
    assertEquals(Level.SEVERE, entry.getLevel());
    assertTrue(entry.getMessage().endsWith("Error log"));

    // 5. "console.info("Info log");"
    assertNotNull(it.hasNext());
    entry = it.next();
    System.out.println(entry);
    assertEquals(Level.INFO, entry.getLevel());
    assertTrue(entry.getMessage().endsWith("Info log"));
}

From source file:org.jitsi.meet.test.FailureListener.java

License:Apache License

/**
 * Saves browser console logs./*from  w  w w  . j a  va 2 s.c  o m*/
 */
private void saveBrowserLogs(WebDriver driver, String fileNamePrefix, String suffix, String extension) {
    try {
        LogEntries logs = driver.manage().logs().get(LogType.BROWSER);

        BufferedWriter out = new BufferedWriter(new FileWriter(
                new File(outputLogsParentFolder, fileNamePrefix + suffix + "-driver" + extension)));

        Iterator<LogEntry> iter = logs.iterator();
        while (iter.hasNext()) {
            LogEntry e = iter.next();

            out.write(e.toString());
            out.newLine();
            out.newLine();
        }
        out.flush();
        out.close();

        if (ConferenceFixture.getBrowserType(driver) == ConferenceFixture.BrowserType.chrome) {
            FileUtils.copyFile(new File(outputLogsParentFolder, "chrome" + suffix + ".log"),
                    new File(outputLogsParentFolder, fileNamePrefix + suffix + "-chrome" + extension));
        }
    } catch (IOException e) {
        // cannot create file or something
    }
}