java Espresso并没有等待键盘打开
我有一个浓缩咖啡测试,我的屏幕下面有一个EditText
和一个skipButton
。
当我启动活动时,键盘弹出打开,集中在EditText
上,并与Button
重叠
现在我想为skip按钮编写一个测试,并断言之后会发生什么
问题在于,浓缩咖啡不会等待键盘打开
所以发生的是
- Espresso没有等待键盘并按下“跳过”
- 键盘滑开
- 对现在位于键盘下方的内容的断言失败
代码如下所示:
public void givenSkipped_whenConfirmed_thenMainActivityLaunched() {
Espresso.closeSoftKeyboard();// <- Not working as espresso seems to think it is not open yet
skipPostcodeEntry.perform(click()); //<- Can click this as keyboard is not open yet.
warningText.check(matches(withText(R.string.some_text)));
confirmationButton.perform(click());//<- Fails as this is now overlapped by KB
Assert.DoesSomething()
}
我发现了一个问题,意式浓缩咖啡是not waiting for the keyboard to close的,但没有什么关于它不等待键盘打开
有人解决了这个问题吗
编辑:
当您查看closeSoftKeyboard
方法时,可以找到一个名为CloseKeyboardAction
的类。您可以看到,当键盘未被识别为打开时,它甚至会记录日志
Log.w(TAG, "Attempting to close soft keyboard, while it is not shown.");
# 1 楼答案
不幸的是,目前看来浓缩咖啡无法检查键盘是否在屏幕上!(https://groups.google.com/forum/#!topic/android-platform/FyjybyM0wGA)
作为一种解决方法,我们要做的是检查应该有焦点的输入字段,然后关闭键盘。这可以防止Espresso在键盘出现在屏幕上之前调用closeSoftKeyboard()
然后将EspressoExtensions添加到您的项目中:
希望这能有所帮助,直到浓缩咖啡能够判断键盘是否在屏幕上