无法从命令行运行UIAutomationTest

时间:2012-05-15 18:35:24

标签: ios continuous-integration ui-automation

我有一个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模拟器?我能说它打开我想要的任何模拟器吗?

6 个答案:

答案 0 :(得分:6)

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

最终导致问题的是我指向的.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

答案 1 :(得分:6)

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

答案 2 :(得分:1)

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进行硬编码。

答案 3 :(得分:0)

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

  1. 在装配前清洁模拟器
  2. 找到包含该程序的文件夹,它包含用变量写的这些数字和字母。
  3. 此变量,例如编写脚本。
  4. 也许从这些数字中可以更容易地获取?

答案 4 :(得分:0)

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

答案 5 :(得分:0)

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

相关问题