Java 类org.openqa.selenium.remote.server.log.LoggingManager 实例源码

项目:grid-refactor-remote-server    文件:NewSession.java   
@Override
public Response handle() throws Exception {
  // Handle the case where the client does not send any desired capabilities.
  sessionId = allSessions.newSession(desiredCapabilities != null
                                     ? desiredCapabilities : new DesiredCapabilities());

  Map<String, Object> capabilities =
      Maps.newHashMap(allSessions.get(sessionId).getCapabilities().asMap());

  // Only servers implementing the server-side webdriver-backed selenium need
  // to return this particular value
  capabilities.put("webdriver.remote.sessionid", sessionId.toString());

  if (desiredCapabilities != null) {
    LoggingManager.perSessionLogHandler().configureLogging(
        (LoggingPreferences)desiredCapabilities.getCapability(CapabilityType.LOGGING_PREFS));
  }
  LoggingManager.perSessionLogHandler().attachToCurrentThread(sessionId);

  Response response = new Response();
  response.setSessionId(sessionId.toString());
  response.setValue(capabilities);
  return response;
}
项目:grid-refactor-remote-server    文件:DeleteSession.java   
@Override
public Void call() throws Exception {

  WebDriver driver = getDriver();
  if (driver == null) {
    return null;
  }

  try {
    LoggingManager.perSessionLogHandler().fetchAndStoreLogsFromDriver(getSessionId(), driver);
  } catch (Throwable ignored) {
    // A failure to retrieve logs should not cause a test to fail.
    // Silently ignore this exception.
  }

  driver.quit();

  // Yes, this is funky. See javadocs on PerSessionLogHandler#clearThreadTempLogs for details.
  final PerSessionLogHandler logHandler = LoggingManager.perSessionLogHandler();
    /*
        We may be storing logging information on 2 different threads, the servlet container
        thread and the thread executing commands
        All this ugliness would go away if we just handled create and delete of sessions fully
        inside ResultConfig because then we could avoid switching threads and there will
        not be logevents that do not have a session present
        Additionally; if we ever get non-session bound logging here, it will come in
        the incorrect order. But that should only happen on create/delete, right ?
     */
  logHandler.transferThreadTempLogsToSessionLogs(getSessionId());
  return null;
}
项目:grid-refactor-remote-server    文件:GetSessionLogsHandler.java   
@Override
public Map<String, SessionLogs> handle() throws Exception {
  ImmutableMap.Builder<String, SessionLogs> builder =
      ImmutableMap.<String, SessionLogs>builder();
  for (SessionId sessionId : LoggingManager.perSessionLogHandler().getLoggedSessions()) {
    builder.put(sessionId.toString(),
        LoggingManager.perSessionLogHandler().getAllLogsForSession(sessionId));
  }
  return builder.build();
}
项目:grid-refactor-remote-server    文件:GetLogHandler.java   
@Override
public LogEntries call() throws Exception {
  if (LogType.SERVER.equals(type)) {
    return LoggingManager.perSessionLogHandler().getSessionLog(getSessionId());
  } else {
    return getDriver().manage().logs().get(type);
  }
}
项目:grid-refactor-remote-server    文件:SessionCleaner.java   
void checkExpiry() {
  for (SessionId sessionId : driverSessions.getSessions()) {
    Session session = driverSessions.get(sessionId);
    if (session != null) {
      boolean useDeleteSession = false;
      boolean killed = false;

      boolean inUse = session.isInUse();
      if (!inUse && session.isTimedOut(clientGoneTimeout)) {
        useDeleteSession = true;
        log.info("Session " + session.getSessionId() + " deleted due to client timeout");
      }
      if (inUse && session.isTimedOut(insideBrowserTimeout)) {
        WebDriver driver = session.getDriver();
        if (driver instanceof EventFiringWebDriver){
          driver = ((EventFiringWebDriver)driver).getWrappedDriver();
        }
        if (driver instanceof Killable) {
          //session.interrupt();
          ((Killable) driver).kill();
          killed = true;
          log.warning("Browser killed and session " + session.getSessionId() + " terminated due to in-browser timeout.");
        } else {
          useDeleteSession = true;
          log.warning("Session " + session.getSessionId() + " deleted due to in-browser timeout. " +
                      "Terminating driver with DeleteSession since it does not support Killable, "
                      + "the driver in question does not support selenium-server timeouts fully");
        }
      }

      if (useDeleteSession) {
        DeleteSession deleteSession = new DeleteSession(session);
        try {
          deleteSession.call();
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }

      if (useDeleteSession || killed) {
        driverSessions.deleteSession(sessionId);
        final PerSessionLogHandler logHandler = LoggingManager.perSessionLogHandler();
        logHandler.transferThreadTempLogsToSessionLogs(sessionId);
        logHandler.removeSessionLogs(sessionId);
      }
    }
  }
}