From bc6e127995e0461f8dd9241b111fa6f1553ec3f9 Mon Sep 17 00:00:00 2001 From: Valery Yatsynovich Date: Sun, 7 Jan 2024 21:37:49 +0200 Subject: [PATCH] chore: Add non-W3C endpoints remove from Selenium client --- .../io/appium/java_client/MobileCommand.java | 18 ++++++++++++++++++ .../remote/SupportsContextSwitching.java | 8 ++++---- .../java_client/remote/SupportsRotation.java | 10 +++++----- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index ee08c289a..15704ec40 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -178,6 +178,15 @@ public class MobileCommand { protected static final String GET_ALLSESSION; protected static final String EXECUTE_GOOGLE_CDP_COMMAND; + public static final String GET_SCREEN_ORIENTATION = "getScreenOrientation"; + public static final String SET_SCREEN_ORIENTATION = "setScreenOrientation"; + public static final String GET_SCREEN_ROTATION = "getScreenRotation"; + public static final String SET_SCREEN_ROTATION = "setScreenRotation"; + + public static final String GET_CONTEXT_HANDLES = "getContextHandles"; + public static final String GET_CURRENT_CONTEXT_HANDLE = "getCurrentContextHandle"; + public static final String SWITCH_TO_CONTEXT = "switchToContext"; + public static final Map commandRepository; static { @@ -347,6 +356,15 @@ public class MobileCommand { commandRepository.put(EXECUTE_DRIVER_SCRIPT, postC("/session/:sessionId/appium/execute_driver")); commandRepository.put(GET_ALLSESSION, getC("/sessions")); commandRepository.put(EXECUTE_GOOGLE_CDP_COMMAND, postC("/session/:sessionId/goog/cdp/execute")); + + commandRepository.put(GET_SCREEN_ORIENTATION, getC("/session/:sessionId/orientation")); + commandRepository.put(SET_SCREEN_ORIENTATION, postC("/session/:sessionId/orientation")); + commandRepository.put(GET_SCREEN_ROTATION, getC("/session/:sessionId/rotation")); + commandRepository.put(SET_SCREEN_ROTATION, postC("/session/:sessionId/rotation")); + + commandRepository.put(GET_CONTEXT_HANDLES, getC("/session/:sessionId/contexts")); + commandRepository.put(GET_CURRENT_CONTEXT_HANDLE, getC("/session/:sessionId/context")); + commandRepository.put(SWITCH_TO_CONTEXT, postC("/session/:sessionId/context")); } /** diff --git a/src/main/java/io/appium/java_client/remote/SupportsContextSwitching.java b/src/main/java/io/appium/java_client/remote/SupportsContextSwitching.java index b5c7e4b3b..b126e4fa1 100644 --- a/src/main/java/io/appium/java_client/remote/SupportsContextSwitching.java +++ b/src/main/java/io/appium/java_client/remote/SupportsContextSwitching.java @@ -17,11 +17,11 @@ package io.appium.java_client.remote; import io.appium.java_client.ExecutesMethod; +import io.appium.java_client.MobileCommand; import io.appium.java_client.NoSuchContextException; import org.openqa.selenium.ContextAware; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.remote.DriverCommand; import org.openqa.selenium.remote.Response; import javax.annotation.Nullable; @@ -42,7 +42,7 @@ public interface SupportsContextSwitching extends WebDriver, ContextAware, Execu default WebDriver context(String name) { requireNonNull(name, "Must supply a context name"); try { - execute(DriverCommand.SWITCH_TO_CONTEXT, Map.of("name", name)); + execute(MobileCommand.SWITCH_TO_CONTEXT, Map.of("name", name)); return this; } catch (WebDriverException e) { throw new NoSuchContextException(e.getMessage(), e); @@ -55,7 +55,7 @@ default WebDriver context(String name) { * @return List list of context names. */ default Set getContextHandles() { - Response response = execute(DriverCommand.GET_CONTEXT_HANDLES, Map.of()); + Response response = execute(MobileCommand.GET_CONTEXT_HANDLES, Map.of()); Object value = response.getValue(); try { //noinspection unchecked @@ -75,7 +75,7 @@ default Set getContextHandles() { @Nullable default String getContext() { String contextName = - String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue()); + String.valueOf(execute(MobileCommand.GET_CURRENT_CONTEXT_HANDLE).getValue()); return "null".equalsIgnoreCase(contextName) ? null : contextName; } } 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 4e8078707..74397a3e0 100644 --- a/src/main/java/io/appium/java_client/remote/SupportsRotation.java +++ b/src/main/java/io/appium/java_client/remote/SupportsRotation.java @@ -17,10 +17,10 @@ package io.appium.java_client.remote; import io.appium.java_client.ExecutesMethod; +import io.appium.java_client.MobileCommand; import org.openqa.selenium.DeviceRotation; import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DriverCommand; import org.openqa.selenium.remote.Response; import java.util.Map; @@ -32,17 +32,17 @@ public interface SupportsRotation extends WebDriver, ExecutesMethod { * @return The rotation value. */ default DeviceRotation rotation() { - Response response = execute(DriverCommand.GET_SCREEN_ROTATION); + Response response = execute(MobileCommand.GET_SCREEN_ROTATION); //noinspection unchecked return new DeviceRotation((Map) response.getValue()); } default void rotate(DeviceRotation rotation) { - execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters()); + execute(MobileCommand.SET_SCREEN_ROTATION, rotation.parameters()); } default void rotate(ScreenOrientation orientation) { - execute(DriverCommand.SET_SCREEN_ORIENTATION, + execute(MobileCommand.SET_SCREEN_ORIENTATION, Map.of("orientation", orientation.value().toUpperCase())); } @@ -52,7 +52,7 @@ default void rotate(ScreenOrientation orientation) { * @return The orientation value. */ default ScreenOrientation getOrientation() { - Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION); + Response response = execute(MobileCommand.GET_SCREEN_ORIENTATION); String orientation = String.valueOf(response.getValue()); return ScreenOrientation.valueOf(orientation.toUpperCase()); }