Testing Google Android Places Autocomplete with Espresso


I’m struggling with instrumental ui test of a PlaceAutocomplete API, provided by Google.

What I’m trying to test is ability to open AutoComplete Activity (fired with proper button), enter some text, pick result from given list and check if picked position is listed on the recyclerview.

I’m trying to target this EditText below 🙁

Screenshot of ui automater


                .perform(typeTextIntoFocusedView("kotek"), closeSoftKeyboard());

And other variations, like withText “Szukaj” or with com.google.android.gms.R.id 🙂 without luck.

Help will be appreciated! Thank You!


This view is auto-generated by Google Api.

If it’s true, sorry I haven’t any experience with Places API, it would mean that Espresso is unable to find this view.

Solution: Espresso Test Recorder

You can install the latest Android Studio 2.2-RC2 (don’t remove the previous) from: http://tools.android.com/download/studio/builds/2-2-rc to check brand new Espresso Test Recorder (check: http://tools.android.com/tech-docs/test-recorder) and try to get this view by click on this to generate code, but I said this might not help.

Solution: Espresso with uiatomator

My doubts about it come from Espresso framework limitation – it depends on actual context of app, it means that it may not recognize intents, genereated code or notifications.

Try to use typical instrumentation framework like Google’s uiatomator. There’s no problem to use it along with Espresso UI testing framework.

Read: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html

More info you would find here: http://google.github.io/android-testing-support-%20/docs/uiautomator/

Solution: Espresso with Robotium or Robotium Test Recorder

If you find uiatomator a pretty hard to learn you can also use another instrumentation test framework called Robotium, which has clean and conchise syntax with some powerfull functions like taking screenshots.

It can work along with Espresso. Check last paragraph of this article: https://github.com/codepath/android_guides/wiki/UI-Testing-with-Robotium

It also has its own recorder: http://robotium.com/products/robotium-recorder. Try it for free, but I doubt that you would find it useful, as Robotium code is really simple to learn.

Hope it will help

Answered By – piotrek1543

Leave a Comment