android - 我无法让 ViewActions.closeSoftKeyboard() 在 Espresso 2.2.2 中工作

标签 android unit-testing testing android-espresso

我正在尝试测试一个应用程序,我需要隐藏键盘,因为我因此无法点击按钮。所以,我在 build.gradle 中添加了 Espresso:

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

并尝试从 android.support.test.espresso.action.ViewActions 库中使用它:

ViewActions.closeSoftKeyboard();

测试成功运行,但在我的布局中的 EditText 中键入一些文本后失败。键盘还在那里,正在显示。

附言在 reading this answer. 之后我意识到这是键盘的错

最佳答案

ViewAction 本身不会执行任何操作,除非在 ViewInteraction 中使用它。这意味着您需要将它与您之前在 perform() 中的操作链接起来,如下所示:onView()..perform(typeText(..), closeSoftKeyboard()) 或使用 Espresso 类中的内置助手,如下所示:Espresso.closeSoftKeyboard()

关于android - 我无法让 ViewActions.closeSoftKeyboard() 在 Espresso 2.2.2 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39580415/

相关文章:

android - 为 QLineEdit 选择输入键盘类型

c# - 在 windows phone 7 模拟器上模拟连接不稳定进行测试

java - 将字段添加到枚举

android - Remoteview showNext() 和 showPrevious() 中的 ViewFlipper 不工作

javascript - Framework7 上未显示涟漪效果和图标

android - 当键盘弹出时,TextField 被隐藏

c# - Visual Studio 中的 TestContext - 它有什么作用?

java - 在同一对象中测试方法时如何模拟对象中的方法

unit-testing - 打开 NUnit 的卷影复制时,如何将资源(任何内容)文件复制到输出文件夹?

php - 在任何其他测试之前运行的 Symfony 测试?