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: Add mobile endpoint for Web Atoms #380

Merged
merged 19 commits into from
Jan 23, 2019
Merged

feat: Add mobile endpoint for Web Atoms #380

merged 19 commits into from
Jan 23, 2019

Conversation

dpgraham
Copy link
Contributor

Implements an endpoint mobile: webAtoms which calls the Espresso web atoms API. The call provides JSON that provides an optional webView element, and then list of atoms to execute.

e.g.)

{
      webviewElement: webviewEl.value,
      forceJavascriptEnabled: true,
      methodChain: [
        {name: 'withElement', atom: {name: 'findElement', locator: {using: 'ID', value: 'i_am_a_textbox'}}},
        {name: 'perform', atom: {name: 'webKeys', args: 'Hello world'}},
        {name: 'withElement', atom: {name: 'findElement', locator: {using: 'ID', value: 'i am a link'}}},
        {name: 'perform', atom: 'webClick'},
      ]
    }

calls...

onWebView(theWebView)
  .forceJavascriptEnabled(true)
  .withElement(findElement(Locator.ID, "i_am_a_textbox"))
  .perform(webKeys("Hello world))
  .withElement(findElement(Locator.ID, "i am a link"))
  .perform(webClick())

Also added KReflectionUtils which implements reflection using Kotlin.

@jlipps
Copy link
Member

jlipps commented Jan 22, 2019

why expose this as a mobile command? i thought the idea was that we would switch context into the webview, and from then on all commands would ultimately generate atoms internally, but the user wouldn't know that as it's just an implementation detail?

@dpgraham
Copy link
Contributor Author

@jlipps this is a stopgap. I wanted to add this capability to see if there's interest in it. Also because the other option would require a lot more effort and I would like this available in the meantime.

for (arg in args.asJsonArray) {
if (arg.isJsonPrimitive) {
val argPrimitive = arg.asJsonPrimitive
if (argPrimitive.isBoolean) argsAsList.add(argPrimitive.asBoolean)
Copy link
Contributor

Choose a reason for hiding this comment

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

does kotlin allow to use switch?

Copy link
Contributor Author

@dpgraham dpgraham Jan 22, 2019

Choose a reason for hiding this comment

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

In this case, I can't use switch because I couldn't find anything for the JsonPrimitive that returns the type. I had to go check the types individually.

Copy link
Contributor

Choose a reason for hiding this comment

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

Kotlin, actually has when operator, which might be in use here. Check https://superkotlin.com/kotlin-when-statement/

@@ -95,6 +95,10 @@ commands.mobileNavigateTo = async function (opts = {}) {
});
};

commands.mobileWebAtoms = async function (opts = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect to see some docstring here especially about opts JSON format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add it to the mobile documents section in appium.io

Copy link
Contributor

Choose a reason for hiding this comment

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

do we have any required fields in opts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just methodChain.... I'll add that.

@mykola-mokhnach
Copy link
Contributor

I like the tests

* "webviewEl": "<ELEMENT_ID>", // optional webview element to operate on
* "forceJavascriptEnabled": true|false, // if webview disables javascript, webatoms won't work, this forces it
* "methods": [
* {"name": "methodName", "atom": {"name": "atomName", "args": ["arg1", "arg2", ...]}},
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind to also add a link containing a list of available atoms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@dpgraham dpgraham merged commit 36837a1 into master Jan 23, 2019
@dpgraham dpgraham deleted the dpgraham-web-atoms branch January 23, 2019 18:16
val atom = invokeMethod(DriverAtoms::class, method.atom.name, *method.atom.args.toTypedArray());

logger.info("Calling interaction '${method.name}' with the atom '${method.atom}'")
val args = if (atom == null) emptyList<Any>() else atom;
Copy link
Contributor

Choose a reason for hiding this comment

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

there is also ?: operator ;)

val args = if (atom == null) emptyList<Any>() else atom;
val res = invokeInstanceMethod(webViewInteraction, method.name, args);

if (!(res is WebInteraction<*>)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

!is is also valid

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

3 participants