Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/io/appium/java_client/AppiumBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package io.appium.java_client;

import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.openqa.selenium.By;
import org.openqa.selenium.By.Remotable;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.json.Json;

import java.io.Serializable;
import java.util.HashMap;
Expand Down Expand Up @@ -383,7 +383,7 @@ protected FlutterBy(String selector, String locatorString, String locatorName) {
}

public abstract static class FlutterByHierarchy extends FlutterBy {
private static final Json JSON = new Json();
private static final Gson GSON = new Gson();

protected FlutterByHierarchy(
String selector,
Expand All @@ -404,7 +404,7 @@ static String formatLocator(FlutterBy of, FlutterBy matching, Map<String, Object
locator.put("of", parseFlutterLocator(of));
locator.put("matching", parseFlutterLocator(matching));
locator.put("parameters", properties);
return JSON.toJson(locator);
return GSON.toJson(locator);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/appium/java_client/LogsEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package io.appium.java_client;

import com.google.gson.Gson;
import io.appium.java_client.serverevents.CommandEvent;
import io.appium.java_client.serverevents.CustomEvent;
import io.appium.java_client.serverevents.ServerEvents;
import io.appium.java_client.serverevents.TimedEvent;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.Response;

import java.util.List;
Expand Down Expand Up @@ -52,7 +52,7 @@ default void logEvent(CustomEvent event) {
*/
default ServerEvents getEvents() {
Response response = execute(GET_EVENTS);
String jsonData = new Json().toJson(response.getValue());
String jsonData = new Gson().toJson(response.getValue());

//noinspection unchecked
Map<String, Object> value = (Map<String, Object>) response.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package io.appium.java_client.plugins.storage;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.ErrorCodec;
import org.openqa.selenium.remote.codec.AbstractHttpResponseCodec;
import org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec;
Expand All @@ -31,6 +32,7 @@
import org.openqa.selenium.remote.http.WebSocket;

import java.io.File;
import java.lang.reflect.Type;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -54,7 +56,8 @@
*/
public class StorageClient {
public static final String PREFIX = "/storage";
private final Json json = new Json();
private static final Type MAP_TYPE = new TypeToken<Map<String, Object>>() { }.getType();
private final Gson gson = new Gson();
private final AbstractHttpResponseCodec responseCodec = new W3CHttpResponseCodec();
private final ErrorCodec errorCodec = ErrorCodec.createDefault();

Expand Down Expand Up @@ -186,7 +189,7 @@ private static URL formatPath(URL url, String... suffixes) {
}

private HttpRequest setJsonPayload(HttpRequest request, Map<String, Object> payload) {
var strData = json.toJson(payload);
var strData = gson.toJson(payload);
var data = strData.getBytes(StandardCharsets.UTF_8);
request.setHeader(HttpHeader.ContentLength.getName(), String.valueOf(data.length));
request.setHeader(HttpHeader.ContentType.getName(), "application/json; charset=utf-8");
Expand Down Expand Up @@ -233,7 +236,7 @@ public void onError(Throwable cause) {

private Optional<WebDriverException> extractException(String payload) {
try {
Map<String, Object> record = json.toType(payload, Json.MAP_TYPE);
Map<String, Object> record = gson.fromJson(payload, MAP_TYPE);
//noinspection unchecked
var value = (Map<String, Object>) record.get("value");
if ((Boolean) value.get("success")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.appium.java_client;

import com.google.gson.Gson;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

class AppiumByFlutterHierarchyTest {

private final Gson gson = new Gson();

@Test
void flutterDescendantLocatorIsValidJsonWithExpectedShape() {
AppiumBy.FlutterBy of = AppiumBy.flutterType("myType");
AppiumBy.FlutterBy matching = AppiumBy.flutterText("myText");

String locatorString = (String) AppiumBy.flutterDescendant(of, matching, true, false)
.getRemoteParameters().value();

@SuppressWarnings("unchecked")
Map<String, Object> locator = gson.fromJson(locatorString, Map.class);
assertEquals(Map.of("using", "-flutter type", "value", "myType"), locator.get("of"));
assertEquals(Map.of("using", "-flutter text", "value", "myText"), locator.get("matching"));
assertEquals(Map.of("matchRoot", true, "skipOffstage", false), locator.get("parameters"));
}

@Test
void flutterAncestorLocatorIsValidJsonWithExpectedShape() {
AppiumBy.FlutterBy of = AppiumBy.flutterKey("myKey");
AppiumBy.FlutterBy matching = AppiumBy.flutterSemanticsLabel("myLabel");

String locatorString = (String) AppiumBy.flutterAncestor(of, matching, true).getRemoteParameters().value();

@SuppressWarnings("unchecked")
Map<String, Object> locator = gson.fromJson(locatorString, Map.class);
assertEquals(Map.of("using", "-flutter key", "value", "myKey"), locator.get("of"));
assertEquals(Map.of("using", "-flutter semantics label", "value", "myLabel"), locator.get("matching"));
assertEquals(Map.of("matchRoot", true), locator.get("parameters"));
}
}
Loading