my espresso instrumentation test can't click an ImageView:
Error performing 'single click' on view 'with id: com.example.test:id/btnNext'.
Caused by: android.support.test.espresso.PerformException: Error performing 'click (after 3 attempts)' on view 'unknown'.
Caused by: android.support.test.espresso.InjectEventSecurityException: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
But what is strange that just three lines before it is able to click another ImageView looking quite similar to me. And using the app as human works as well.
Here is my minimal non-working example, do you see the error?
@RunWith(AndroidJUnit4.class)
@LargeTest
public class TestTest {
@Rule
public ActivityTestRule<TestActivity> _activityRule = new ActivityTestRule<TestActivity>(
TestActivity.class);
@Test
public void testClicking() {
onView(withId(R.id.btnPrevious)).perform(click());
onView(withId(R.id.btnNext)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.btnNext)).check(matches(isClickable()));
onView(withId(R.id.btnNext)).perform(click()); // This line throws an exception
}
}
The activity to test:
public class TestActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity);
}
}
And the layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:id="@+id/lytFooter">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnPrevious"
app:srcCompat="@drawable/left_arrow_shadow"
android:layout_margin="1dp"
android:layout_gravity="center_vertical"
android:background="@drawable/lightbutton_selector"
android:focusable="true"/>
<TextView
android:id="@+id/txtBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/look_around"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:gravity="center_horizontal"
style="@style/CameraText" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/prgVideoMode"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:gravity="center_horizontal"
android:max="100" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnNext"
app:srcCompat="@drawable/left_arrow_shadow"
android:layout_margin="1dp"
android:layout_gravity="center_vertical"
android:background="@drawable/lightbutton_selector"
android:focusable="true"
android:clickable="true"/>
</LinearLayout>
</RelativeLayout>
The full stracktrace is 80 lines long so I posted it here if you are interested: http://pastebin.com/RWa91G63