/*
   * (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;
  }
  @Test
  public void roundTrip() throws JSONException {
    Response response = new Response();
    response.setStatus(ErrorCodes.SUCCESS);
    response.setValue(ImmutableMap.of("color", "red"));

    HttpResponse httpResponse = codec.encode(response);
    Response decoded = codec.decode(httpResponse);

    assertEquals(response.getStatus(), decoded.getStatus());
    assertEquals(response.getSessionId(), decoded.getSessionId());
    assertEquals(response.getValue(), decoded.getValue());
  }
  @Test
  public void decodeJsonResponseMissingContentType() throws JSONException {
    Response response = new Response();
    response.setStatus(ErrorCodes.ASYNC_SCRIPT_TIMEOUT);
    response.setValue(ImmutableMap.of("color", "red"));

    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatus(HTTP_OK);
    httpResponse.setContent(new BeanToJsonConverter().convert(response).getBytes(UTF_8));

    Response decoded = codec.decode(httpResponse);
    assertEquals(response.getStatus(), decoded.getStatus());
    assertEquals(response.getSessionId(), decoded.getSessionId());
    assertEquals(response.getValue(), decoded.getValue());
  }
예제 #4
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;
  }
  @Test
  public void convertsResponses_failure() throws JSONException {
    Response response = new Response();
    response.setStatus(ErrorCodes.NO_SUCH_ELEMENT);
    response.setValue(ImmutableMap.of("color", "red"));

    HttpResponse converted = codec.encode(response);
    assertThat(converted.getStatus(), is(HTTP_INTERNAL_ERROR));
    assertThat(converted.getHeader(CONTENT_TYPE), is(JSON_UTF_8.toString()));

    Response rebuilt =
        new JsonToBeanConverter()
            .convert(Response.class, new String(converted.getContent(), UTF_8));

    assertEquals(response.getStatus(), rebuilt.getStatus());
    assertEquals(response.getState(), rebuilt.getState());
    assertEquals(response.getSessionId(), rebuilt.getSessionId());
    assertEquals(response.getValue(), rebuilt.getValue());
  }
예제 #6
0
  @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;
  }