2013-03-26 42 views
10

我的應用程序正在使用位置服務,並且爲了進行自動測試,我希望能夠解除「APP將使用您當前的位置」彈出窗口。然而,當我嘗試用UIAutomation腳本來做到這一點的儀器,我得到這個錯誤:UIAutomation:任何方式來解僱「想使用您當前的位置」警報?

Fail: Could not start script, target application is not frontmost. 

這種有道理的,因爲警報是由不同的工藝生產的。但是,在這種情況下,蘋果計劃如何幫助人們自動化測試呢?

回答

0

該解決方案似乎是使用AppleScript,在足夠延遲後運行以允許警報出現。你告訴它點擊模擬器窗口中的提示按鈕。

+1

請問您可以發佈您的解決方案嗎? – 2013-05-31 11:20:51

1
**Try** 

UIATarget.onAlert = function onAlert(alert) 
     { 
     return true; 
     } 
alertTitle = target.frontMostApp().alert().name(); 
if(alertTitle==="APP Would Like To Use Your Current Location") 
{ 
target.frontMostApp().alert().buttons()["OK"].tap(); 
} 
0

在觸發位置請求對話框的外觀之前使用此代碼。請注意應用程序名稱周圍的特殊引號。

UIATarget.onAlert = function onAlert(alert) 
{ 
    if(alert.name()=="「local」 Would Like to Use Your Current Location") 
    { 
     alert.buttons()["OK"].tap(); 
    } 
    else 
    { 
     UIALogger.logFail("Location request dialog expected."); 
    } 
    return true; 
}