Xcode 使用Instrument(2)

UIAutomation

UIAutomation是随iOS4.0系统一起发布的一款旨在iPhone Device/Simulator上可执行的自动化测试框架。

使用UIAutomation准备

  • 被测试app源代码
  • 了解JavaScript

录制测试脚本

  • 录制测试脚本

    1. 使用Xcode打开被测试app工程
    2. command + i 打开Instrument
    3. 选择Automation template ->profile

    4. command + R 停止 profile
    5. 找到scripts 选择 add->create... 会看到一个新的脚本文件,下方有3个操作按钮

    6. 点击红色录制按钮,会启动APP,你在设备或是模拟器上进行操作都会生成操作代码 点击方形停止录制按钮录制完成,后Command + R停止

    7. 需要重新对录制脚本进行回放 可以点击三角按钮,或者直接C+R执行测试回放
  • 编写测试脚本:
    通过导入测试脚本和录制脚本,可以熟悉一些基本API
    接下来写一个测试脚本

    1. 打开被测试app工程
    2. Command + I 打开Instrument
    3. 选择Automation template ->profile
    4. Command + R 停止profile
    5. 在左边Scripts 选择add->create… 会看到一个新脚本文件生成 脚本可编辑区中进行脚本编辑如下图 4区域,在此区域进行测试用例的编写

    6. 测试用例demo 新建window上添加一个UITextField

    var target = UIATarget.localTarget();
    var app = target.frontMostApp();
    var window = app.mainWindow();
    var textFields = window.textFields();
    
    // Check number of Text field(s)
    if(textfields.length!=1)
    {
    	UIALogger.logFail("FAIL: Inavlid number of Text 		field(s)");
    }
    else
    {
    	UIALogger.logPass("PASS: Correct number of Text 		field(s)");
    }

    Note

    1. 在使用设备进行自动化测试有一点需要注意,在Release configuration 中选择使用Developer profile(不是Ad-Hoc Distrubution profile)。默认release 下profiling都已经完成。

    2. 文档
      UIAutomation JavaScript API 参考文档:
      http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值