android+ui+注入,如何注入click事件与Android UiAutomation.injectInputEvent

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

limian3687

2017.07.24

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率: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分享举报

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值