/*
   * (non-Javadoc)
   *
   * @see org.uiautomation.ios.server.command.Handler#handle()
   */
  @Override
  public Response handle() throws Exception {
    JSONObject res = new JSONObject();

    res.put(
        "os",
        new JSONObject()
            .put("name", System.getProperty("os.name"))
            .put("arch", System.getProperty("os.arch"))
            .put("version", System.getProperty("os.version")));

    res.put("java", new JSONObject().put("version", System.getProperty("java.version")));

    res.put("ios", new JSONObject().put("simulatorVersion", ClassicCommands.getDefaultSDK()));

    JSONArray supportedApps = new JSONArray();
    for (IOSApplication a : getDriver().getSupportedApplications()) {
      JSONObject app = new JSONObject();

      JSONObject resources = new JSONObject();
      for (String key : a.getResources().keySet()) {
        resources.put(key, "/wd/hub/resources/" + getDriver().getCache().getKey(a, key));
      }
      app.put("resources", resources);

      Map<String, Object> capabilities = getDriver().getCapabilities(a).getRawCapabilities();
      for (String key : capabilities.keySet()) {
        app.put(key, capabilities.get(key));
      }
      supportedApps.put(app);
    }

    res.put("supportedApps", supportedApps);

    res.put(
        "build",
        new JSONObject()
            .put("version", BuildInfo.getAttribute("version"))
            .put("time", BuildInfo.getAttribute("buildTimestamp"))
            .put("revision", BuildInfo.getAttribute("sha")));

    List<ServerSideSession> sessions = getDriver().getSessions();
    Response resp = new Response();

    resp.setStatus(0);
    resp.setValue(res);
    if (sessions.size() == 0) {
      resp.setSessionId(null);
    } else if (sessions.size() == 1) {
      resp.setSessionId(sessions.get(0).getSessionId());
    } else {
      throw new WebDriverException("NI multi sessions per server.");
    }
    return resp;
  }
Beispiel #2
0
  @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;
  }
Beispiel #3
0
  @Override
  public Response handle() throws Exception {
    boolean useNativeEvents = getConfiguration("nativeEvents", nativeEvents);

    if (useNativeEvents) {
      // backNative();
    } else {
      backWeb();
    }
    getSession().getRemoteWebDriver().getContext().newContext();
    getSession().getRemoteWebDriver().waitForPageToLoad();
    Response resp = new Response();
    resp.setSessionId(getSession().getSessionId());
    resp.setStatus(0);
    resp.setValue(new JSONObject());
    return resp;
  }
  @Override
  public Response handle() throws Exception {
    JSONObject payload = getRequest().getPayload();

    String type = payload.getString("using");
    String value = payload.getString("value");

    RemoteWebElement element = null;

    if (getRequest().hasVariable(":reference")) {
      int id = Integer.parseInt(getRequest().getVariableValue(":reference"));
      element = new RemoteWebElement(new NodeId(id), getSession());
    } else {
      element = getSession().getWebInspector().getDocument();
    }

    List<RemoteWebElement> res;
    if ("link text".equals(type)) {
      res = element.findElementsByLinkText(value, false);
    } else if ("partial link text".equals(type)) {
      res = element.findElementsByLinkText(value, true);
    } else if ("xpath".equals(type)) {
      res = element.findElementsByXpath(value);
    } else {
      String cssSelector = ToCSSSelectorConvertor.convertToCSSSelector(type, value);
      res = element.findElementsByCSSSelector(cssSelector);
    }

    JSONArray array = new JSONArray();

    List<JSONObject> list = new ArrayList<JSONObject>();
    for (RemoteWebElement el : res) {
      list.add(new JSONObject().put("ELEMENT", "" + el.getNodeId().getId()));
    }

    Response resp = new Response();
    resp.setSessionId(getSession().getSessionId());
    resp.setStatus(0);
    resp.setValue(list);
    return resp;
  }
  @Override
  public Response handle() throws Exception {
    JSONArray res = new JSONArray();

    List<ServerSideSession> sessions = getDriver().getSessions();

    for (ServerSideSession s : sessions) {
      JSONObject session = new JSONObject();
      session.put("id", s.getSessionId());

      IOSApplication app = s.getApplication();
      IOSCapabilities cap = getDriver().getCapabilities(app);
      session.put("capabilities", cap.getRawCapabilities());
      res.put(session);
    }
    Response resp = new Response();
    resp.setSessionId("dummy one");
    resp.setStatus(0);
    resp.setValue(res.toString());
    return resp;
  }