Mobile Testing Background
Have you ever been in a situation where you’re trying to hail a car service or find a nearby coffee shop and your phone location has you a few blocks away, and the circle covers a two miles radius? Understandably, it drives users nuts! This is why it’s important to have mobile testing for your location-based app.
Many applications behave differently depending on the availability and accuracy of location services. These would include locations based on the cellular network or GPS. Referring to the example mentioned, the quality of your application and certainly the user satisfaction heavily depend on the service your app provides in these conditions. These services need to be included in test automation, to the degree made possible by the OS vendor.
Luckily, Android does offer the ability to programmatically enable/disable GPS and network location. Before we go into details, please note:
- iOS (to the best of my knowledge) does not support this functionality
- The below discussion is about Android 6.0+
- You are likely to see popups, especially when enabling previously disabled location services. Make sure you handle that in your script.
Mobile Testing Implementation
First, the relevant ADB commands are:
To Enable use :
For GPS : adb shell settings put secure location_providers_allowed +gps
For Network : adb shell settings put secure location_providers_allowed +network
To Disable :
GPS : adb shell settings put secure location_providers_allowed -gps
For Network : adb shell settings put secure location_providers_allowed -network
In my project I am using the following classes:
In order to execute the ADB commands, in PerfectoUtils.Java:
Some additional, helpful commands also in PerfectoUtils.Java:
And finally, the main code is in setLocationProviderClass.java, testLocationSettings():
You will notice that I’m toggling back to the home screen and then swiping down in order to see the settings:
Figure 2: Location providers disabled
Figure 3: Location providers enabled
Mobile Testing Summary
Location services impact the user experience. It is important to ensure quality by thorough testing of the application when location services are enabled, disabled, or different providers (GPS, network) are enabled or disabled. Test automation is ideal to cover these scenarios. This post is referencing data from my latest project- click here to review.