From 2150ca6207a8eb854236ca152c50d840832c7b39 Mon Sep 17 00:00:00 2001 From: Valery Yatsynovich Date: Wed, 27 Mar 2024 18:08:32 +0200 Subject: [PATCH] chore: Bump minimum Selenium version to `4.19.0` --- README.md | 1 + gradle.properties | 2 +- .../remote/AppiumProtocolHandshake.java | 50 ++++++------------- 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index a20c5218e..b0ee499da 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ dependencies { ### Compatibility Matrix Appium Java Client | Selenium client ---------------------------|----------------- + | `4.19.0` `9.1.0`, `9.2.0` | `4.17.0`, `4.18.0`, `4.18.1` `9.0.0` | `4.14.1`, `4.15.0`, `4.16.0` (partially [corrupted](https://github.com/SeleniumHQ/selenium/issues/13256)), `4.16.1` N/A | `4.14.0` diff --git a/gradle.properties b/gradle.properties index fb33c2c1a..306b374dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.daemon=true -selenium.version=4.17.0 +selenium.version=4.19.0 # Please increment the value in a release appiumClient.version=9.2.0 diff --git a/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java b/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java index 0f42b9a51..f92a3632d 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java +++ b/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java @@ -16,8 +16,6 @@ package io.appium.java_client.remote; -import com.google.common.io.CountingOutputStream; -import com.google.common.io.FileBackedOutputStream; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ImmutableCapabilities; import org.openqa.selenium.SessionNotCreatedException; @@ -28,21 +26,17 @@ import org.openqa.selenium.remote.Command; import org.openqa.selenium.remote.NewSessionPayload; import org.openqa.selenium.remote.ProtocolHandshake; +import org.openqa.selenium.remote.http.Contents; import org.openqa.selenium.remote.http.HttpHandler; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; +import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map; import java.util.Set; -import java.util.function.Supplier; import java.util.stream.Stream; -import static java.nio.charset.StandardCharsets.UTF_8; - @SuppressWarnings("UnstableApiUsage") public class AppiumProtocolHandshake extends ProtocolHandshake { private static void writeJsonPayload(NewSessionPayload srcPayload, Appendable destination) { @@ -108,34 +102,22 @@ public Result createSession(HttpHandler client, Command command) throws IOExcept } @Override - public Either createSession( - HttpHandler client, NewSessionPayload payload) throws IOException { - int threshold = (int) Math.min(Runtime.getRuntime().freeMemory() / 10, Integer.MAX_VALUE); - FileBackedOutputStream os = new FileBackedOutputStream(threshold, true); + public Either createSession(HttpHandler client, NewSessionPayload payload) { - try (CountingOutputStream counter = new CountingOutputStream(os); - Writer writer = new OutputStreamWriter(counter, UTF_8)) { - writeJsonPayload(payload, writer); + StringWriter stringWriter = new StringWriter(); + writeJsonPayload(payload, stringWriter); - Supplier contentSupplier = () -> { - try { - return os.asByteSource().openBufferedStream(); - } catch (IOException e) { - throw new RuntimeException(e); - } - }; - try { - Method createSessionMethod = ProtocolHandshake.class.getDeclaredMethod( - "createSession", HttpHandler.class, Supplier.class, long.class - ); - createSessionMethod.setAccessible(true); - //noinspection unchecked - return (Either) createSessionMethod.invoke( - this, client, contentSupplier, counter.getCount() - ); - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - throw new WebDriverException(e); - } + try { + Method createSessionMethod = ProtocolHandshake.class.getDeclaredMethod( + "createSession", HttpHandler.class, Contents.Supplier.class + ); + createSessionMethod.setAccessible(true); + //noinspection unchecked + return (Either) createSessionMethod.invoke( + this, client, Contents.utf8String(stringWriter.toString()) + ); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new WebDriverException(e); } } }