diff --git a/gradle.properties b/gradle.properties index e23c7abf2..633c79fd6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.daemon=true -selenium.version=4.5.0 +selenium.version=4.7.0 # Please increment the value in a release appiumClient.version=8.2.1 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 98b128554..0f42b9a51 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java +++ b/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java @@ -30,7 +30,6 @@ import org.openqa.selenium.remote.ProtocolHandshake; import org.openqa.selenium.remote.http.HttpHandler; -import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; @@ -39,6 +38,7 @@ 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; @@ -62,7 +62,7 @@ private static void writeJsonPayload(NewSessionPayload srcPayload, Appendable de try { Method getW3CMethod = NewSessionPayload.class.getDeclaredMethod("getW3C"); getW3CMethod.setAccessible(true); - //noinspection unchecked + //noinspection unchecked,resource ((Stream>) getW3CMethod.invoke(srcPayload)) .findFirst() .map(json::write) @@ -111,26 +111,31 @@ public Result createSession(HttpHandler client, Command command) throws IOExcept 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); + FileBackedOutputStream os = new FileBackedOutputStream(threshold, true); try (CountingOutputStream counter = new CountingOutputStream(os); Writer writer = new OutputStreamWriter(counter, UTF_8)) { writeJsonPayload(payload, writer); - try (InputStream rawIn = os.asByteSource().openBufferedStream(); - BufferedInputStream contentStream = new BufferedInputStream(rawIn)) { - Method createSessionMethod = ProtocolHandshake.class.getDeclaredMethod("createSession", - HttpHandler.class, InputStream.class, long.class); + 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, contentStream, counter.getCount() + this, client, contentSupplier, counter.getCount() ); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new WebDriverException(e); } - } finally { - os.reset(); } } } diff --git a/src/main/java/io/appium/java_client/remote/SupportsRotation.java b/src/main/java/io/appium/java_client/remote/SupportsRotation.java index 8ac22a707..6e1af3a58 100644 --- a/src/main/java/io/appium/java_client/remote/SupportsRotation.java +++ b/src/main/java/io/appium/java_client/remote/SupportsRotation.java @@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableMap; import io.appium.java_client.ExecutesMethod; import org.openqa.selenium.DeviceRotation; -import org.openqa.selenium.Rotatable; import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DriverCommand; @@ -27,7 +26,7 @@ import java.util.Map; -public interface SupportsRotation extends WebDriver, ExecutesMethod, Rotatable { +public interface SupportsRotation extends WebDriver, ExecutesMethod { /** * Get device rotation. * diff --git a/src/test/java/io/appium/java_client/events/stubs/EmptyWebDriver.java b/src/test/java/io/appium/java_client/events/stubs/EmptyWebDriver.java index 01104b988..9b6af0820 100644 --- a/src/test/java/io/appium/java_client/events/stubs/EmptyWebDriver.java +++ b/src/test/java/io/appium/java_client/events/stubs/EmptyWebDriver.java @@ -22,13 +22,10 @@ import org.openqa.selenium.Capabilities; import org.openqa.selenium.ContextAware; import org.openqa.selenium.Cookie; -import org.openqa.selenium.DeviceRotation; import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.OutputType; -import org.openqa.selenium.Rotatable; -import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; @@ -43,7 +40,7 @@ import java.util.Map; import java.util.Set; -public class EmptyWebDriver implements WebDriver, ContextAware, Rotatable, +public class EmptyWebDriver implements WebDriver, ContextAware, JavascriptExecutor, HasCapabilities, TakesScreenshot { public EmptyWebDriver() { } @@ -64,20 +61,6 @@ public String getContext() { return ""; } - public void rotate(ScreenOrientation orientation) { - } - - public void rotate(DeviceRotation rotation) { - } - - public ScreenOrientation getOrientation() { - return null; - } - - public DeviceRotation rotation() { - return null; - } - public void get(String url) { }