我浪费了两天时间尝试对全屏活动执行点击操作。
为要执行的活动编写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());
}
}
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
完整筹码是here。
我试过以下但没有运气:
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
<uses-permission>
在espresso测试中,如果我使用非全屏活动(例如使用空白活动创建的活动),则执行操作可以正常工作。全屏幕上的相同操作失败。
我正在使用Espresso 2.0并支持库。
我在这里做错了什么?
Espresso dev证实这是缺陷。请参阅issue 140。
答案 0 :(得分:4)
这个错误在Espresso的最后一个版本中得到了解决:
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中的依赖项:
androidTestCompile&#39; com.android.support.test.espresso:espresso-core:2.1&#39;
到
androidTestCompile&#39; com.android.support.test.espresso:espresso-core:2.2.2&#39;
在AndroidStudio中:Grandle Scripts =&gt; build.gradle文件