我正在尝试测试应用程序,我需要隐藏键盘,因为我无法点击按钮.所以,我在build.gradle中添加了Espresso:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
Run Code Online (Sandbox Code Playgroud)
并试图从android.support.test.espresso.action.ViewActions库中使用它:
ViewActions.closeSoftKeyboard();
Run Code Online (Sandbox Code Playgroud)
测试成功运行,但在我的布局中的EditText中键入一些文本后失败.键盘仍在那里,显示出来.
我浪费了两天时间尝试在全屏活动上执行点击操作.
为活动写一个espresso测试以执行点击
public class FullscreenActivityTest
extends ActivityInstrumentationTestCase2<FullscreenActivity> {
public FullscreenActivityTest() {
super(FullscreenActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
getActivity();
}
public void testClickingOnLayout() {
onView(withId(R.id.fullscreen_content)).perform(click());
}
Run Code Online (Sandbox Code Playgroud)
}
android.support.test.espresso.PerformException:
Error performing 'click' on view 'with id: com.example.espressodefect:id/fullscreen_content'
...
Caused by: android.support.test.espresso.PerformException:
Error performing 'Send down montion event' on view 'unknown'.
...
Caused by: android.support.test.espresso.InjectEventSecurityException: java.lang.SecurityException:
Injecting to another application requires INJECT_EVENTS permission
Run Code Online (Sandbox Code Playgroud)
满堆栈在这里.
我试过以下没有运气:
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)