Skip to content

Commit

Permalink
fix: Fix compatibility with latest Selenium snapshots (#2249)
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst authored Dec 15, 2024
1 parent 42480fe commit 7fc702e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.ErrorHandler;
import org.openqa.selenium.remote.ExecuteMethod;
Expand Down Expand Up @@ -242,22 +243,23 @@ public Map<String, Object> getStatus() {
* @param methodName The name of custom appium command.
*/
public void addCommand(HttpMethod httpMethod, String url, String methodName) {
CommandInfo commandInfo;
switch (httpMethod) {
case GET:
MobileCommand.commandRepository.put(methodName, MobileCommand.getC(url));
commandInfo = MobileCommand.getC(url);
break;
case POST:
MobileCommand.commandRepository.put(methodName, MobileCommand.postC(url));
commandInfo = MobileCommand.postC(url);
break;
case DELETE:
MobileCommand.commandRepository.put(methodName, MobileCommand.deleteC(url));
commandInfo = MobileCommand.deleteC(url);
break;
default:
throw new WebDriverException(String.format("Unsupported HTTP Method: %s. Only %s methods are supported",
httpMethod,
Arrays.toString(HttpMethod.values())));
}
((AppiumCommandExecutor) getCommandExecutor()).refreshAdditionalCommands();
((AppiumCommandExecutor) getCommandExecutor()).defineCommand(methodName, commandInfo);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected void setPrivateFieldValue(
ReflectionHelpers.setPrivateFieldValue(cls, this, fieldName, newValue);
}

protected Map<String, CommandInfo> getAdditionalCommands() {
public Map<String, CommandInfo> getAdditionalCommands() {
//noinspection unchecked
return getPrivateFieldValue(HttpCommandExecutor.class, "additionalCommands", Map.class);
}
Expand Down Expand Up @@ -192,7 +192,11 @@ private Response createSession(Command command) throws IOException {
}

public void refreshAdditionalCommands() {
getAdditionalCommands().forEach(this::defineCommand);
getAdditionalCommands().forEach(super::defineCommand);
}

public void defineCommand(String commandName, CommandInfo info) {
super.defineCommand(commandName, info);
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 7fc702e

Please sign in to comment.