浓咖啡-全屏活动执行操作失败-InjectEventSecurityException [英] Espresso - Perform action fails on fullscreen activity - InjectEventSecurityException
问题描述
我浪费了两天时间试图对全屏活动执行点击操作.
I wasted two days trying to perform click action on a fullscreen activity.
- 使用全屏活动代码模板在android studio中创建新项目
-
为该活动编写浓咖啡测试以执行点击
- Create a new project in android studio using fullscreen activity code template
Write an espresso test for the activity to perform click
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());
}
}
失败
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
完整堆栈位于此处.
我没有运气尝试过以下方法:
I have tried the following with no luck:
- 模拟器上没有锁定屏幕. (还使用
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
更新了活动
- 所有动画均已关闭
- 没有屏幕键盘,或应用程序顶部没有覆盖的任何东西.
- 还遵循了此处上的说明.
- JUnit3和JUnit4样式(AndroidJUnitRunner)
-
<uses-permission>
代表INJECT_EVENTS
- No lock screen on the emulator. (also updated activity using
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
- All animations turned off
- No on-screen keyboard, or anything overlayed on top of the app.
- Also followed instructions here at developer.android.com
- JUnit3 and JUnit4 styles (AndroidJUnitRunner)
<uses-permission>
for INJECT_EVENTS
在浓缩咖啡测试中,如果我使用非全屏活动(如使用空白活动创建的活动),则执行操作的效果会很好.全屏上的相同操作失败.
In espresso test, performing actions work fine if I use non-fullscreen activity like the one created with blank activity. Same action on full screen fails.
我正在使用Espresso 2.0和支持库.
I am using Espresso 2.0 and support libraries.
我在做什么错了?
Espresso开发人员确认这是缺陷.请参阅问题140 .
Espresso dev confirmed this as defect. Please see issue 140.
推荐答案
此错误已在Espresso的最新版本中解决:
This bug was solved in the last release of Espresso:
Espresso 2.2.2,Runner/Rules 0.5(2016年2月22日,静默发布)-
Espresso 2.2.2, Runner/Rules 0.5 (2016-02-22, silent release) - https://google.github.io/android-testing-support-library/downloads/release-notes/index.html
在我的项目中,我已将/app/build.grandle中的依赖项从以下位置更改:
In my project, i've changed the dependency in the /app/build.grandle from:
androidTestCompile'com.android.support.test.espresso:espresso-core:2.1'
到
androidTestCompile'com.android.support.test.espresso:espresso-core:2.2.2'
在AndroidStudio中:Grandle Scripts => build.gradle文件
这篇关于浓咖啡-全屏活动执行操作失败-InjectEventSecurityException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!