古詩詞大全網 - 個性簽名 - 如何使用UIAutomation進行iOS自動化測試

如何使用UIAutomation進行iOS自動化測試

使用iOS模擬器

1. 下載示例應用程序TestAutomation.xcodeproj,並打開它。這個項目是壹個很簡單的包含2個tab的tabbar應用程序。

2. 確保選中如下圖所示的“TestAutomation > iPhone 5.0

Simulator”模式(或許已經切換成5.1了,因此它可能是iPhone5.1模擬器)。

3. 啟動Instruments(Product > Profile),或者通過?I。

4. 選擇左邊的iOS Simulator,然後再選擇Automation模板,然後點擊“Profile”。

5. Instruments就已經啟動好後,然後直接開始錄制了。這裏先停止錄制,(紅包按鈕或者?R)。

6. 在左邊的Scripts窗口,點擊“Add > Create”創建新的腳本。

7. 在腳本編輯器裏,輸入下面的代碼

var target = UIATarget.localTarget();

var app = target.frontMostApp();

var window = app.mainWindow();

target.logElementTree();

8. 重新運行這段腳本?R(不需要保存)。腳本跑起來後,可以在日誌打完後停止它。

贊壹個!就這樣完成了第壹個UIAutomation測試用例。

使用iOS設備

除了將測試用例運行模擬器上,也可以將它運行在壹個真實的設備上。不過,自動化測試用例只能運行在支持多任務的:iPhone 3GS,iPad,iOS

> 4.0等設備上。遺憾的是不管iPhone 3G的系統版本是什麽,都不支持。

下面是如何操作:

1. 通過USB接口連接上iPhone。

2. 選擇 “TestAutomation > iOS Device”模式。

3. 確保Developper profile設置成Release模式(而不是Ad-Hoc Distribution

profile)。默認情況下,profiling是設置成Release模式的(因為沒有必要將profile設置成Debug模式)。

4. 啟動測試 (?I)

5. 後面的步驟請參考前面模擬器部分