I'm working on some UI testing with Espresso on a map based application that use the user location.
Setup
- MapBox is used for the map component, no Google Map component used here.
- Google Play services libraries are used for localization purposes
- Tests using Espresso
- Mock used to fake the location (can be found here: How to write Espresso Tests which are mocking GPS locations and use them in Google Testlab?)
- Tests run remotely on Firebase test Lab on a virtual device.
Actual results / Problem
It works: the user location is then faked to the lat long I coded. But after a while I get some trouble. After few tests I get a system popup that seems to be triggered by com.google.android.gms:play-services
that is embbeded in our application.
The message is "For a better experience, turn on device location, which uses Google's location service." as you can see on the picture below :
So it seems that the mocking code trigger somehow this popup and then ruins all the remaining tests since the popup does not dismiss until clicked on one of the buttons.
UI Automator: not a proper solution
I know I could add a bit of code with UI Automator in order to validate the popup but I would like to avoid this workaround since:
- I don't know what trigger this popup (seems random)
- I don't want to run some crappy/duplicated code before running each test just for that popup.
- Actually I am not using UI Atomator for my tests and I don't want to import another library to my project.
Please note that I cannot reproduce this problem on my device or my emulator but only when I run my tests on gcloud (Firebase Test Lab)...
Question
Have you ever faced this problem ? Do you have any idea how I can avoid this popup or any workaround that is not involving UI Automator?
One More Thing
Please remember that i'm running tests remotely, on a virtual device that is not logged into any Google Account. Also, I don't have access to the device system/settings but eventually I should be able to use ADB command to get some rights or apply some settings to the system.
Bad news
Actually the mock location is partially supported on Firebase Test Lab on virtual devices. See my comment below for more information.
So depending the use case, switching to a real device can solve your problem like the problem mentionned in this topic.