天天看點

iOS instruments之ui automation的簡單使用(高手繞道)

  最近使用了幾次instruments中的automation工具,現記錄下automation的簡單使用方法,希望對沒接觸過自動化測試又有需求的人有所幫助。

   ui 自動測試是ios 中重要的附加功能,它由名為“automation”的新的工具對象支援。automation工具的腳本是用javascript語言編寫,主要用于分析應用的性能和使用者行為,模仿/擊發被請求的事件,利用它可以完成對被測應用的簡單的ui測試及相關功能測試。

  一. 簡單的錄制腳本

    打開xcode,這裡用我為我家親愛的龍貓寶貝們制作的龍貓後代基因電腦(totolov)為例。選擇模拟器和真機都可以,過程一樣。

  可以按下圖所示打開instruments工具,也可以點選菜單欄中的“product-profile”

iOS instruments之ui automation的簡單使用(高手繞道)

   選擇ios

simulator->automation,然後點選profile(其它工具都很實用,這裡就不一一介紹了)

iOS instruments之ui automation的簡單使用(高手繞道)
iOS instruments之ui automation的簡單使用(高手繞道)
iOS instruments之ui automation的簡單使用(高手繞道)
iOS instruments之ui automation的簡單使用(高手繞道)
iOS instruments之ui automation的簡單使用(高手繞道)
iOS instruments之ui automation的簡單使用(高手繞道)

二.accessibility inspector

  編寫一個測試用例,該如何找到識别控件元素呢。這裡介紹2個方法

1.可以在腳本中寫target.logelementtree(),會在日志中列印出目前頁的控件資訊。

2.使用自帶的accessibility inspector功能。

  打開模拟器,找到“settings > general > accessibility >

accessibility inspector”,然後将它打開。

iOS instruments之ui automation的簡單使用(高手繞道)
iOS instruments之ui automation的簡單使用(高手繞道)

三.其它

  通過以上兩部分,應該了解怎麼使用automation工具編寫簡單的測試用例了吧

  當熟悉之後就可以不用錄制功能來編寫腳本了 

  具體的api參考官方文檔:http://developer.apple.com/library/ios/#documentation/developertools/reference/uiautomationref/_index.html