UiAutomator 2.0 test from the command line
I am trying to use UIAutomator for some simple tests, I know it should be built with Gradle, since UIAutomator 2.0, I can run my simple test which only presses the home button through Android Studio or command line from "gradlew.bat cC ", I was wondering how can I start it using adb command?
I tried
adb shell am instrument -w test.simple.uiatest/android.test.InstrumentationTestRunner
as suggested here , but i get
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{test.simple.uiatest/android.test.InstrumentationTestRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: test.simple.uiatest/android.test.InstrumentationTestRunner
at com.android.commands.am.Am.runInstrument(Am.java:951)
at com.android.commands.am.Am.onRun(Am.java:316)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:99)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:250)
Below is my code snippet and build.gradle, what am I doing wrong?
package test.simple.uiatest;
import android.support.test.uiautomator.UiDevice;
import android.test.InstrumentationTestCase;
public class ApplicationTest extends InstrumentationTestCase {
private UiDevice theDevice;
@Override
public void setUp() throws Exception {
super.setUp();
theDevice = UiDevice.getInstance(getInstrumentation());
theDevice.pressHome();
}
public void testName() throws Exception {
theDevice.pressHome();
}
}
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
applicationId "test.simple.uiatest"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0'
}
source to share
The error you see will happen if the test APK is not installed, or if the <test_package> / <runner_class> value in your command am instrument ...
is incorrect.
To list the benchmarks available on your device, you can run adb shell pm list instrumentation
. You should see a line like:
instrumentation:test.simple.uiatest/android.test.InstrumentationTestRunner (target=simple.target.app)
If you don't see the line corresponding to your test, you need to install the test APK. If it's installed, double check that part of the test.simple.uiatest/android.test.InstrumentationTestRunner
output pm list instrumentation
matches your command am instrument
.
source to share