UiAutomatorRunner
public
class
UiAutomatorRunner
extends Object
implements
IRemoteAndroidTestRunner
| java.lang.Object | |
| ↳ | com.android.tradefed.testtype.UiAutomatorRunner |
Runs UI Automator test on device and reports results. UI Automator test is a dedicated test runner for running UI automation tests that utilizes UI Automator framework. The test runner on device emulates instrumentation test output format so that existing parsing code in ddmlib and TF can be reused. Essentially, this is a wrapper around this command: adb shell uiautomator runtest (jar files) -e class (test classes) ...
Summary
Public constructors | |
|---|---|
UiAutomatorRunner(IDevice remoteDevice, String[] jarPaths, String runnerPath)
Create a UiAutomatorRunner for running UI automation tests |
|
Public methods | |
|---|---|
void
|
addBooleanArg(String name, boolean value)
Adds a boolean argument to include in instrumentation command. |
void
|
addInstrumentationArg(String name, String value)
Adds a argument to include in instrumentation command. |
void
|
cancel()
Requests cancellation of this test run. |
IRemoteAndroidTestRunner.CoverageOutput
|
getCoverageOutputType()
Returns the type of the test coverage produces by the runner. |
String
|
getPackageName()
Returns the package name of last Java class added |
String
|
getRunnerName()
Returns default UiAutomatorTestRunner class name |
void
|
removeInstrumentationArg(String name)
Removes a previously added argument. |
void
|
run(ITestRunListener... listeners)
Execute this test run. |
void
|
run(
Execute this test run. |
void
|
setAdditionalTestOutputLocation(String additionalTestDataPath)
Sets the location of the additional test output to be copied to host before the test app is uninstalled. |
void
|
setClassName(String className)
Sets to run only tests in this class Must be called before 'run'. |
void
|
setClassNames(String[] classNames)
Sets to run only tests in the provided classes Must be called before 'run'. |
void
|
setCoverage(boolean coverage)
Sets this code coverage mode of this test run. |
void
|
setCoverageReportLocation(String arg0)
Sets the location of the generated coverage reports. |
void
|
setDebug(boolean debug)
Sets this debug mode of this test run. |
void
|
setIgnoreSighup(boolean value)
Sets the option in the uiautomator to ignore SIGHUP. |
void
|
setLogOnly(boolean logOnly)
Sets this test run to log only mode - skips test execution. |
void
|
setMaxTimeToOutputResponse(long timeout, TimeUnit unit)
Sets the maximum time allowed between output of the shell command running the tests on the devices. |
void
|
setMaxTimeout(long maxTimeout, TimeUnit unit)
Sets the maximum time allowed for the instrumentation to finish. |
void
|
setMaxtimeToOutputResponse(int maxTimeToOutputResponse)
This method is deprecated.
use |
void
|
setMethodName(String className, String testName)
Sets to run only specified test method Must be called before 'run'. |
void
|
setRunName(String runName)
Set a custom run name to be reported to the If unspecified, will use package name |
void
|
setTestCollection(boolean b)
Sets this test run to test collection mode. |
void
|
setTestPackageName(String packageName)
Sets to run all tests in specified package Must be called before 'run'. |
void
|
setTestSize(IRemoteAndroidTestRunner.TestSize size)
Sets to run only tests of given size. |
Protected methods | |
|---|---|
String
|
getRunCommand()
|
String
|
getRunnerPath()
|
Public constructors
UiAutomatorRunner
public UiAutomatorRunner (IDevice remoteDevice, String[] jarPaths, String runnerPath)
Create a UiAutomatorRunner for running UI automation tests
| Parameters | |
|---|---|
remoteDevice |
IDevice: the remote device to interact with: run test, collect results etc |
jarPaths |
String: the paths to jar files where UI Automator test cases are; the paths must be
absolute or relative to /data/local/tmp/ on device |
runnerPath |
String: alternative uiautomator runner to use, may be null and default
will be used in this case |
Public methods
addBooleanArg
public void addBooleanArg (String name,
boolean value)Adds a boolean argument to include in instrumentation command.
| Parameters | |
|---|---|
name |
String: the name of the instrumentation bundle argument |
value |
boolean: the value of the argument |
addInstrumentationArg
public void addInstrumentationArg (String name,
String value)Adds a argument to include in instrumentation command.
Must be called before 'run'. If an argument with given name has already been provided, its value will be overridden.
| Parameters | |
|---|---|
name |
String: the name of the instrumentation bundle argument |
value |
String: the value of the argument |
cancel
public void cancel ()
Requests cancellation of this test run.
getCoverageOutputType
public IRemoteAndroidTestRunner.CoverageOutput getCoverageOutputType ()
Returns the type of the test coverage produces by the runner. See CoverageOutput.
| Returns | |
|---|---|
IRemoteAndroidTestRunner.CoverageOutput |
|
getPackageName
public String getPackageName ()
Returns the package name of last Java class added
| Returns | |
|---|---|
String |
|
getRunnerName
public String getRunnerName ()
Returns default UiAutomatorTestRunner class name
| Returns | |
|---|---|
String |
|
removeInstrumentationArg
public void removeInstrumentationArg (String name)
Removes a previously added argument.
| Parameters | |
|---|---|
name |
String: the name of the instrumentation bundle argument to remove |
run
public void run (ITestRunListener... listeners)
Execute this test run.
Convenience method for ERROR(/#run(Collection)).
| Parameters | |
|---|---|
listeners |
ITestRunListener: listens for test results |
| Throws | |
|---|---|
AdbCommandRejectedException |
|
ShellCommandUnresponsiveException |
|
TimeoutException |
|
run
public void run (listeners)
Execute this test run.
| Parameters | |
|---|---|
listeners |
: collection of listeners for test results |
| Throws | |
|---|---|
AdbCommandRejectedException |
|
ShellCommandUnresponsiveException |
|
TimeoutException |
|
setAdditionalTestOutputLocation
public void setAdditionalTestOutputLocation (String additionalTestDataPath)
Sets the location of the additional test output to be copied to host before the test app is uninstalled. E.g., generated benchmark reports.
| Parameters | |
|---|---|
additionalTestDataPath |
String |
setClassName
public void setClassName (String className)
Sets to run only tests in this class Must be called before 'run'.
| Parameters | |
|---|---|
className |
String: fully qualified class name (eg x.y.z) |
setClassNames
public void setClassNames (String[] classNames)
Sets to run only tests in the provided classes Must be called before 'run'.
If providing more than one class, requires a InstrumentationTestRunner that supports the multiple class argument syntax.
| Parameters | |
|---|---|
classNames |
String: array of fully qualified class names (eg x.y.z) |
setCoverage
public void setCoverage (boolean coverage)
Sets this code coverage mode of this test run.
| Parameters | |
|---|---|
coverage |
boolean |
setCoverageReportLocation
public void setCoverageReportLocation (String arg0)
Sets the location of the generated coverage reports.
| Parameters | |
|---|---|
arg0 |
String |
setDebug
public void setDebug (boolean debug)
Sets this debug mode of this test run. If true, the Android test runner will wait for a debugger to attach before proceeding with test execution.
| Parameters | |
|---|---|
debug |
boolean |
setIgnoreSighup
public void setIgnoreSighup (boolean value)
Sets the option in the uiautomator to ignore SIGHUP.
| Parameters | |
|---|---|
value |
boolean: ignore the signal if set to true |
setLogOnly
public void setLogOnly (boolean logOnly)
Sets this test run to log only mode - skips test execution.
| Parameters | |
|---|---|
logOnly |
boolean |
setMaxTimeToOutputResponse
public void setMaxTimeToOutputResponse (long timeout,
TimeUnit unit)Sets the maximum time allowed between output of the shell command running the tests on the devices.
This allows setting a timeout in case the tests can become stuck and never finish. This is different from the normal timeout on the connection.
By default no timeout will be specified.
| Parameters | |
|---|---|
timeout |
long: the maximum amount of time during which the command is allowed
to not output any response. A value of 0 means the method will wait forever (until the
receiver cancels the execution) for command output and never throw. |
unit |
TimeUnit: Units for non-zero maxTimeToOutputResponse and maxTimeout
values. |
setMaxTimeout
public void setMaxTimeout (long maxTimeout,
TimeUnit unit)Sets the maximum time allowed for the instrumentation to finish.
This allows setting a timeout in case the tests can become stuck and never finish. This is different from the normal timeout on the connection.
By default no timeout will be specified.
| Parameters | |
|---|---|
maxTimeout |
long: the maximum amount of time during which the command is allowed to not
output any response. A value of 0 means the method will wait forever (until the
receiver cancels the execution) for command output and never throw. |
unit |
TimeUnit: Units for non-zero maxTimeToOutputResponse and maxTimeout
values. |
setMaxtimeToOutputResponse
public void setMaxtimeToOutputResponse (int maxTimeToOutputResponse)
This method is deprecated.
use setMaxTimeToOutputResponse(long, TimeUnit) instead.
| Parameters | |
|---|---|
maxTimeToOutputResponse |
int |
setMethodName
public void setMethodName (String className,
String testName)Sets to run only specified test method Must be called before 'run'.
| Parameters | |
|---|---|
className |
String: fully qualified class name (eg x.y.z) |
testName |
String: method name |
setRunName
public void setRunName (String runName)
Set a custom run name to be reported to the ITestRunListener on run(
If unspecified, will use package name
setTestCollection
public void setTestCollection (boolean b)
Sets this test run to test collection mode. If true, will skip test execution and will set all appropriate runner arguments required for a successful test collection.
| Parameters | |
|---|---|
b |
boolean |
setTestPackageName
public void setTestPackageName (String packageName)
Sets to run all tests in specified package Must be called before 'run'.
| Parameters | |
|---|---|
packageName |
String: fully qualified package name (eg x.y.z) |
setTestSize
public void setTestSize (IRemoteAndroidTestRunner.TestSize size)
Sets to run only tests of given size. Must be called before 'run'.
| Parameters | |
|---|---|
size |
IRemoteAndroidTestRunner.TestSize: the TestSize to run. |
Protected methods
getRunCommand
protected String getRunCommand ()
| Returns | |
|---|---|
String |
|
getRunnerPath
protected String getRunnerPath ()
| Returns | |
|---|---|
String |
|