espresso : code to pick a single image from gallery / or capture image using camera

1,537 views
Skip to first unread message

SK

unread,
Jul 21, 2016, 2:21:22 PM7/21/16
to Android Testing Support Library
I am trying to use intents to pick a single image from library.
When I run the code, the image does not get picked.

Can someone help me with the code that worked for them using Camera / picking image from gallery?


 Bundle bundle = new Bundle();
ArrayList<Parcelable> parcels = new ArrayList<>();
Intent resultData = new Intent();
// Uri uri1 = Uri.parse("file://mnt/sdcard/img01.jpg");
Uri uri1 = Uri.parse("file://storage/extSdCard/DCIM/Camera/esp.jpg");
Parcelable parcelable1 = (Parcelable) uri1;
parcels.add(parcelable1);
bundle.putParcelableArrayList(Intent.EXTRA_STREAM, parcels);
// Create the Intent that will include the bundle.
resultData.putExtras(bundle);

intending(not(isInternal())).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData));


Jose Alcérreca

unread,
Jul 21, 2016, 2:51:42 PM7/21/16
to SK, Android Testing Support Library
Hi SK, this mailing list is for questions about the development of the ATSL. Please check out http://google.github.io/android-testing-support-library/support/index.html


Jose Alcérreca | Developer Programs Engineer | ja...@google.com | Google+


--
You received this message because you are subscribed to the Google Groups "Android Testing Support Library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-testing-suppo...@googlegroups.com.
To post to this group, send email to android-testing...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-testing-support-library/40856ff9-2866-4298-b1ef-c93b40d1358f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis Ramirez

unread,
Jul 21, 2016, 8:15:22 PM7/21/16
to SK, Android Testing Support Library

On Thu, Jul 21, 2016 at 1:21 PM, SK <sana...@gmail.com> wrote:
I am trying to use intents to pick a single image from library.
When I run the code, the image does not get picked.

Can someone help me with the code that worked for them using Camera / picking image from gallery?

You might have to clarify your intention. You can't "pick a single image from library" with Espresso - it works within your own app's process.

What you can do - and what it looks like you're setting up - is simulate picking an image, to ensure your code responds to it correctly. To that end, your code is incomplete. After setting up the result you want to respond with, you need to trigger the intent you're looking for (for example, click the button that launches the picker intent), and then assert that your code does the right thing with it.

The documentation has a very clear example of this:

If you do want to interact with the on-device image chooser, to simulate really choosing an image, then you need to go through UIAutomator. But that will be less reliable as it will depend on the particular image picker app that is available on the particular device.

Hope that helps.
Reply all
Reply to author
Forward
0 new messages