Java Code Examples for org.openqa.selenium.logging.LogEntries#getAll()

The following examples show how to use org.openqa.selenium.logging.LogEntries#getAll() . 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 vote down vote up
/**
 * @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: ConsoleTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @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 3
Source File: ConsoleTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @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 4
Source File: ConsoleTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @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 5
Source File: ConsoleTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @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 6
Source File: RemoteLogsTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@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: RemoteLogsTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: ConsoleTest.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void simpleString() throws Exception {
    final String html
        = "<html>\n"
        + "<body>\n"
        + "<script>\n"
        + "  for (i = 0; i < 4; i++) {\n"
        + "    console.log('test log ' + i);\n"
        + "  }\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();

    final int count = logEntryList.size();
    assertTrue(count > 0);

    long timestamp = 0;
    for (int i = 0; i < 4; i++) {
        final LogEntry logEntry = logEntryList.get(i);
        assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("test log " + i));
        assertTrue(logEntry.getTimestamp() >= timestamp);
        timestamp = logEntry.getTimestamp();
    }
}
 
Example 9
Source File: JavaDriverLogsTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void loggingWorks() {
    LoggingPreferences prefs = new LoggingPreferences();
    prefs.enable(LogType.DRIVER, Level.INFO);
    DesiredCapabilities caps = JavaDriver.defaultCapabilities();
    caps.setCapability(CapabilityType.LOGGING_PREFS, prefs);
    driver = new JavaDriver(caps, caps);
    LogEntries logEntries = driver.manage().logs().get(LogType.DRIVER);
    List<LogEntry> all = logEntries.getAll();
    AssertJUnit.assertTrue(all.get(0).getMessage().contains("A new session created. sessionID = "));
}
 
Example 10
Source File: JavaDriverLogsTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void loglevelsAreRespected() {
    LoggingPreferences prefs = new LoggingPreferences();
    prefs.enable(LogType.DRIVER, Level.WARNING);
    DesiredCapabilities caps = JavaDriver.defaultCapabilities();
    caps.setCapability(CapabilityType.LOGGING_PREFS, prefs);
    driver = new JavaDriver(caps, caps);
    LogEntries logEntries = driver.manage().logs().get(LogType.DRIVER);
    List<LogEntry> all = logEntries.getAll();
    AssertJUnit.assertEquals(0, all.size());
}