移动测试基础 [Share]如何在命令行中运行 UIAutomation

唐僧之妈 · 2014年09月24日 · 最后由 恒温 回复于 2014年09月25日 · 1662 次阅读
本帖已被设为精华帖!

基本介绍

有时候我们需要更快捷的运行 UIAutomation,下面就给大家分享一下在 Command Line 中运行 UIAutomation 的方法

instruments -w deviceID -t defaultTemplateFilePath targetAppName -e UIASCRIPT scriptFilePath -e UIARESULTSPATH resultsFolderPath

各参数释义:

  • deviceID:就是通常说的 UDID,一个 40 位的设备唯一识别码,可以在 Xcode--organizer 中的 devices 中找到(注意:最新的 Xcode6 已经把 devices 从 organizer 中分离了出来)
  • defaultTemplateFilePath:Automation 的默认模板文件路径,如果你使用的是 Xcode5,其路径在 “/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate”,如果你已经升级到了 Xcode6,则其路径就变成了 “/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate”。
  • targetAppName:应用的名称,也就是应用的 Bundle Identifier,在 Xcode General 中可以看到
  • scriptFilePath:需要执行的脚本路径
  • resultsFolderPath:需要输出的结果路径

实践

如果你使用的是 Xcode5

模拟器(在模拟器上运行不需要 UDID,但是需要将 targetAppName 替换成具体的模拟器的沙盒应用程序,在 Xcode5 下模拟器的沙盒应用程序位于 /Users/Your_UserName/Library/Application Support/iPhone Simulator/Simulator_Version/Applications 中)

instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate "/Users/kingson/Library/Application Support/iPhone Simulator/7.1/Applications/C28DDC1B-810E-43BD-A0E7-C16A680D8E15/Testapp.app" -e UIASCRIPT /Users/kingson/PycharmProjects/ynm3k/robot4ios/util/logtree.js -e UIARESULTSPATH /Users/kingson/UIAutomationResult

真机

instruments -w ae04ee552548410bad958135304cd519******** -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate Testapp -e UIASCRIPT /Users/kingson/PycharmProjects/ynm3k/robot4ios/util/logtree.js -e UIARESULTSPATH /Users/kingson/UIAutomationResult

如果你使用的是 Xcode6

模拟器(注意:在 Xcode6 中,模拟器的沙盒应用程序位置变成了 /Users/Your_UserName/Library/Developer/CoreSimulator/Devices/Simulator_UDID/data/Containers/Bundle/Application 中)

instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate "/Users/kingson/Library/Developer/CoreSimulator/Devices/E48D90E6-8313-4318-8064-48B16462AD8E/data/Containers/Bundle/Application/35A7348C-059D-42BA-86F4-ADFFD76DC182/Testapp.app" -e UIASCRIPT /Users/kingson/PycharmProjects/ynm3k/robot4ios/util/logtree.js -e UIARESULTSPATH /Users/kingson/UIAutomationResult

真机

instruments -w ae04ee552548410bad958135304cd519******** -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate Testapp -e UIASCRIPT /Users/kingson/PycharmProjects/ynm3k/robot4ios/util/logtree.js -e UIARESULTSPATH /Users/kingson/UIAutomationResult

其他注意点&问题

  • 运行时需要关闭设备的密码验证,否则会提示:device locked
  • 如果指定目录,就会在指定目录中生成一个 Run 1 的文件,其中是一些运行的截图以及 Plist 文件以及在当前目录下生成一个 instrumentscli.trace 文件,如果没有指定输出结果路径或者指定的路径不存在,默认只会在当前目录生成一个 instrumentscli.trace 文件
共收到 7 条回复 时间 点赞

nice!尤其 xcode6 的执行变更很有用!


➜  ~  instruments -s devices
Known Devices:
lihua的MacBook Air [DD126F87-5B14-55FA-9045-CBC6064F5299]
Resizable iPad (8.0 Simulator) [4858F598-29D2-4E53-9E36-53747C480D1A]
Resizable iPhone (8.0 Simulator) [E71308F7-2B81-450F-9FB1-0B48FC0D8507]
iPad 2 (7.0.3 Simulator) [E8E8A927-7475-4E64-8616-1782E67B1873]
iPad 2 (8.0 Simulator) [28D3DCB1-60EA-4777-A558-D7F55867F737]
iPad Air (7.0.3 Simulator) [AFB4A797-AC8B-44D9-956A-28309FD43011]
iPad Air (8.0 Simulator) [16E78C88-0E58-4A21-97B1-C9F2E7761166]
iPad Retina (7.0.3 Simulator) [C83CB313-BB13-48B8-A989-F3FA765D77F5]
iPad Retina (8.0 Simulator) [C29FE5F2-A4FE-45E2-A8A0-DC96782639B8]
iPhone 4s (7.0.3 Simulator) [5525F839-57C4-4643-AB9D-8336AA23F21E]
iPhone 4s (8.0 Simulator) [BF94BA47-9EF2-49BD-ACB6-359381A09408]
iPhone 5 (7.0.3 Simulator) [4A1B0D01-A5EC-414F-8140-C1ABF2E46E80]
iPhone 5 (8.0 Simulator) [83FD5F96-AC57-41B1-A34D-1223E4DF33CF]
iPhone 5s (7.0.3 Simulator) [531C27F2-0683-4EB9-9089-153AE59EEE62]
iPhone 5s (8.0 Simulator) [0BB7D2C7-11A6-4629-8EE4-5CC19BD9AD3A]
iPhone 6 (8.0 Simulator) [176E7205-CE5A-44CF-ACC0-B7A37A6A513F]
iPhone 6 Plus (8.0 Simulator) [2D04C98E-230F-4CF2-9DA8-6911F7372EE5]

加一个命令

这个命令行针对 xcode6.1 版本需要优化了吗?
我执行的结果是不管模拟器还是真机都需要加 instruments -w xxxxxxx -t xxxxxx 这样

#3 楼 @davidyang
6.1 相比较 6.0 或 6.0.1 有什么具体变化吗?我没有具体关注过 UIAutomation 在 6.1 的表现。
如果是模拟器是不需要加-w xxxxxxx 的

#4 楼 @xiaomayi0323 6.1 中模拟器上运行也是要加-w xxxxxxx, 这个试过很多次,如果不加会出错的,所以只能加上了,当然如果有更好的方法,欢迎回帖吧

#6 楼 @davidyang 非常感谢,我没有在 6.1 上通过命令行运行过模拟器,可能是因为现在模拟器也加上了 Identifier,所以运行时也要加上-w xxxxxxx

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册