Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to add custom command dynamically #1506

Merged
merged 7 commits into from
Aug 30, 2021
Merged

Conversation

SrinivasanTarget
Copy link
Member

Change list

Appium 2.0 will allow custom plugins to add their own endpoint. This feature helps add custom commands dynamically.

Types of changes

What types of changes are you proposing/introducing to Java client?
Put an x in the boxes that apply

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Details

driver.addCommand(HttpMethod.GET, "/sessions", "getSessions");
driver.execute("getSessions");

@SrinivasanTarget
Copy link
Member Author

@jlipps fyi

@@ -241,6 +241,9 @@ public Response execute(Command command) throws WebDriverException {
}
});
}
if (getAdditionalCommands().containsKey(command.getName())) {
super.defineCommand(command.getName(), getAdditionalCommands().get(command.getName()));
Copy link
Contributor

Choose a reason for hiding this comment

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

should we verify if the defined command does not override an existing one?

Copy link
Member Author

Choose a reason for hiding this comment

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

At server side of plugin, we allow to override the behaviour of an Appium command though the path of command remain same. Keep the client side in line with server, I would like to allow client plugins also to override the existing command in same path with a different behaviour.

@SrinivasanTarget SrinivasanTarget merged commit bcd6881 into master Aug 30, 2021
@SrinivasanTarget SrinivasanTarget deleted the addNewCommand branch August 30, 2021 05:39
Copy link
Member

@jlipps jlipps left a comment

Choose a reason for hiding this comment

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

I think it would help to have an example of how an actual client plugin might be used by end users. This PR seems to help plugin builders, without necessarily providing a recommended format. For example, would it be something like this? (pseudo java):

CustomPlugin plugin = new CustomPlugin(driver);
driver.findElement(...); // do stuff with driver
plugin.myCustomCommand(...); // do stuff with plugin

Is there no way in Java to do some metaprogramming? Ideally we'd be able to use multiple plugins, something like this:

CustomPlugin1.installTo(driver);
CustomPlugin2.installTo(driver);
driver.findElement(...); // do stuff with driver
driver.customCommand1(...); // do stuff with plugin 1
driver.customCommand2(...); // do stuff with plugin 2

I don't know Java well enough to know whether this is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants