Reputation: 83557
When I run the following test in the Android emulator, the input value doesn't show up in the EditText. Why doesn't it? And what do I need to change so that I can see the input in the emulator? (The test passes, so in the end, it probably doesn't matter. I just would like to be able to see it actually happen in the emulator.)
public void testOkButtonOnClickWithUserInputNumber() throws Throwable {
this.sendKeys(Integer.toString(this.testNumber)); // 123
this.runTestOnUiThread(new Runnable() {
@Override
public void run() {
Assert.assertTrue(NumberFilterTest.this.okButton.performClick());
}
});
this.getInstrumentation().waitForIdle(new Runnable() {
@Override
public void run() {
Assert.assertTrue(NumberFilterTest.this.activity.isFinishing());
}
});
}
Upvotes: 1
Views: 1142
Reputation: 41126
Check out official dev guide - Activity Testing.
1 Make sure touch mode is turned off:
To control the emulator or a device with key events you send from your tests, you must turn off touch mode. If you do not do this, the key events are ignored.
ActivityInstrumentationTestCase2.setActivityTouchMode(false);
2 Make sure screen is unlocked:
You may find that UI tests don't work if the emulator's or device's home screen is disabled with the keyguard pattern. This is because the application under test can't receive key events sent by sendKeys().
mKeyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); mLock = mKeyGuardManager.newKeyguardLock("activity_classname"); mLock.disableKeyguard();
Upvotes: 3