Skip to content

How to stop Android Location Accuracy popup displaying in Appium test

0

I'm writing tests for an Android app in Device Farm using webdriverio and Appium (in TypeScript). We recently added a request for location permissions to the app. When I run tests on Device Farm now I'm getting a popup in the tests asking for Location Accuracy to be enabled.

Location Accuracy popup on Android 15 For a better experience, your device will need to use Location Accuracy The screenshot is from the end of a test run after our app has been closed. The popup displays when the user logs into our app and the app would be requesting to use location permissions.

Is there any way to enable Location Accuracy before the test is run or a workaround to stop it displaying? Form the answers I've found by searching it seems not but I thought I would ask here if anyone had a workaround. I'd like to avoid adding code into the test to accept the popup if possible since the popup doesn't seem to be consistent on different Android devices.

I'm using UiAutomator2 and have autoGrantPermissions enabled in my wdio.conf file capabilities.

I've tried adding a call to Appium's setGeoLocation method into my test. This worked when testing on a local physical device and stopped the popup, but I get an error on Device Farm that its not available.

    await driver.execute('mobile: setGeolocation', {
      latitude: 51.5074,
      longitude: -0.1278,
      altitude: 10
    });

This gives this error when the test runs on Device Farm (apparently it doesn't support setGeoLocation)

unknown command: Unknown mobile command "mobile: setGeolocation". Only shell, execEmuConsoleCommand, dragGesture, flingGesture, doubleClickGesture, clickGesture, longClickGesture, pinchCloseGesture, pinchOpenGesture, swipeGesture, scrollGesture, scrollBackTo, scroll, viewportScreenshot, viewportRect, deepLink, startLogsBroadcast, stopLogsBroadcast, deviceidle, acceptAlert, dismissAlert, batteryInfo, deviceInfo, getDeviceTime, changePermissions, getPermissions, performEditorAction, startScreenStreaming, stopScreenStreaming, getNotifications, openNotifications, listSms, type, replaceElementValue, pushFile, pullFile, pullFolder, deleteFile, isAppInstalled, queryAppState, activateApp, removeApp, terminateApp, installApp, clearApp, backgroundApp, getCurrentActivity, getCurrentPackage, startActivity, startService, stopService, broadcast, getContexts, getAppStrings, installMultipleApks, lock, unlock, isLocked, refreshGpsCache, startMediaProjectionRecording, isMediaProjectionRecordingRunning, stopMediaProjectionRecording, getConnectivity, setConnectivity, toggleGps, isGpsEnabled, hideKeyboard, isKeyboardShown, pressKey, getDisplayDensity, getSystemBars, fingerprint, sendSms, gsmCall, gsmSignal, gsmVoice, powerAc, powerCapacity, networkSpeed, sensorSet, getPerformanceData, getPerformanceDataTypes, statusBar, screenshots, scheduleAction, getActionHistory, unscheduleAction, getUiMode, setUiMode, sendTrimMemory commands are supported.

I've also tried explicitly setting the location in the schedule-run command --configuration parameter but that didn't stop the popup either.

aws devicefarm schedule-run --project-arn [other params omitted] --configuration '{"locale":"en_US","location":{"latitude": 51.5074,"longitude": -0.1278},"customerArtifactPaths":{"deviceHostPaths":["$WORKING_DIRECTORY"]},"billingMethod":"METERED","radios":{"bluetooth":false,"gps":true,"nfc":true,"wifi":true}}' --execution-configuration '{"videoCapture":true,"skipAppResign":false,"jobTimeoutMinutes":5}'

Thanks in advance!

asked a month ago32 views
2 Answers
0

Based on the information provided, there isn't a direct method in AWS Device Farm to prevent the Android Location Accuracy popup from displaying during your Appium tests.

The approaches you've tried so far:

  1. Using autoGrantPermissions in your capabilities - this handles basic permissions but not the Location Accuracy popup specifically
  2. Using Appium's setGeolocation method - this works locally but isn't supported in Device Farm as shown by the error message
  3. Setting location in the AWS Device Farm schedule-run command - this didn't prevent the popup

Since Device Farm has limited support for certain Appium commands (as evidenced by the error message listing only supported commands), you may need to handle this popup programmatically in your tests. While you mentioned wanting to avoid adding code to handle the popup, it might be the most reliable solution given the constraints.

You could try:

  1. Adding code to detect and dismiss the popup when it appears
  2. Using custom test environments in Device Farm with a test spec that might allow you to configure location settings before your tests run
  3. Exploring if any of the supported mobile commands like changePermissions or getPermissions could help with this specific scenario

Unfortunately, there doesn't appear to be a straightforward way to prevent this popup from appearing in Device Farm without handling it within your test code.
Sources
Speeding up Appium-based tests in Device Farm through desired capabilities - AWS Device Farm

answered a month ago
0

I've tried a few more settings and found that the deprecated method driver.setGeoLocation() still works and stops the popup displaying. I've added this function to my setup that gets called before the user logs into our app and is prompted for the location permissions.

Ideally the driver.execute('mobile: setGeolocation') version above would work so if its possible to add support for this in future that would be great.

  static async setLocation(latitude: number = 51.5074, longitude: number = -0.1278) {
    await driver.setGeoLocation({ latitude, longitude }); 
  }

Before this I also tried adding mockLocationApp to the wdio conf capabilities to see if it stopped the popup but it didn't.

capabilities: [{
        // capabilities for local Appium web tests on an Android Emulator
        platformName: 'Android',
        'appium:automationName': 'UiAutomator2',
        'appium:deviceName': 'Android',
        'appium:autoGrantPermissions': true,
        'appium:mockLocationApp': 'io.appium.settings'
    }],

I also tried revoking the ACCESS_FINE_LOCATION permission for the app to see if that stopped the app Location Accuracy prompt but it didn't work either.

await driver.execute('mobile: changePermissions', {
  appPackage: 'com.example.myapp', 
  permissions: [
    'android.permission.ACCESS_FINE_LOCATION',
  ],
  action: 'revoke'
});
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.