Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click on Android Gallery with Espresso

We currently have an Android application that we are testing with Espresso. One of the features we want to test is selecting a picture/image from the local image gallery. We can get all the way to bringing up the Gallery view, but then cannot select from Recent, Downloads, Gallery in the resulting window. A snippet as to how we got as far as we did is included below.

public void testShouldBeAbleToSelectPhotoFromGallery() {

    getActivity();

    // given
    onView(withId(launch_gallery_button)).perform(click());
    onView(withText("Gallery")).perform(click());  // this is a button in our app
    // then we get stuck :(
}

Thanks!

like image 552
user3298441 Avatar asked Oct 20 '14 15:10

user3298441


1 Answers

This is not possible with with either Robotium or Espresso, as they only work on Activities of the app under test.

To write integration tests that work across different apps and Android built-in apps, you can use the UiAutomator framework provided by Google.

Basically you would analyse the gallery app in the uiautomatorview to learn how to select the ui elements your test case needs and then act on them, not unlike Espresso.

like image 125
haffax Avatar answered Sep 25 '22 06:09

haffax