Skip to content

Commit

Permalink
fix: Fix addition of custom commands
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed Dec 12, 2024
1 parent 0a29a3a commit 0ee114b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 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 @@ -195,6 +195,10 @@ public void refreshAdditionalCommands() {
getAdditionalCommands().forEach(this::defineCommand);
}

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

@SuppressWarnings("unchecked")
private void setDirectConnect(Response response) throws SessionNotCreatedException {
Map<String, ?> responseValue = (Map<String, ?>) response.getValue();
Expand Down

0 comments on commit 0ee114b

Please sign in to comment.