public class InstrumentationUtils
extends java.lang.Object
Instrumentation
.Constructor and Description |
---|
InstrumentationUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getD2Option(java.lang.String key)
Calls
getOption(java.lang.String) with "dd." prefixed to key . |
static android.app.Instrumentation |
getInstrumentation() |
static java.lang.String |
getOption(java.lang.String key)
Gets the string value associated with the given key.
|
static android.os.Bundle |
getOptions()
Gets the am instrument options.
|
static android.content.Context |
getTargetContext() |
static void |
init(android.app.Instrumentation instrumentation,
android.os.Bundle arguments)
Initializes this class.
|
static <V> V |
runOnMainSyncWithTimeout(java.util.concurrent.Callable<V> callable)
Runs
callable on the main thread on best-effort basis up to a time limit, which
defaults to 10000L and can be set as an am instrument option under the key dd.runOnMainSyncTimeout . |
static void |
runOnMainSyncWithTimeout(java.lang.Runnable runnable) |
static boolean |
tryWaitForIdleSync(long timeoutMillis)
Tries to wait for an idle state on the main thread on best-effort basis up to
timeoutMillis . |
public static void init(android.app.Instrumentation instrumentation, android.os.Bundle arguments)
TestRunner.onCreate(android.os.Bundle)
for
example.public static android.app.Instrumentation getInstrumentation()
public static android.content.Context getTargetContext()
public static android.os.Bundle getOptions()
public static java.lang.String getOption(java.lang.String key)
getOptions()
because the returned Bundle
contains only string values - am instrument
options do not support value types other than string.public static java.lang.String getD2Option(java.lang.String key)
getOption(java.lang.String)
with "dd." prefixed to key
. This is for DroidDriver
implementation to use a consistent pattern for its options.public static boolean tryWaitForIdleSync(long timeoutMillis)
timeoutMillis
. The main thread may not enter the idle state when animation is playing, for
example, the ProgressBar.public static void runOnMainSyncWithTimeout(java.lang.Runnable runnable)
public static <V> V runOnMainSyncWithTimeout(java.util.concurrent.Callable<V> callable)
callable
on the main thread on best-effort basis up to a time limit, which
defaults to 10000L
and can be set as an am instrument option under the key dd.runOnMainSyncTimeout
. This is a safer variation of Instrumentation.runOnMainSync(java.lang.Runnable)
because the latter may hang. You may turn off this behavior by setting "-e
dd.runOnMainSyncTimeout 0"
on the am command line.
callable
may never run, for
example, if the main Looper has exited due to uncaught exception.