I wasted two days trying to perform click action on a fullscreen activity.
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
Full stack is here.
I have tried the following with no luck:
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
<uses-permission>
for INJECT_EVENTSIn 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.
I am using Espresso 2.0 and support libraries.
What am I doing wrong here?
Espresso dev confirmed this as defect. Please see issue 140.
This bug was solved in the last release of 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
In my project, i've changed the dependency in the /app/build.grandle from:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
to
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
In AndroidStudio: Grandle Scripts => build.gradle file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With