Ejemplo n.º 1
0
 public void run() {
   try {
     String startURL =
         "http://localhost:"
             + configuration.getPortDriversShouldContact()
             + "/selenium-server/driver/?sessionId="
             + sessionId
             + "&uniqueId="
             + uniqueId;
     String commandLine =
         doBrowserRequest(
             startURL + "&seleniumStart=true&sequenceNumber=" + sequenceNumber++, "START");
     while (!interrupted) {
       log.info("MOCK: " + commandLine);
       RemoteCommand sc = DefaultRemoteCommand.parse(commandLine);
       String result = doCommand(sc);
       if (browserOptions.is("browserSideLog") && !interrupted) {
         for (int i = 0; i < 3; i++) {
           doBrowserRequest(
               startURL + "&logging=true&sequenceNumber=" + sequenceNumber++,
               "logLevel=debug:dummy log message " + i + "\n");
         }
       }
       if (!interrupted) {
         commandLine = doBrowserRequest(startURL + "&sequenceNumber=" + sequenceNumber++, result);
       }
     }
     log.info("MOCK: interrupted, exiting");
   } catch (Exception e) {
     RuntimeException re = new RuntimeException("Exception in mock browser", e);
     re.printStackTrace();
     throw re;
   }
 }
Ejemplo n.º 2
0
  /**
   * 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();
    }
  }
Ejemplo n.º 3
0
 /**
  * Isolated dependency
  *
  * @param sessionId
  * @param port
  * @param configuration
  * @return a new FrameGroupCommandQueueSet instance
  */
 protected FrameGroupCommandQueueSet makeQueueSet(
     String sessionId, int port, RemoteControlConfiguration configuration) {
   return FrameGroupCommandQueueSet.makeQueueSet(
       sessionId, configuration.getPortDriversShouldContact(), configuration);
 }