满意答案
limian3687
2017.07.24
采纳率:52% 等级:6
已帮助:309人
基本介绍
有时候我们需要更快捷的运行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 ae04eebadcd519******** -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 ae04eebadcd519******** -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文件
00分享举报