Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add non-W3C endpoints remove from Selenium client #2093

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
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