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();
相关文章
相关标签/搜索