-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Conversation
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? |
@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. |
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/handlers/WebAtoms.kt
Outdated
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/handlers/WebAtoms.kt
Outdated
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/handlers/WebAtoms.kt
Outdated
Show resolved
Hide resolved
...sso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/KReflectionUtils.kt
Show resolved
Hide resolved
...sso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/KReflectionUtils.kt
Outdated
Show resolved
Hide resolved
...sso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/KReflectionUtils.kt
Outdated
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/web/WebAtom.kt
Outdated
Show resolved
Hide resolved
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/web/WebAtom.kt
Outdated
Show resolved
Hide resolved
for (arg in args.asJsonArray) { | ||
if (arg.isJsonPrimitive) { | ||
val argPrimitive = arg.asJsonPrimitive | ||
if (argPrimitive.isBoolean) argsAsList.add(argPrimitive.asBoolean) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/
espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/web/WebAtom.kt
Outdated
Show resolved
Hide resolved
...sso-server/app/src/androidTest/java/io/appium/espressoserver/lib/model/web/WebAtomsParams.kt
Outdated
Show resolved
Hide resolved
@@ -95,6 +95,10 @@ commands.mobileNavigateTo = async function (opts = {}) { | |||
}); | |||
}; | |||
|
|||
commands.mobileWebAtoms = async function (opts = {}) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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", ...]}}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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; |
There was a problem hiding this comment.
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<*>)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!is
is also valid
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.)
calls...
Also added KReflectionUtils which implements reflection using Kotlin.