public void reset(String baseUrl) {
   LOGGER.debug("resetting frame group");
   if (proxyInjectionMode) {
     // shut down all but the primary top level connection
     List<FrameAddress> newOrphans = new LinkedList<FrameAddress>();
     for (String uniqueId : uniqueIdToCommandQueue.keySet()) {
       CommandQueue q = getCommandQueue(uniqueId);
       FrameAddress frameAddress = q.getFrameAddress();
       if (frameAddress.getLocalFrameAddress().equals(DEFAULT_LOCAL_FRAME_ADDRESS)
           && frameAddress.getWindowName().equals(DEFAULT_SELENIUM_WINDOW_NAME)) {
         continue;
       }
       if (frameAddress.getLocalFrameAddress().equals(DEFAULT_LOCAL_FRAME_ADDRESS)) {
         if (LOGGER.isDebugEnabled()) {
           LOGGER.debug("Trying to close " + frameAddress);
         }
         try {
           q.doCommandWithoutWaitingForAResponse("close", "", "");
         } catch (WindowClosedException e) {
           LOGGER.debug("Window was already closed");
         }
       }
       orphanedQueues.add(q);
       newOrphans.add(frameAddress);
     }
     for (FrameAddress frameAddress : newOrphans) {
       uniqueIdToCommandQueue.remove(frameAddress);
     }
   }
   removeTemporaryFiles();
   selectWindow(DEFAULT_SELENIUM_WINDOW_NAME);
   // String defaultUrl = "http://localhost:"
   StringBuilder openUrl = new StringBuilder();
   if (proxyInjectionMode) {
     openUrl.append("http://localhost:");
     openUrl.append(portDriversShouldContact);
     openUrl.append("/selenium-server/core/InjectedRemoteRunner.html");
   } else {
     openUrl.append(LauncherUtils.stripStartURL(baseUrl));
   }
   try {
     doCommand("open", openUrl.toString(), ""); // will close out subframes
   } catch (RemoteCommandException rce) {
     LOGGER.debug("RemoteCommandException in reset: " + rce.getMessage());
   }
 }
  /**
   * Creates and tries to open a new session.
   *
   * @param browserString
   * @param startURL
   * @param extensionJs
   * @param configuration Remote Control configuration. Cannot be null.
   * @param ensureClean if a clean session is required
   * @return the BrowserSessionInfo of the new session.
   * @throws RemoteCommandException if the browser failed to launch and request work in the required
   *     amount of time.
   */
  protected BrowserSessionInfo createNewRemoteSession(
      String browserString,
      String startURL,
      String extensionJs,
      Capabilities browserConfiguration,
      boolean ensureClean,
      RemoteControlConfiguration configuration)
      throws RemoteCommandException {

    final FrameGroupCommandQueueSet queueSet;
    final BrowserSessionInfo sessionInfo;
    final BrowserLauncher launcher;
    String sessionId;

    sessionId = UUID.randomUUID().toString().replace("-", "");
    if ("*webdriver".equals(browserString) && browserConfiguration != null) {
      Object id = browserConfiguration.getCapability("webdriver.remote.sessionid");
      if (id != null && id instanceof String) {
        sessionId = (String) id;
      }
    }

    queueSet = makeQueueSet(sessionId, configuration.getPortDriversShouldContact(), configuration);
    queueSet.setExtensionJs(extensionJs);

    try {
      launcher =
          browserLauncherFactory.getBrowserLauncher(
              browserString, sessionId, configuration, browserConfiguration);
    } catch (InvalidBrowserExecutableException e) {
      throw new RemoteCommandException(e.getMessage(), "");
    }

    sessionInfo = new BrowserSessionInfo(sessionId, browserString, startURL, launcher, queueSet);
    SessionIdTracker.setLastSessionId(sessionId);
    log.info("Allocated session " + sessionId + " for " + startURL + ", launching...");

    final PerSessionLogHandler perSessionLogHandler = LoggingManager.perSessionLogHandler();
    perSessionLogHandler.attachToCurrentThread(new SessionId(sessionId));
    try {
      launcher.launchRemoteSession(startURL);
      queueSet.waitForLoad(configuration.getTimeoutInSeconds() * 1000l);

      // TODO DGF log4j only
      // NDC.push("sessionId="+sessionId);
      FrameGroupCommandQueueSet queue = getQueueSet(sessionId);
      queue.doCommand("setContext", sessionId, "");

      activeSessions.add(sessionInfo);
      return sessionInfo;
    } catch (Exception e) {
      /*
       * At this point the session might not have been added to neither available nor active
       * sessions. This session is unlikely to be of any practical use so we need to make sure we
       * close the browser and clear all session data.
       */
      log.log(
          Level.SEVERE,
          "Failed to start new browser session, shutdown browser and clear all session data",
          e);
      shutdownBrowserAndClearSessionData(sessionInfo);
      throw new RemoteCommandException("Error while launching browser", "", e);
    } finally {
      perSessionLogHandler.detachFromCurrentThread();
    }
  }