Xcode 使用Instrument(1)

UIAutomation

UIAutomation是隨iOS4.0系統一塊兒發佈的一款旨在iPhone Device/Simulator上可執行的自動化測試框架。app

使用UIAutomation準備

  • 被測試app源代碼
  • 瞭解JavaScript

開始使用

  • 測試腳本的導入
    1. 使用Xcode打開被測試app工程
    2. command + i 打開Instrument
    3. 選擇Automation template ->profile
    4. command + R 中止 profile
    5. 找到scripts 選擇 add->import...
    6. 選擇寫好的測試腳本後會看到腳本list
    7. 在腳本list右邊script能夠看到腳本內容
    8. command + R執行腳本
    9. 能夠看到腳本測試log

    附上一個顯示遍歷UI元素樹的腳本,保存爲本地的showUIAElementTree.js框架

    DEMO_DELAY=2;
    var target = UIATarget.localTarget();
    var app = target.frontMostApp();
    
    //test functions
    
    function showCurrentViewInfo(){
        UIALogger.logStart("show CurrentViewInfoTree");
            try{
                //show the target logElementTree
                target.logElementTree();
                UIALogger.logPass();
            } catch(error){
                UIALogger.logFail(error);
            }
        }
    
    //calling test functions
    showCurrentViewInfo();
相關文章
相關標籤/搜索