Skip to content

Commit

Permalink
chore: Add non-W3C endpoints removed from Selenium client (#2093)
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst authored Jan 7, 2024
1 parent f253794 commit 3ab5bf9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
18 changes: 18 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CommandInfo> commandRepository;

static {
Expand Down Expand Up @@ -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"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -55,7 +55,7 @@ default WebDriver context(String name) {
* @return List list of context names.
*/
default Set<String> 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
Expand All @@ -75,7 +75,7 @@ default Set<String> 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;
}
}
10 changes: 5 additions & 5 deletions src/main/java/io/appium/java_client/remote/SupportsRotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Number>) 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()));
}

Expand All @@ -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());
}
Expand Down

0 comments on commit 3ab5bf9

Please sign in to comment.