How to deal with the “_APPNAME_ Would Like to Use Your Current Location” alert through UIAutomation

ε祈祈猫儿з 提交于 2019-12-10 14:58:19

问题


Ok, this is driving me nuts. I've got a little CI-build system running. And I'm doing UI testing of my application with UIAutomation. Since the application uses CoreLocation, the first time the application is launched I get a little alert asking me to confirm that I want my location tracked. This would be great and all, but the alert is not part of my own application and I can't use UIAutomation to interface with it. Is there any solution to confirming this alert without manual taping of the button.

Thanks.

P.S. Getting rid of CoreLocation for a test build is not an option.


回答1:


The only way I have gotten around this at the previous place I worked was to write a little apple script app that can dismiss the alert for you.

You should be able to do some simple UI scripting to dismiss the alert on the iOS simulator.

Obviously I am assuming your running on the simulator and not device for your tests.

How to dismiss location alert via apple script for iPhone simulator

  1. In System Preferences open up Accessibility. In the bottom left corner make sure you check the option Enable Access for assistive devices

Apple script to run after you app has launched in the simulator and the alert is displayed so you will need to run this after some delay.

tell application "iPhone Simulator"
    activate
end tell

tell application "System Events"
    tell process "iPhone Simulator"
        click button "OK" of window 1
    end tell
end tell



回答2:


It is indeed possible to interact with this alert. All alerts that show up while your app is running can be handled by assigning an onAlert handler before you trigger it.

Based on the question you asked, it sounds like you're firing up the CLLocationManager immediately on app launch. If possible, try to delay it by a half second or so. Then, in your UI Automation script, you can immediately assign an alert handler right at the beginning. Something like this:

UIATarget.onAlert = function(alert) {
    alert.defaultButton().tap();
    return true;
};

That tells the alert to tap the default (confirmation) button and the return true tells the alert handling mechanism that we handled it. If you returned false, then the system would think it needs to tap the cancel button (which is the default behavior).

Hope that helps!




回答3:


Above solution that embeds applescript script into cucumber script

Given /^I am on the GPS permission screen$/ do
IO.popen("osascript", "w") do |f|
# applescript to OK sharing of Current Location
f.puts <<-eos
    tell application "iPhone Simulator"
        activate
    end tell

    tell application "System Events"
        tell process "iPhone Simulator"
            repeat
                try
                    click button "OK" of window 1
                    exit repeat
                end try
            end repeat
        end tell
    end tell
eos

end end



来源:https://stackoverflow.com/questions/13938537/how-to-deal-with-the-appname-would-like-to-use-your-current-location-alert-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!