Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Mobile Testing of Location Powered Android Apps

DZone's Guide to

Mobile Testing of Location Powered Android Apps

This tutorial walks you through test automation when location services are enabled or disabled, and with both GPS and Network, to ensure a good user experience.

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

Have you ever been in a situation where you’re trying to hail a car service or find a nearby coffee shop, but your phone location has you a few blocks away, and the circle covers a two-mile radius? Understandably, it drives users nuts!

Figure 1: Location accuracy could impact where your driver would pick you up.

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 and 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.

Implementation

First, the relevant ADB commands:

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 use:

  • 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 locationSettings.java: 

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.

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 for these scenarios. This post references data from my latest project- click here to review.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:
mobile ,mobile app testing ,android apps ,location based apps ,geolocation

Published at DZone with permission of Amir Rozenberg, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}