public SimulatorSession(ResponseFinder... finders) {
   connectionKey = UUID.randomUUID().toString();
   simulatorProtocol = new SimulatorProtocolImpl(new DefaultMessageListener(this), finders);
   simulatorProtocol.sendSetConnectionKey(connectionKey);
   waitForSimToRegister();
   waitForSimToSendApps();
 }
  public BaseWebInspector connect(WebkitPage webkitPage, ServerSideSession session) {
    for (WebkitPage page : getPages()) {
      if (page.equals(webkitPage)) {
        WebInspector inspector =
            new WebInspector(
                null, webkitPage.getPageId(), simulatorProtocol, bundleId, connectionKey, session);
        // TODO move to webinspector
        simulatorProtocol.sendSetConnectionKey(connectionKey);
        simulatorProtocol.sendConnectToApplication(connectionKey, bundleId);
        simulatorProtocol.sendSenderKey(
            connectionKey, bundleId, inspector.getSenderKey(), "" + page.getPageId());
        inspector.sendCommand(Page.enablePageEvent());

        boolean ok = created.add(inspector);
        if (ok) {
          simulatorProtocol.addListener(inspector);
        }
        return inspector;
      }
    }
    throw new WebDriverException("Cannot connect to page " + webkitPage + ".Cannot find it.");
  }
 public void connect(String bundleId) {
   List<WebkitApplication> knownApps = getApplications();
   for (WebkitApplication app : knownApps) {
     if (bundleId.equals(app.getBundleId())) {
       this.bundleId = bundleId;
       simulatorProtocol.sendConnectToApplication(connectionKey, bundleId);
       waitForSimToSendPages();
       return;
     }
   }
   throw new WebDriverException(
       bundleId
           + " not in the list "
           + knownApps
           + ".Either it's not started, or it has no webview to connect to.");
 }
 public void stop() {
   simulatorProtocol.stop();
 }