Created
December 23, 2019 22:37
-
-
Save dpgraham/7f57a527dcea436043415b60a6951390 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Versions of Appium above v1.9.1 and below v1.16.0 have a bug in `setLocation` and `getLocation` that looks like this: | |
``` | |
2019-12-23 21:57:26:835 - [HTTP] --> GET /wd/hub/session/372d6e4d-279a-4582-ab6d-90804845bcb0/location | |
2019-12-23 21:57:26:835 - [HTTP] {} | |
2019-12-23 21:57:26:836 - [debug] [MJSONWP (372d6e4d)] Calling AppiumDriver.getGeoLocation() with args: ["372d6e4d-279a-4582-ab6d-90804845bcb0"] | |
2019-12-23 21:57:26:837 - [debug] [ADB] Running '/home/chef/android-sdk-linux/platform-tools/adb -P 5037 -s emulator-5554 shell am broadcast -n io.appium.settings/.receivers.LocationInfoReceiver -a io.appium.settings.location' | |
2019-12-23 21:57:26:924 - [debug] [MJSONWP (372d6e4d)] Encountered internal error running command: Error: Cannot parse the actual location values from the command output: Broadcasting: Intent { act=io.appium.settings.location flg=0x400000 cmp=io.appium.settings/.receivers.LocationInfoReceiver } | |
2019-12-23 21:57:26:924 - [debug] [MJSONWP (372d6e4d)] Broadcast completed: result=0, data="" | |
2019-12-23 21:57:26:924 - [debug] [MJSONWP (372d6e4d)] at ADB.getGeoLocation (/home/chef/appium/appium-v1.15.0/appium-v1.15.0/node_modules/appium-android-driver/node_modules/appium-adb/lib/tools/adb-commands.js:968:11) | |
2019-12-23 21:57:26:926 - [HTTP] <-- GET /wd/hub/session/372d6e4d-279a-4582-ab6d-90804845bcb0/location 500 91 ms - 402 | |
``` | |
The workaround for this is to add this snippet of code: | |
```python | |
def updateSettingsApp(): | |
# Get rid of the broken io.appium.settings apk | |
driver.remove_app('io.appium.settings'); | |
# Install the patched io.appium.settings apk | |
driver.install_app('https://github.com/appium/io.appium.settings/releases/download/v2.16.2/settings_apk-debug.apk') | |
# Set the permissions on the app to allow location services | |
driver.execute_script('mobile: shell', { | |
'command': 'pm', | |
'args': ['grant', 'io.appium.settings', 'android.permission.ACCESS_COARSE_LOCATION'], | |
'includeStderr': True, | |
'timeout': 5000 | |
}) | |
driver.execute_script('mobile: shell', { | |
'command': 'pm', | |
'args': ['grant', 'io.appium.settings', 'android.permission.ACCESS_FINE_LOCATION'], | |
'includeStderr': True, | |
'timeout': 5000 | |
}) | |
``` | |
And call `updateSettingsApp` after session is initialized (and before any call to `getLocation` or `setLocation`). | |
The snippet is written in Python but can be adapted to any other Appium client languages. Just look for documentation for: | |
* [Remove App](http://appium.io/docs/en/commands/device/app/remove-app/) | |
* [Install App](http://appium.io/docs/en/commands/device/app/install-app/) | |
* [Execute Script](http://appium.io/docs/en/commands/mobile-command/) | |
This workaround is unnecessary for Appium 1.16.0 and above as it will already have the patched settings app. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment