繁体   English   中英

无法从命令行运行UIAutomationTest

[英]Can't run UIAutomationTest from command line

我有一个iOS应用程序,我想把它放在持续集成中。 我用来做的策略是尝试从命令行运行测试。

我正在尝试使用以下脚本:

TRACETEMPLATE="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
instruments   -t $TRACETEMPLATE build/Release-iphonesimulator/MyApp.app -e UIACSCRIPT "UnitTests/SomeTest.js"

SomeTest.js是一个简单的javascript文件,我可以在Xcode中的Instrumentation中运行它可以工作。 我用以下方法构建应用程序

xcodebuild -alltargets -sdk iphonesimulator5.1

这会生成MyApp.app。 我可以在模拟器中从Xcode运行应用程序就好了,但是,当我尝试通过仪器运行时,我得到一个框,说有一个未知错误,并在命令行中打印:

2012-05-15 15:32:59.928 instruments[17548:1d03] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Failed to start trace.

任何人都可以给我任何关于可能发生的事情的帮助/建议,我该如何解决这个问题?

此外,它总是打开iPad模拟器? 我能说它打开我想要的任何模拟器吗?

我得到了同样的错误,差点把我的头发拉出来试图解决它。 错误消息完全没有用。

最终成为问题的是我指向的.app文件。 一旦我找到了深深埋藏在5.1 Simulator文件夹中的“正确”.app文件,我就能够最终使用Xcode 4.3从命令行运行UIAutomation测试。

.app的路径对我有用:

~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications/{string-of-numbers-and-letters}/MyApp.app/

这是我用来从Xcode 4.3命令行运行UIAutomation测试的完整命令:

instruments -t /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate ~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications/{string-of-numbers-and-letters}/MyApp.app/ -e UIASCRIPT /Path/To/TestFile.js

希望这可以帮助其他人,因为那里的文档非常缺乏。

更新

请注意,从Xcode 4.5.2开始,自动化模板位置与原始答案的位置有所不同:

/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate

自Xcode 4.5.2起,Automation.tracetemplate的正确位置是/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate

在过去几年中,UIAutomation命令行调用的路径略有变化。 我编写了一些可以协同工作的bash shell脚本,它们可以用Xcode 4.4.1的方式启动你的UIAutomation测试文件。

请参阅此要点: https//gist.github.com/3605692#comments

简而言之,关键命令最终是:

instruments -t $INSTRUMENTS_TEMPLATE $APP_PATH -e UIASCRIPT $SCRIPT_PATH -e UIARESULTSPATH $RESULTS_PATH

我的脚本显示了所需的变量替换。 另一个好处是iOS模拟器应用程序经常将GUID更改为其路径的一部分。 我的脚本会找到它们,因此您不必在构建/脚本/命令行调用中对临时GUID进行硬编码。

抱歉,我的英语很不好。 作为从Teamtsity运行此脚本的最简单方法? 每个组件 - 数字和字母都不同。 不是最简单的方法:

  1. 在组装之前清洁模拟器
  2. 找到带有程序的文件夹,它包含这些数字和字母,写在变量中。
  3. 这个变量,比如编写脚本。

也许从这些数字中可以更方便地获取?

构建配置应该是调试而不是发布。 这就是我的错误的原因。 您可以在“编辑方案”中更改“构建配置”,然后选择“配置文件”选项卡。 验证构建选项卡是否也处于调试模式。

我做了ps命令来查看正在运行的进程。 我发现仪器还在运行。 然后我做了killall instruments并且杀死了乐器过程。 然后我做了我的乐器命令,之后它完美无缺。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM