Skip to content

Commit 3ab5bf9

Browse files
authored
chore: Add non-W3C endpoints removed from Selenium client (#2093)
1 parent f253794 commit 3ab5bf9

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/main/java/io/appium/java_client/MobileCommand.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ public class MobileCommand {
178178
protected static final String GET_ALLSESSION;
179179
protected static final String EXECUTE_GOOGLE_CDP_COMMAND;
180180

181+
public static final String GET_SCREEN_ORIENTATION = "getScreenOrientation";
182+
public static final String SET_SCREEN_ORIENTATION = "setScreenOrientation";
183+
public static final String GET_SCREEN_ROTATION = "getScreenRotation";
184+
public static final String SET_SCREEN_ROTATION = "setScreenRotation";
185+
186+
public static final String GET_CONTEXT_HANDLES = "getContextHandles";
187+
public static final String GET_CURRENT_CONTEXT_HANDLE = "getCurrentContextHandle";
188+
public static final String SWITCH_TO_CONTEXT = "switchToContext";
189+
181190
public static final Map<String, CommandInfo> commandRepository;
182191

183192
static {
@@ -347,6 +356,15 @@ public class MobileCommand {
347356
commandRepository.put(EXECUTE_DRIVER_SCRIPT, postC("/session/:sessionId/appium/execute_driver"));
348357
commandRepository.put(GET_ALLSESSION, getC("/sessions"));
349358
commandRepository.put(EXECUTE_GOOGLE_CDP_COMMAND, postC("/session/:sessionId/goog/cdp/execute"));
359+
360+
commandRepository.put(GET_SCREEN_ORIENTATION, getC("/session/:sessionId/orientation"));
361+
commandRepository.put(SET_SCREEN_ORIENTATION, postC("/session/:sessionId/orientation"));
362+
commandRepository.put(GET_SCREEN_ROTATION, getC("/session/:sessionId/rotation"));
363+
commandRepository.put(SET_SCREEN_ROTATION, postC("/session/:sessionId/rotation"));
364+
365+
commandRepository.put(GET_CONTEXT_HANDLES, getC("/session/:sessionId/contexts"));
366+
commandRepository.put(GET_CURRENT_CONTEXT_HANDLE, getC("/session/:sessionId/context"));
367+
commandRepository.put(SWITCH_TO_CONTEXT, postC("/session/:sessionId/context"));
350368
}
351369

352370
/**

src/main/java/io/appium/java_client/remote/SupportsContextSwitching.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package io.appium.java_client.remote;
1818

1919
import io.appium.java_client.ExecutesMethod;
20+
import io.appium.java_client.MobileCommand;
2021
import io.appium.java_client.NoSuchContextException;
2122
import org.openqa.selenium.ContextAware;
2223
import org.openqa.selenium.WebDriver;
2324
import org.openqa.selenium.WebDriverException;
24-
import org.openqa.selenium.remote.DriverCommand;
2525
import org.openqa.selenium.remote.Response;
2626

2727
import javax.annotation.Nullable;
@@ -42,7 +42,7 @@ public interface SupportsContextSwitching extends WebDriver, ContextAware, Execu
4242
default WebDriver context(String name) {
4343
requireNonNull(name, "Must supply a context name");
4444
try {
45-
execute(DriverCommand.SWITCH_TO_CONTEXT, Map.of("name", name));
45+
execute(MobileCommand.SWITCH_TO_CONTEXT, Map.of("name", name));
4646
return this;
4747
} catch (WebDriverException e) {
4848
throw new NoSuchContextException(e.getMessage(), e);
@@ -55,7 +55,7 @@ default WebDriver context(String name) {
5555
* @return List list of context names.
5656
*/
5757
default Set<String> getContextHandles() {
58-
Response response = execute(DriverCommand.GET_CONTEXT_HANDLES, Map.of());
58+
Response response = execute(MobileCommand.GET_CONTEXT_HANDLES, Map.of());
5959
Object value = response.getValue();
6060
try {
6161
//noinspection unchecked
@@ -75,7 +75,7 @@ default Set<String> getContextHandles() {
7575
@Nullable
7676
default String getContext() {
7777
String contextName =
78-
String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());
78+
String.valueOf(execute(MobileCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());
7979
return "null".equalsIgnoreCase(contextName) ? null : contextName;
8080
}
8181
}

src/main/java/io/appium/java_client/remote/SupportsRotation.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
package io.appium.java_client.remote;
1818

1919
import io.appium.java_client.ExecutesMethod;
20+
import io.appium.java_client.MobileCommand;
2021
import org.openqa.selenium.DeviceRotation;
2122
import org.openqa.selenium.ScreenOrientation;
2223
import org.openqa.selenium.WebDriver;
23-
import org.openqa.selenium.remote.DriverCommand;
2424
import org.openqa.selenium.remote.Response;
2525

2626
import java.util.Map;
@@ -32,17 +32,17 @@ public interface SupportsRotation extends WebDriver, ExecutesMethod {
3232
* @return The rotation value.
3333
*/
3434
default DeviceRotation rotation() {
35-
Response response = execute(DriverCommand.GET_SCREEN_ROTATION);
35+
Response response = execute(MobileCommand.GET_SCREEN_ROTATION);
3636
//noinspection unchecked
3737
return new DeviceRotation((Map<String, Number>) response.getValue());
3838
}
3939

4040
default void rotate(DeviceRotation rotation) {
41-
execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters());
41+
execute(MobileCommand.SET_SCREEN_ROTATION, rotation.parameters());
4242
}
4343

4444
default void rotate(ScreenOrientation orientation) {
45-
execute(DriverCommand.SET_SCREEN_ORIENTATION,
45+
execute(MobileCommand.SET_SCREEN_ORIENTATION,
4646
Map.of("orientation", orientation.value().toUpperCase()));
4747
}
4848

@@ -52,7 +52,7 @@ default void rotate(ScreenOrientation orientation) {
5252
* @return The orientation value.
5353
*/
5454
default ScreenOrientation getOrientation() {
55-
Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);
55+
Response response = execute(MobileCommand.GET_SCREEN_ORIENTATION);
5656
String orientation = String.valueOf(response.getValue());
5757
return ScreenOrientation.valueOf(orientation.toUpperCase());
5858
}

0 commit comments

Comments
 (0)