gpt4 book ai didi

android - 为什么我使用 sendKeys() 的测试在 Android 模拟器中没有动画?

转载 作者:行者123 更新时间:2023-11-29 18:06:29 24 4
gpt4 key购买 nike

当我在 Android 模拟器中运行以下测试时,输入值未显示在 EditText 中。为什么不呢?我需要更改什么才能在模拟器中看到输入? (测试通过,所以最后,这可能并不重要。我只是希望能够在模拟器中看到它实际发生。)

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());
}
});
}

最佳答案

查看官方开发指南 - Activity Testing .

1 确保触摸模式已关闭:

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 确保屏幕已解锁:

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();

关于android - 为什么我使用 sendKeys() 的测试在 Android 模拟器中没有动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13169260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com