Backdoor Method
The Espresso driver allows to directly invoke a method from the application under test using the
mobile: backdoor execute method.
Info
Only 'public' methods can be invoked (they must have the Kotlin open modifier).
Targets¶
The execute method allows to specify the application methods using the methods parameter, and
distinguish the target type depending on the value of the target parameter:
application:methodswill be invoked on the application classactivity:methodswill be invoked on the current application activityelement:methodswill be invoked on the selected view element
Argument Types¶
Arguments provided in methods must have one of the following primitive types: int, boolean,
byte, short, long, float, or char.
The driver also supports object wrappers over primitive types with the java.lang.* fully
qualified name: java.lang.CharSequence, java.lang.String, java.lang.Integer,
java.lang.Float, java.lang.Double, java.lang.Boolean, java.lang.Long, java.lang.Short,
java.lang.Character, etc.
Example¶
{
"target": "activity",
"methods":
[
{
"name": "firstMethod",
},
{
"name": "secondMethod",
"args": [
{"value": "foo", "type": "java.lang.CharSequence"},
{"value": 1, "type": "int"}
]
}
]
}
The flow in the above example is as follows:
firstMethodis called on the current activity instance. It takes no arguments.secondMethodis called on the object returned byfirstMethod. It accepts two arguments, with the first one beingfooof typejava.lang.CharSequence, and the second being1of typeint.- The result of
secondMethodis returned to the client.