1
1
package io.appium.espressoserver.lib.handlers
2
2
3
- import io.appium.espressoserver.lib.handlers.exceptions.AppiumException
4
3
import io.appium.espressoserver.lib.handlers.exceptions.InvalidArgumentException
5
4
import io.appium.espressoserver.lib.helpers.ActivityHelpers
6
5
import io.appium.espressoserver.lib.helpers.InvocationOperation
@@ -11,7 +10,6 @@ import io.appium.espressoserver.lib.model.MobileBackdoorParams
11
10
12
11
class MobileBackdoor : RequestHandler <MobileBackdoorParams , Any ?> {
13
12
14
- @Throws(AppiumException ::class )
15
13
override fun handleInternal (params : MobileBackdoorParams ): Any? {
16
14
params.target?.let {target ->
17
15
val activity = ActivityHelpers .currentActivity
@@ -21,7 +19,9 @@ class MobileBackdoor : RequestHandler<MobileBackdoorParams, Any?> {
21
19
val result = when (target) {
22
20
InvocationTarget .ACTIVITY -> invokeBackdoorMethods(activity, ops)
23
21
InvocationTarget .APPLICATION -> invokeBackdoorMethods(activity.application, ops)
24
- InvocationTarget .ELEMENT -> invokeBackdoorMethods(EspressoElement .getViewById(params.targetElement), ops)
22
+ InvocationTarget .ELEMENT -> invokeBackdoorMethods(
23
+ EspressoElement .getCachedViewStateById(params.targetElement).view, ops
24
+ )
25
25
else -> throw InvalidArgumentException (" target cannot be '$target '" )
26
26
} ? : return null
27
27
@@ -38,12 +38,11 @@ class MobileBackdoor : RequestHandler<MobileBackdoorParams, Any?> {
38
38
throw InvalidArgumentException (" Target must not be empty and must be of type: 'activity', 'application'" )
39
39
}
40
40
41
- @Throws( AppiumException :: class )
41
+ @Suppress( " RedundantNullableReturnType " )
42
42
private fun invokeBackdoorMethods (invokeOn : Any , ops : List <InvocationOperation >): Any? {
43
43
return ops.fold(invokeOn) { invocationTarget, operation -> operation.apply (invocationTarget) }
44
44
}
45
45
46
- @Throws(InvalidArgumentException ::class )
47
46
private fun getBackdoorOperations (params : MobileBackdoorParams ): List <InvocationOperation > {
48
47
return params.methods.map {method ->
49
48
InvocationOperation (method.name, method.arguments, method.argumentTypes)
0 commit comments