Skip to content

Commit 440a6fd

Browse files
authored
feat: Return web atom response (#941)
1 parent 47ee699 commit 440a6fd

File tree

1 file changed

+14
-10
lines changed
  • espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/handlers

1 file changed

+14
-10
lines changed

espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/handlers/WebAtoms.kt

+14-10
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ import io.appium.espressoserver.lib.model.EspressoElement
2929
import io.appium.espressoserver.lib.model.web.WebAtomsParams
3030
import io.appium.espressoserver.lib.viewmatcher.withView
3131

32-
class WebAtoms : RequestHandler<WebAtomsParams, Void?> {
32+
class WebAtoms : RequestHandler<WebAtomsParams, Any?> {
3333

3434
@Throws(AppiumException::class)
35-
override fun handleInternal(params: WebAtomsParams): Void? {
36-
var webViewInteraction:WebInteraction<*>
35+
override fun handleInternal(params: WebAtomsParams): Any? {
36+
var webViewInteraction: WebInteraction<*>
3737

3838
// TODO: Add a 'waitForDocument' feature to wait for HTML DOCUMENT to be ready
3939

4040
// Initialize onWebView with web view matcher (if webviewEl provided)
41-
params.webviewElement.let{ webviewElement ->
41+
params.webviewElement.let { webviewElement ->
4242
AndroidLogger.info("Initializing webView interaction on webview with el: '$webviewElement'")
4343
val viewState = EspressoElement.getCachedViewStateById(webviewElement)
4444
val matcher = withView(viewState.view)
@@ -53,18 +53,22 @@ class WebAtoms : RequestHandler<WebAtomsParams, Void?> {
5353
// Iterate through methodsChain and call the atoms
5454
params.methodChain.forEach { method ->
5555
val atom = invokeStaticMethod(DriverAtoms::class.java, method.atom.name, *method.atom.args) as? Atom<*>
56-
?: throw InvalidArgumentException("'${method.atom.name}' did not return a valid " +
57-
"'${Atom::class.qualifiedName}' object")
56+
?: throw InvalidArgumentException(
57+
"'${method.atom.name}' did not return a valid '${Atom::class.qualifiedName}' object",
58+
)
5859

5960
AndroidLogger.info("Calling interaction '${method.name}' with the atom '${method.atom}'")
6061

6162
val res = invokeInstanceMethod(webViewInteraction, method.name, atom) as? WebInteraction<*>
62-
?: throw InvalidArgumentException("'${method.name}' does not return a valid " +
63-
"'${WebInteraction::class.qualifiedName}' object")
63+
?: throw InvalidArgumentException(
64+
"'${method.name}' does not return a valid '${WebInteraction::class.qualifiedName}' object",
65+
)
6466

6567
webViewInteraction = res
6668
}
67-
68-
return null
69+
// if you don't pass any action to perform `webViewInteraction.get()` will throw error
70+
// java.lang.IllegalStateException: Perform or Check never called on this WebInteraction!
71+
// when you just want to just check element existence call with `selectActiveElement` as action
72+
return webViewInteraction.get()
6973
}
7074
}

0 commit comments

Comments
 (0)