Espresso - typeText() not working correclty, sometimes letters are missing

旧街凉风 提交于 2019-12-23 08:02:25

问题


I start my login activity and I use in Espresso test:

onView(withId(R.id.username)).perform(typeText("USERNAME"));

I expect the text in the field to be "USERNAME", but sometimes I get "SERNAME", others "UERNAME".

Most of the times it works but sometimes it fails, specially after rebooting the phone.

Here is the sample code to reproduce the bug: https://github.com/neoranga55/CleanGUITestArchitecture


回答1:


The test phone uses Swift keyboard with double language typing enabled. Apparently this causes the first appearance of the keyboard after phone boot to be slow but also auto-correct in a weird way the first letters of a word typed by Espresso.

Solution: always use default system keyboard on testing device/emulator and make sure a software keyboard is enabled to avoid this other issue.




回答2:


You can also try replaceText(). It should not be affected by the slow IME:

onView(withId(R.id.username)).perform(replaceText("USERNAME"));



来源:https://stackoverflow.com/questions/32667781/espresso-typetext-not-working-correclty-sometimes-letters-are-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!