Skip to content

Commit 0dae8da

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

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

+6-4
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private Response createSession(Command command) throws IOException {
181181
+ "Please make sure your server is up to date.");
182182
}
183183
setCommandCodec(new AppiumW3CHttpCommandCodec());
184-
refreshAdditionalCommands();
184+
getAdditionalCommands().forEach(this::defineCommand);
185185
setResponseCodec(dialect.getResponseCodec());
186186
Response response = result.createResponse();
187187
if (this.appiumClientConfig != null && this.appiumClientConfig.isDirectConnectEnabled()) {
@@ -191,8 +191,8 @@ private Response createSession(Command command) throws IOException {
191191
return response;
192192
}
193193

194-
public void refreshAdditionalCommands() {
195-
getAdditionalCommands().forEach(this::defineCommand);
194+
public void defineCommand(String commandName, CommandInfo info) {
195+
super.defineCommand(commandName, info);
196196
}
197197

198198
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)