【问题标题】:Start Instruments from the command line从命令行启动 Instruments
【发布时间】:2013-03-02 20:56:19
【问题描述】:

我关注这个网站是为了开始使用 UI 自动化。 http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation#1.2

我正在尝试从命令行启动 Instruments。不幸的是,我收到一个错误:

2013-03-14 14:06:36.376 instruments[17854:1207] Connection to the remote device lost while launching target. Aborting...
2013-03-14 14:06:36.378 instruments[17854:1207] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Failed to start trace.

这是我使用的命令:

instruments -w {deviceId} -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate {appname} -e UIASCRIPT /Path/to/Script.js

目前我使用的是 Xcode 4.6。

【问题讨论】:

  • 设备上是否安装了应用程序? Instruments 不会自动安装在设备上(至少目前不会)。你有{appname} 作为参数。您不能只指定名称。您必须指定 Xcode 构建的应用程序包的完整路径。 Instruments 使用它来找出包标识符,以便知道要在设备上启动什么应用程序。
  • 哦,我的演示应用程序中的这个脚本可能会有所帮助:github.com/jonathanpenn/ScheduleDemo/blob/master/test_run.sh

标签: command-line instruments ios-ui-automation


【解决方案1】:

在 2014 年的 Xcode 6.0.1 中,您将在模拟器上运行 UIAutomation 测试,在 -w 开关后命名您的模拟器:

instruments -t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
    -w 'iPhone 5s' \
    '/Users/sohail/Library/Developer/CoreSimulator/Devices/7232A640-A9D2-4626-A2AD-37AFFF706718/data/Containers/Bundle/Application/E71B915E-051D-4BEF-9083-34416D02EC91/RoadRunnerRadar.app' \
    -e UIASCRIPT '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestRunner.js' \
    -e UIARESULTSPATH '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestResults/'

如果您想在您的设备上运行它,而不是像我在上面的 sn-p 中用于在模拟器上运行的“iPhone 5s”,您需要提供设备的 UDID。然后,您可以省略我上面给出的长应用程序路径,只提供应用程序的名称。 Instruments 将能够在设备上找到它。

使用上面的示例,但针对假设设备进行了修改,如下所示:

instruments -t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
    -w '8532A640-A9C2-4626-A2AD-37AFFF706799' \
    'RoadRunnerRadar' \
    -e UIASCRIPT '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestRunner.js' \
    -e UIARESULTSPATH '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestResults/'

这未通过设备调用验证,因此请对其进行测试。参数排序有一点灵活性。

我确实有一个经过验证的 UI Automation Runner 脚本,它非常适用于 Xcode 6.0.1 和模拟器。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,我做了以下更改并且工作正常:

    在给定命令中更改了-w udid的位置,将其放在tracetemplate路径之后和app路径之前,即应该是这样的

    instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w {deviceId} {appname} -e UIASCRIPT /Path/to/Script.js
    

    【讨论】:

    • 这会忽略 -w 参数,只是在最近使用的模拟器硬件上启动。
    【解决方案3】:

    试试这个

    instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate  <path to your app> -e UIASCRIPT /Users/t-rbudhbhatti/Desktop/Scripts/FT5/SearchByRoute.js -e UIARESULTSPATH /Users/t-rbudhbhatti/Desktop/Scripts/FT5/SearchByRouteResult
    

    您应该提供应用的完整路径,而不是应用名称。

    【讨论】:

    • 这在设备中不起作用,它只适用于模拟器
    【解决方案4】:

    我建议你看看 Jonathan 的屏幕截图,他在 http://cocoamanifest.net/articles/2013/01/ui-screen-shooter.html 上对此进行了解释。这真的帮助我了解了很多关于模拟器、从命令行运行仪器等等的知识。就像 Jonathan 解释的那样,您需要先构建应用程序才能运行。

    在此处获取他的消息来源:https://github.com/jonathanpenn/ui-screen-shooter,看看这是否适合您。然后回到一个简单的脚本来构建应用程序,将它放在一个方便的位置并使用应用程序和所需的模板运行仪器。

    【讨论】:

      【解决方案5】:

      这对我有用。

      我执行了ps 命令来查看哪些进程正在运行。我发现仪器仍在运行。然后我做了killall instruments,这杀死了仪器进程。然后我做了我的仪器命令,然后它就完美地工作了。

      【讨论】:

        猜你喜欢
        • 2016-07-10
        • 1970-01-01
        • 2015-01-29
        • 2013-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-04
        • 2014-04-03
        相关资源
        最近更新 更多