Skip to content
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
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume there we can safely delete this getter as it is public now in the parent class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can, but it will bump the minimal Selenium client version to 4.28.0-SNAPSHOT, if it's ok, I'll do it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets wait until 4.28 is released, so then we could also release a new minor version of java client and set the minimum version there

//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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this method is not used anymore then it would probably make sense to mark it deprecated

getAdditionalCommands().forEach(this::defineCommand);
getAdditionalCommands().forEach(super::defineCommand);
}

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

@SuppressWarnings("unchecked")
Expand Down
Loading