2014-12-02 86 views
1

我正在爲我的應用程序進行自動化UI測試,並且在嘗試設置運行測試環境時遇到了問題。該計劃大致是這樣的:在iOS模擬器上初次啓動時關閉警報

  • 構建應用程序
  • 關機模擬器如果運行
  • 刪除模擬器做一個乾淨的安裝
  • 在模擬器上安裝我的應用程序
  • 運行UIAutomation測試

除了當儀器啓動應用程序以執行測試時,一切正常,警報似乎詢問是否用戶允許通知。這一切都如預期,但我無法找到擺脫警報的方式。

事情我已經嘗試:

  • 創建onAlert在我的測試腳本中的第一件事情,如果它出現在我的警惕回調的情況下,定義
  • 延遲目標由前5秒實際測試運行,即使之前的應用程序的UI是在模擬器

我也是通過上面所有的排列組合就可見可在SO被發現,我從來沒有讓我的onAlert調用的回調,不管是什麼我做。所以,我想另一件事是:

  • 嘗試駁回警報使用AppleScript

我寫的劇本:

tell application "System Events" 
    tell process "iOS Simulator" 
     set allUIElements to entire contents of window 1 
     repeat with anElement in allUIElements 
      try 
       log anElement 
      end try 
     end repeat 
    end tell 
end tell 

並顯示:

static text 「MyApp」 Would Like to Send You Notifications of window iOS Simulator - iPhone 6 - iPhone 6/iOS 8.1 (12B411) of application process iOS Simulator 
static text Notifications may include alerts, sounds, and icon badges. These can be configured in Settings. of window iOS Simulator - iPhone 6 - iPhone 6/iOS 8.1 (12B411) of application process iOS Simulator 
UI element 3 of window iOS Simulator - iPhone 6 - iPhone 6/iOS 8.1 (12B411) of application process iOS Simulator 

看起來像按鈕放置在「UI元素3」中,但我無法從i中檢索任何元素放棄它,更不用說點擊它了。所以,我有無障礙經理檢查:

UI element 3 in Accessibility Manager

它坐在那裏,作爲一個孩子,其他的人都通知的標題和消息。但是,當我去那個元素,突出顯示它,我看到:

enter image description here enter image description here

它認定爲一般元素,它沒有任何的孩子...... 有趣的是,當我選擇在輔助功能檢查OK按鈕,我可以清楚地看到它的窗口的子窗口,但它永遠不會上市:

enter image description here

可有人請闡明這是怎麼回事一些輕?我怎樣才能用Applescript按下那個按鈕?

回答

0

如果您正在使用Instrument進行自動化,則需要註冊回調(onAlert)以對警報執行任何操作。

但您的情況的問題是,警報出現在您的腳本實際開始執行之前,並且此時沒有註冊警報的回調。

因此,如果警報在啓動應用程序時可能延遲約10秒,則只能處理它。但是這隻能通過源代碼來控制,而不能通過自動化代碼來控制。

因此僅剩下的選擇是你需要手動解僱一次新的應用程序被安裝

,我也面臨着同樣的問題的警覺,並發現它是工具

有太多的限制許多限制這個工具,這就是爲什麼我轉移到UFT

0

我有一個類似的問題。我只是想要在警報上的最後一個控件的位置。所以我想出了以下一段代碼:

on get_simulator_last_object_rect(simulator_index) 

tell application "System Events" 
    set ProcessList to (unix id of processes whose name is "iOS Simulator") 
    set myProcessId to item simulator_index of ProcessList 
    tell window 1 of (processes whose unix id is myProcessId) 

     -- Forcefully print the UI elements so that Accessibility hierarchy is built 
     UI elements 
     -- Then wait precisely to let the Accessibility view hierarchy is ready 
     delay 0.5 

     set lowest_label_lowest_position to 0 
     set _x to 0 
     set _y to 0 
     set _width to 0 
     set _height to 0 

     repeat with element in UI elements 

      set {_x, _y} to position of element 
      set {_width, _height} to size of element 
      set current_control_lowest_position to _y + _height 

      if current_control_lowest_position > lowest_label_lowest_position then set lowest_label_lowest_position to current_control_lowest_position - _height/2 

     end repeat 
     return {{_x, _y}, {_width, lowest_label_lowest_position}} 
    end tell 
end tell 
end get_simulator_alert_ok_button_position 

我有一個桌面應用程序來控制我的行爲。我在我的桌面應用程序中使用這個蘋果腳本來獲取最後一個控件的框架。現在我已經有了框架,我創建了一個鼠標事件,並在激活模擬器後單擊框架。

儘管我還沒有嘗試過,但我確信您可以從Apple腳本創建鼠標事件並執行點擊幀/幀的中心。

希望這會有所幫助。

謝謝, RKS