iOS Appium and location services popup

3485 views
Skip to first unread message

isonic1

unread,
May 1, 2013, 11:10:42 AM5/1/13
to appium-...@googlegroups.com
This is a bit puzzling. My app requires location services to be enabled. When launching my test script using Appium , the location services popup gets closed (taps Cancel button) automatically. I assume it's using the default button behavior built into UIAutomation. However, I've noticed on other popups that occur in my app, Appium keeps them opened and does not use the default button behavior then. My location services popup occurs about 8 seconds after launching the app, this is enough time for my UIAutomation scripts to override the default button behavior (clicking OK) but doesn't look like it's enough time for Appium to control it. 

1. Is there a way to inject the UIAutomation java script inside of the appium script directly? If this is possible, I could use the override js code to tap the location services OK button. I'd love see an example if anyone has one. I'm using ruby.

2. Is there an Appium specific method to handling location services? I doubt it but thought I'd ask.

3. Is it possible to toggle Appiums handling of popups? Appium leaves the popups up always (except for what I said above) which is good an bad. Bad because you may get a popup you don't expect, but good because you wont need to worry about overriding the default button. Sorta a catch 22 I guess.

Amit Rawat

unread,
May 1, 2013, 11:30:10 AM5/1/13
to appium-...@googlegroups.com
I think there is no way to handle this pop up on a real device but for simulator you can write some code in Apple Script to handle this pop up and you can call this applescript from your Ruby code.

Please refer this link to create that apple script:

Satyajit Malugu

unread,
May 1, 2013, 11:37:34 AM5/1/13
to appium-...@googlegroups.com
I had trouble with location services popup dialog and the work around I did is to not uninstall the app. Once an app got that permission it stays. I doubt I will get a buy in from devs for the 8 sec delay because our app is very location centric. 

Regarding 3 yes appium can and has handled popups. In the apples UIAutomation framework it is a onevent listener but the wrappers appium have in javascript and ruby handled these under the covers. Run the sample tests and you will see number of popups being handled. 

Dan Cuellar

unread,
May 1, 2013, 11:38:00 AM5/1/13
to appium-...@googlegroups.com
I believe you can handle these with raw UIAutomation commands using ExecuteScript. You have to look at Apple's UIAAlert class reference

isonic1

unread,
May 1, 2013, 12:02:23 PM5/1/13
to appium-...@googlegroups.com
Thanks. Yeah, for the most part when I'm running appium on my local machine, accepting the location services manually gets me by. However, I want to run my tests in CI or even on sauce labs so I'll need to enable location services via my ruby appium script, similar to what I did in UIAutomation directly. thanks.
Message has been deleted
Message has been deleted

Igor Dorovskikh

unread,
May 28, 2013, 3:33:34 AM5/28/13
to appium-...@googlegroups.com
There is another way to suppress location service popup on Simulator. All you have to do is to accept Location Service once you start your app. Then, you have to copy clients.plist from /Users/#{ENV['USER']}/Library/Application Support/iPhone Simulator/#{ENV['SDK']}/Library/Caches/locationd/clients.plist
to you project directory. 
Once you have the clients.plist, write a script in you tests setup that would copy it every time to you Simulator before each test execution.
Here is example in Ruby:

location_service_dir = "/Users/#{ENV['USER']}/Library/Application Support/iPhone Simulator/#{ENV['SDK']}/Library/Caches/locationd/clients.plist"
FileUtils.copy '../Appium/clients.plist', "#{location_service_dir}"

On Wednesday, May 1, 2013 8:10:42 AM UTC-7, isonic1 wrote:

Satyajit Malugu

unread,
May 28, 2013, 9:14:00 AM5/28/13
to Igor Dorovskikh, appium-...@googlegroups.com
That's very sharp, will try it today.

-Satyajit
--
http://appium.io
---
You received this message because you are subscribed to a topic in the Google Groups "Appium-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/appium-discuss/k5gbfVFRPsE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

satyajit malugu

unread,
May 28, 2013, 1:29:48 PM5/28/13
to Igor Dorovskikh, appium-...@googlegroups.com
This didn't work for me, can you send me your client.plist file, though not completely this file partially makes sense.

Also below the order should be reversed, correct?


FileUtils.copy '../Appium/clients.plist', "#{location_service_dir}"

And this clients.plist file should go to the .app folder for the app in question or to the simulator/appium. I am not clear of your ../Appium directory

May 28, 2013 6:14 AM
That's very sharp, will try it today.

-Satyajit

On May 28, 2013, at 12:33 AM, Igor Dorovskikh <idor...@gmail.com> wrote:

May 28, 2013 12:33 AM

Satyajit Malugu

unread,
May 28, 2013, 2:35:32 PM5/28/13
to appium-...@googlegroups.com, Igor Dorovskikh
This - http://stackoverflow.com/questions/6452492/how-can-i-request-standard-pop-up-use-current-location-with-plist

seems to say that its not possible. Would love to know otherwise. 

Igor Dorovskikh

unread,
May 28, 2013, 5:11:39 PM5/28/13
to appium-...@googlegroups.com, Igor Dorovskikh
Make sure that Simulator is turned off while your script is coping your plist. BTW, the order is correct -- you should copy plist you saved into your project to simulator before each test execution. Sorry...I can't share with plist...company policy :(

Satyajit Malugu

unread,
May 31, 2013, 1:00:24 PM5/31/13
to appium-...@googlegroups.com, Igor Dorovskikh
I am really confused now. Did anyone else were able to make this working?

My questions
  1. Are we copying the clients.plist file to the .app folder or to simulator cache (back again)
  2. What is the ../Appium folder above - how does it contain clients.plist file in the first place

Satyajit Malugu

unread,
May 31, 2013, 1:05:06 PM5/31/13
to appium-...@googlegroups.com, Igor Dorovskikh
And the biggest question. Can I make this work on sauce cloud. File copying on the cloud to the simulator cache folder?

Jonathan Lipps

unread,
May 31, 2013, 1:31:42 PM5/31/13
to Satyajit Malugu, appium-...@googlegroups.com, Igor Dorovskikh
You won't be able to make this work yourself on Sauce but once we update appium with the set location services desired capability, it will work on Sauce as well.

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.

Satyajit Malugu

unread,
Jun 3, 2013, 12:43:39 PM6/3/13
to appium-...@googlegroups.com, Satyajit Malugu, Igor Dorovskikh
I've tried this approach again on Friday but couldn't get it to work. Did any else got this to work? Would like some sort of update or detailed example of this.

Aleksei Petrovski

unread,
Oct 29, 2013, 6:25:55 PM10/29/13
to appium-...@googlegroups.com
here is my solution:

1. open directory: Users/your_user/Library/Application Support/iPhone Simulator/7.0(or yours)/Library/Caches/locationd/
2. open your app and suppress location popup manually
3. after this in folder locationd will be created file clients.plist, this file contains yours location
4. before starting tests I have precondition method whih copying back clients.plist file to locationd folder

Good Luck!
Aleks.

Jonathan Lipps

unread,
Oct 29, 2013, 6:41:29 PM10/29/13
to Aleksei Petrovski, appium-...@googlegroups.com
great this strategy could also be used automatically by appium

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.

Dan Doveralba

unread,
Oct 29, 2013, 8:13:59 PM10/29/13
to Aleksei Petrovski, appium-...@googlegroups.com
Hey Aleksei,

Would it be bad if your application started popping up the request for access to location services at an incorrect time?  Or didn’t pop-up the request for access to location services at all?  If yes, you might be doing yourself a disservice and miss issues with your application under test by adding that.

Best,
Dan

On Oct 29, 2013, at 3:25 PM, Aleksei Petrovski <alekseip...@gmail.com> wrote:

Kanstantsin Sudzilouski

unread,
Jan 28, 2014, 2:53:25 AM1/28/14
to appium-...@googlegroups.com
Jonathan, may you please summirize how to fix location services popup?
I did dowloaded appium 0.14.2 and set locationServicesEnabled=true but still have problems with popup.
Coping file as Aleksei suggested did not helped me by some reason.

In another thread you wrote: "Appium now accepts Location Services popups automatically. If you want to disable this, pass a desiredCap of useLocationServices: false". But it is still does not works for me, popup is here.

I saw you make some fixes in your git branch on this topic. Should I take your branch or patch some files against 0.14.2?

Kanstantsin Sudzilouski

unread,
Jan 29, 2014, 4:17:26 AM1/29/14
to appium-...@googlegroups.com
Confirmed, branch loc-services helped to me.
The only issue that at the first start we does not have "/Users/user/Library/Application Support/iPhone Simulator/6.1/Library/Caches/locationd/" folder. So clients.plist was not able to created.

Thanks Jonathan!

Kanstantsin Sudzilouski

unread,
Jan 30, 2014, 9:28:10 AM1/30/14
to appium-...@googlegroups.com
Actually loc-services broke something in my app session and it stop working.
I have to rollack this changes to 0.14.2 :-(

Jonathan Lipps

unread,
Jan 30, 2014, 1:33:53 PM1/30/14
to Kanstantsin Sudzilouski, appium-...@googlegroups.com
it's an in-progress branch so that's not totally unexpected. i hope to have it more ready soon.

Kanstantsin Sudzilouski

unread,
Feb 3, 2014, 4:20:49 AM2/3/14
to appium-...@googlegroups.com, Kanstantsin Sudzilouski
Message for guys who need fix the popup ASAP (to use test in CI):

solution from Aleksei Petrovski:
1. open directory: Users/your_user/Library/Application Support/iPhone Simulator/7.0(or yours)/Library/Caches/locationd/
2. open your app and suppress location popup manually
3. after this in folder locationd will be created file clients.plist, this file contains yours location

modified by me, dirty hack for 0.14.2:
4. add to Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios.js at line 806, method IOS.prototype.cleanupAppState:

              exec('mkdir -p /Users/user/Library/Application\\ Support/iPhone\\ Simulator/6.1/Library/Caches/locationd/', function (err) {
if (err !== null) {
cb(new Error(err));
}
              });
logger.info('cp /Users/user/clients.plist /Users/user/Library/Application\\ Support/iPhone\\ Simulator/6.1/Library/Caches/locationd/');
              exec('cp /Users/user/clients.plist /Users/user/Library/Application\\ Support/iPhone\\ Simulator/6.1/Library/Caches/locationd/', function (err) {
if (err !== null) {
cb(new Error(err));
}
              });

replace bold text with your pathes.

MUI

unread,
Mar 6, 2014, 1:44:42 AM3/6/14
to appium-...@googlegroups.com
Hi,

I want to validate the Location Services Alert that appears everytime my app is launched, but behavior of the appium is to thrown an error saying 'target app is not the frontmost app' - as this is also the behavior of Instruments.

With the latest 0.16.0, I have seen the capabilities 'locationServicesEnabled' and 'locationServicesAuthorized' is available to handle it.

But is there is anyway to verify the content of Local Services alert once the App is launched by letting Appium not throwing the error ?

Thanks.

Dan Doveralba

unread,
Mar 6, 2014, 2:19:24 PM3/6/14
to MUI, appium-...@googlegroups.com
Both of the additions you refer to will not allow you to actually test the alert.  locationServicesEnabled is actually unrelated to the popup - it’s an iOS setting.  locationServicesAuthorized will force the alert to not appear at all.

I recommend you change the app behavior to enable testability.  Perhaps delay the alert by a second or two on a debug build as a workaround.

Aleksei Petrovski

unread,
Mar 6, 2014, 8:08:12 PM3/6/14
to appium-...@googlegroups.com
Hi Dan!
did you try new capabilities?
I`m trying
'locationServicesEnabled' => true,
 'locationServicesAuthorized' => true

and still see current location popup.

BR.
Aleks

Jonathan Lipps

unread,
Mar 6, 2014, 8:21:43 PM3/6/14
to Dan Doveralba, MUI, appium-...@googlegroups.com
As Dan said, if you want to test the alert, make sure you _don't_ use the locationServicesAuthorized cap. Otherwise it won't come up at all.

Joel Neubert

unread,
Mar 11, 2014, 6:23:27 PM3/11/14
to appium-...@googlegroups.com
I'm seeing the same as you Aleksei with Appium 16.0 and the following caps. I still see the location services popup running my tests locally, and against the sauce labs cloud. It doesn't dismiss. Is that not the expected behavior when setting locationServicesAuthorized => true, and autoAcceptAlerts => true?

    caps = {
      'browserName' => '',
      'platform'    => 'Mac',
      'version'     => '7.0',
      'device'      => 'ipad',
      'app'         => myapp,
      'locationServicesAuthorized' => true,
      'autoAcceptAlerts'  => true
  }
  server_url = "http://0.0.0.0:4723/wd/hub"
  @driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps, :url => server_url)
  @accept_next_alert = true
  @driver.manage.timeouts.implicit_wait = 10
  @verification_errors = []



Jonathan Lipps

unread,
Mar 11, 2014, 8:09:05 PM3/11/14
to Joel Neubert, appium-...@googlegroups.com
I fixed another bug with this that will be effective in the next release, I think that could help what you're seeing.

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

Curtis Stuehrenberg

unread,
May 30, 2014, 2:31:27 PM5/30/14
to appium-...@googlegroups.com, joeln...@gmail.com
Will the fix correct the issue that locationServicesAuthorized doesn't seem to work at all now that I've updated to Cygnus?  Based on the logs it looks like either Appium can no longer find the plist to update or it's killing the simulator right after updating the list to allow for locations.

 - Curtis

info: Setting location services to 1
info: Updating settings for locationServices
info: Getting current settings for locationServices from /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Preferences/com.apple.locationd.plist
warn: Settings file /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Preferences/com.apple.locationd.plist did not exist
info: Writing settings for locationServices to /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Preferences/com.apple.locationd.plist:
info: {"LocationServicesEnabled":1,"LocationServicesEnabledIn7.0":1}
info: Authorizing location services for app
info: Getting current settings for locationCache from /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Preferences/cache.plist
warn: Settings file /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Preferences/cache.plist did not exist
info: Getting current settings for locationCache from /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Caches/locationd/cache.plist
warn: Settings file /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Caches/locationd/cache.plist did not exist
info: Getting current settings for locationClients from /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Caches/locationd/clients.plist
warn: Settings file /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Caches/locationd/clients.plist did not exist
info: Writing settings for locationClients to /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Caches/locationd/clients.plist:
info: {"com.apple.locationd.bundle-/System/Library/PrivateFrameworks/AOSNotification.framework":{"BundlePath":"/System/Library/PrivateFrameworks/AOSNotification.framework","Whitelisted":false,"Executable":"","Registered":""},"com.climate.growers.iphone.CGPQA":{"BundleId":"com.climate.growers.iphone.CGPQA","Authorized":true,"Whitelisted":false},"Executable":"","Registered":""}
warn: Base directory /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Caches/locationd doesn't exist, creating it
info: Writing settings for locationCache to /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Preferences/cache.plist:
info: {"LastFenceActivityTimestamp":412122103.232983,"CleanShutdown":true}
info: Writing settings for locationCache to /Users/cstuehrenberg/Library/Application Support/iPhone Simulator/7.1/Library/Caches/locationd/cache.plist:
info: {"LastFenceActivityTimestamp":412122103.232983,"CleanShutdown":true}
info: Starting iOS 7.* simulator log capture
info: Killing the simulator process
info: Killing any other simulator daemons
debug: Checking whether instruments supports our device string
info: Getting list of devices instruments supports
info: Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: Cleaning app state.

Jonathan Lipps

unread,
May 30, 2014, 3:23:02 PM5/30/14
to Curtis Stuehrenberg, appium-...@googlegroups.com, joeln...@gmail.com
Does it work if you use --no-reset and run at least 1 test before this one?

Curtis Stuehrenberg

unread,
May 30, 2014, 3:39:15 PM5/30/14
to appium-...@googlegroups.com, cstueh...@climate.com, joeln...@gmail.com
I'm using TestNG to run Java files so I've not run the tests with flags before.  I'll look into how to do this programmatically and give it a try.

Curtis Stuehrenberg

unread,
May 30, 2014, 4:38:08 PM5/30/14
to appium-...@googlegroups.com, cstueh...@climate.com, joeln...@gmail.com
I bypassed the whole problem by setting the autoAcceptAlerts capability to true since I don't currently care about checking alerts.

Unfortunately it looks like it's now not letting me do a full-reset between simulations, which is the root cause of another issue I was attempting to debug.  If I start the server with --full-reset enabled then I can't run my TestNG test cases.

I'll keep looking .....
Reply all
Reply to author
Forward
0 new messages