Skip to content

Commit 0ee114b

Browse files
committed
fix: Fix addition of custom commands
1 parent 0a29a3a commit 0ee114b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.openqa.selenium.UnsupportedCommandException;
3232
import org.openqa.selenium.WebDriverException;
3333
import org.openqa.selenium.remote.CapabilityType;
34+
import org.openqa.selenium.remote.CommandInfo;
3435
import org.openqa.selenium.remote.DriverCommand;
3536
import org.openqa.selenium.remote.ErrorHandler;
3637
import org.openqa.selenium.remote.ExecuteMethod;
@@ -242,22 +243,23 @@ public Map<String, Object> getStatus() {
242243
* @param methodName The name of custom appium command.
243244
*/
244245
public void addCommand(HttpMethod httpMethod, String url, String methodName) {
246+
CommandInfo commandInfo;
245247
switch (httpMethod) {
246248
case GET:
247-
MobileCommand.commandRepository.put(methodName, MobileCommand.getC(url));
249+
commandInfo = MobileCommand.getC(url);
248250
break;
249251
case POST:
250-
MobileCommand.commandRepository.put(methodName, MobileCommand.postC(url));
252+
commandInfo = MobileCommand.postC(url);
251253
break;
252254
case DELETE:
253-
MobileCommand.commandRepository.put(methodName, MobileCommand.deleteC(url));
255+
commandInfo = MobileCommand.deleteC(url);
254256
break;
255257
default:
256258
throw new WebDriverException(String.format("Unsupported HTTP Method: %s. Only %s methods are supported",
257259
httpMethod,
258260
Arrays.toString(HttpMethod.values())));
259261
}
260-
((AppiumCommandExecutor) getCommandExecutor()).refreshAdditionalCommands();
262+
((AppiumCommandExecutor) getCommandExecutor()).defineCommand(methodName, commandInfo);
261263
}
262264

263265
@Override

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ public void refreshAdditionalCommands() {
195195
getAdditionalCommands().forEach(this::defineCommand);
196196
}
197197

198+
public void defineCommand(String commandName, CommandInfo info) {
199+
super.defineCommand(commandName, info);
200+
}
201+
198202
@SuppressWarnings("unchecked")
199203
private void setDirectConnect(Response response) throws SessionNotCreatedException {
200204
Map<String, ?> responseValue = (Map<String, ?>) response.getValue();

0 commit comments

Comments
 (0)