最近在跑InstrumentedTest例子,发现官网以下代码无法通过typeText方法自动输入大写字母,即输入的是Expresso但输入框显示 espresso,最终导致Assert失败。
onView(withId(R.id.editTextUserInput))
.perform(typeText("Espresso"), closeSoftKeyboard())
onView(withId(R.id.changeTextBt)).perform(click())
效果如下:
经查询得知,使用Instrumentation#sendStringSync方法,并且加上延时。
最终代码如下:
// 延时输入,否则输入的首字母缺失
Thread.sleep(2000)
InstrumentationRegistry.getInstrumentation().sendStringSync(stringToBeTyped)
最后看下效果。
测试通过。
版权声明:本文为m0_48179608原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。