APISonar


org.openqa.selenium.json.Json.Json

> org > openqa > selenium > json > Json > Json
org APIs openqa APIs selenium APIs json APIs Json APIs Json APIs

Example 1
public Map<?,?> getConfigurationForJMX() {
    Json json = new Json();
    return json.toType(json.toJson(config.toJson()), Map.class);
  }
Example 2
private Map<String, Object> getPayload(RemoteWebDriverBuilder builder) {
    Json json = new Json();

    try (Writer writer = new StringWriter();
         JsonOutput jsonOutput = json.newOutput(writer)) {
      builder.getPlan().writePayload(jsonOutput);

      return json.toType(writer.toString(), MAP_TYPE);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }
Example 3
public static FirefoxProfile fromJson(String json) throws IOException {
    // We used to just pass in the entire string without quotes. If we see that, we're good.
    // Otherwise, parse the json.

    if (json.trim().startsWith("\"")) {
      json = new Json().toType(json, String.class);
    }

    return new FirefoxProfile(Zip.unzipToTempDir(
        json,
        "webdriver",
        "duplicated"));
  }
Example 4
private Map<String, Object> invokeCommand(String method, Map<String, Object> params)
      throws IOException, ServletException {
    FakeHttpServletResponse fakeResponse = sendCommand(method, "/", params);
    Json json = new Json();
    JsonInput jin = json.newInput(new StringReader(fakeResponse.getBody()));
    return jin.read(Json.MAP_TYPE);
  }
Example 5
public void ensureIdIsSerializedProperly() {
    // Although it's not legal, make sure we handle the case where people use spaces.
    By by = By.id("one two");

    Json json = new Json();
    Map<String, Object> blob = json.toType(json.toJson(by), MAP_TYPE);

    assertThat(blob.get("using")).isEqualTo("css selector");
    assertThat(blob.get("value")).isEqualTo("#one #two");

  }
Example 6
private Map<String, Object> getRequestJSON(HttpServletRequest request) throws IOException {
    Json json = new Json();
    try (BufferedReader rd = new BufferedReader(new InputStreamReader(request.getInputStream()));
         JsonInput jin = json.newInput(rd)) {
      return jin.read(MAP_TYPE);
    } catch (JsonException e) {
      throw new IOException(e);
    }
  }
Example 7
public static NewSessionPayload create(Map<String, ?> source) {
    Objects.requireNonNull(source, "Payload must be set");

    String json = new Json().toJson(source);
    return new NewSessionPayload(new StringReader(json));
  }
Example 8
private static Map<String, Object> toMap(Object o) {
    String rawJson = new Json().toJson(o);
    return new Json().toType(rawJson, Map.class);
  }
Example 9
public void shouldUseLongestConstructor() {
    Json json = new Json();
    Proxy proxy = new Proxy();
    Injector injector = Injector.builder().register(json).register(proxy).build();

    MultipleConstructors instance = injector.newInstance(MultipleConstructors.class);

    assertSame(json, instance.json);
    assertSame(proxy, instance.proxy);
  }
Example 10
public static NewAppiumSessionPayload create(Capabilities caps) throws IOException {
        boolean forceMobileJSONWP =
                ofNullable(caps.getCapability(FORCE_MJSONWP))
                .map(o -> Boolean.class.isAssignableFrom(o.getClass()) && Boolean.class.cast(o))
                .orElse(false);

        HashMap<String, ?> capabilityMap = new HashMap<>(caps.asMap());
        capabilityMap.remove(FORCE_MJSONWP);
        Map<String, ?> source = of(DESIRED_CAPABILITIES, capabilityMap);
        String json = new Json().toJson(source);
        return new NewAppiumSessionPayload(new StringReader(json), forceMobileJSONWP);
    }
Example 11
public void rpcRequestDataInitializedWithDataAsAString() throws IOException {
    Map<String, Object> json = ImmutableMap.of("foo", "bar");
    HttpServletRequest mockRequest = createJsonRequest("GET", "/", json);

    CrossDomainRpc rpc = new CrossDomainRpcLoader().loadRpc(mockRequest);

    Object data = new Json().toType(rpc.getData(), MAP_TYPE);

    assertEquals(ImmutableMap.of("foo", "bar"), data);
  }
Example 12
public void shouldSurviveASerializationRoundTrip() {
    InternetExplorerOptions options = new InternetExplorerOptions()
        .withInitialBrowserUrl("http://www.cheese.com")
        .addCommandSwitches("--cake");

    String json = new Json().toJson(options);
    Capabilities capabilities = new Json().toType(json, Capabilities.class);

    assertThat(capabilities).isEqualTo(options);

    InternetExplorerOptions freshOptions = new InternetExplorerOptions(capabilities);

    assertThat(freshOptions).isEqualTo(options);
  }
Example 13
private Map<String, Object> getSessions(Hub hub) throws IOException {
    String url = String.format("http://%s:%d/grid/api/sessions", hub.getUrl().getHost(),
                               hub.getUrl().getPort());
    URL grid = new URL(url);
    URLConnection connection = grid.openConnection();
    try (InputStream in = connection.getInputStream();
         JsonInput input = new Json().newInput(new BufferedReader(new InputStreamReader(in)))) {
      return input.read(Json.MAP_TYPE);

    }
  }
Example 14
private static IDefaultProvider defaults(String json) {
    Map<String, Object> map = (Map<String, Object>) new Json().toType(json, Map.class);
    map.remove("custom");
    return optionName -> {
      String option = optionName.replaceAll("-", "");
      return map.containsKey(option) && map.get(option) != null ? map.get(option).toString() : null;
    };
  }
Example 15
public void shouldIndicateDownstreamW3cDialect() {
    Map<String, Map<String, Map<String, String>>> caps = singletonMap(
        "capabilities", singletonMap(
            "alwaysMatch", singletonMap(
                "browserName", "cheese")));

    try (NewSessionPayload payload = NewSessionPayload.create(caps)) {
      assertEquals(singleton(Dialect.W3C), payload.getDownstreamDialects());
    }

    String json = new Json().toJson(caps);
    try (NewSessionPayload payload = NewSessionPayload.create(new StringReader(json))) {
      assertEquals(singleton(Dialect.W3C), payload.getDownstreamDialects());
    }
  }
Example 16
protected static JsonInput loadJsonFromResourceOrFile(String resource) {
    try {
      return new Json().newInput(readFileOrResource(resource));
    } catch (RuntimeException e) {
      throw new GridConfigurationException("Unable to read input", e);
    }
  }
Example 17
public void doesNotForwardRequiredCapabilitiesAsTheseAreVeryLegacy() throws IOException {
    try (NewSessionPayload payload = NewSessionPayload.create(    ImmutableMap.of(
        "capabilities", ImmutableMap.of(),
        "requiredCapabilities", ImmutableMap.of("key", "so it's not empty")))) {
      StringBuilder toParse = new StringBuilder();
      payload.writeTo(toParse);
      Map<String, Object> seen = new Json().toType(toParse.toString(), MAP_TYPE);

      assertNull(seen.get("requiredCapabilities"));
    }
  }
Example 18
private HttpResponse createValidResponse(int statusCode, Map<String, ?> data) {
    byte[] contents = new Json().toJson(data).getBytes(UTF_8);

    HttpResponse response = new HttpResponse();
    response.setStatus(statusCode);
    response.addHeader("Content-Type", "application/json; charset=utf-8");
    response.addHeader("Cache-Control", "no-cache");
    response.addHeader("Content-Length", String.valueOf(contents.length));
    response.setContent(bytes(contents));

    return response;
  }
Example 19
private FakeHttpServletResponse sendCommand(
      String method,
      String commandPath,
      Map<String, Object> parameters) throws IOException, ServletException {
    FakeHttpServletRequest request = new FakeHttpServletRequest(method, createUrl(commandPath));
    if (parameters != null) {
      request.setBody(new Json().toJson(parameters));
    }

    FakeHttpServletResponse response = new FakeHttpServletResponse();

    driverServlet.service(request, response);
    return response;
  }
Example 20
private static JsonInput loadJsonFromResourceOrFile(String source) {
    try {
      return new Json().newInput(readFileOrResource(source));
    } catch (RuntimeException e) {
      throw new GridConfigurationException("Unable to load configuration from " + source, e);
    }
  }
Example 21
public void serialiazesAndDeserializesWithoutError() {
    Proxy proxy = new Proxy();
    proxy.setProxyAutoconfigUrl("http://www.example.com/config.pac");

    Capabilities caps = new ImmutableCapabilities(PROXY, proxy);

    String rawJson = new Json().toJson(caps);
    Capabilities converted = new Json().toType(rawJson, Capabilities.class);

    Object returnedProxy = converted.getCapability(PROXY);
    assertTrue(returnedProxy instanceof Proxy);
  }
Example 22
public void forwardsMetaDataAssociatedWithARequest() throws IOException {
    try (NewSessionPayload payload = NewSessionPayload.create(    ImmutableMap.of(
        "desiredCapabilities", EMPTY_MAP,
        "cloud:user", "bob",
        "cloud:key", "there is no cake"))) {
      StringBuilder toParse = new StringBuilder();
      payload.writeTo(toParse);
      Map<String, Object> seen = new Json().toType(toParse.toString(), MAP_TYPE);

      assertEquals("bob", seen.get("cloud:user"));
      assertEquals("there is no cake", seen.get("cloud:key"));
    }
  }
Example 23
public void testLoadFromJson() throws IOException {
    GridHubConfiguration ghc;

    try (Reader reader = new StringReader("{\"role\":\"hub\", \"host\":\"dummyhost\", \"port\":1234}");
        JsonInput jsonInput = new Json().newInput(reader)) {
          ghc = GridHubConfiguration.loadFromJSON(jsonInput);
    }

    assertEquals("hub", ghc.role);
    assertEquals(1234, ghc.port.intValue());
    assertEquals("dummyhost", ghc.host);
    assertEquals(-1, ghc.newSessionWaitTimeout.intValue());
  }
Example 24
public void shouldSendSimpleQueryParameters() throws Exception {
    HttpRequest request = new HttpRequest(GET, "/query");
    request.addQueryParameter("cheese", "cheddar");

    HttpResponse response = getQueryParameterResponse(request);
    Map<String, Object> values = new Json().toType(response.getContentString(), MAP_TYPE);

    assertEquals(ImmutableList.of("cheddar"), values.get("cheese"));
  }
Example 25
public SessionMap(Tracer tracer) {
    this.tracer = Objects.requireNonNull(tracer);

    Json json = new Json();
    routes = combine(
        post("/se/grid/session").to(() -> new AddToSessionMap(tracer, json, this)),
        Route.get("/se/grid/session/{sessionId}")
            .to(params -> new GetFromSessionMap(tracer, json, this, new SessionId(params.get("sessionId")))),
        delete("/se/grid/session/{sessionId}")
            .to(params -> new RemoveFromSession(tracer, this, new SessionId(params.get("sessionId")))));
  }