Start Instruments from the command line

2019-04-09 16:35发布

I followed this site to get started with UI Automation. http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation#1.2

I am trying to start Instruments from the command line. Unfortunately I get an error:

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.

This is the command I used:

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

Currently I am using Xcode 4.6.

5条回答
一纸荒年 Trace。
2楼-- · 2019-04-09 16:59

I was having the same problem, I had done following changes and worked fine for me:

Changed the location of -w udid in given command, put it after path of tracetemplate and before path of app, i.e. this should be just like

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
查看更多
Viruses.
3楼-- · 2019-04-09 17:09

I'd suggest you take a look at Jonathan's screen-shooter, which he explains about on: http://cocoamanifest.net/articles/2013/01/ui-screen-shooter.html. This really helped me to understand a lot about the simulator, running instruments from the command line and more. Like Jonathan explained, you will need to build the app first, to have something to run.

Get his sources here: https://github.com/jonathanpenn/ui-screen-shooter and see if that works for you. Then work your way back to a simple script that will build the app, put it in a convenient location and run instruments using the app and the desired template.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-04-09 17:10

In 2014 with Xcode 6.0.1, you would do something like this for running UIAutomation tests on the simulator, naming your simulator after the -w switch:

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/'

If you want to run this on your device, instead of 'iPhone 5s' like I have in the snippet above for running on the simulator, you'd provide the UDID of your device. You can then omit the long app path I've given above, and just provide the name of the app. Instruments will be able to find it on the device.

Using my example from above, but modified for a hypothetical device, this would look like:

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/'

This is not verified with an on device invocation, so please test it. There's a bit of flexibility with parameter ordering.

I do have a verified UI Automation Runner script that works really well for Xcode 6.0.1 and the simulator.

查看更多
聊天终结者
5楼-- · 2019-04-09 17:18

This worked for me.

I did the ps command to see which processes are running. I found that instruments was still running. I then did killall instruments and that killed the instruments process. I then did my instruments command and it worked perfect after that.

查看更多
一纸荒年 Trace。
6楼-- · 2019-04-09 17:18

try this

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

instead of app name, you should give the complete path to your app.

查看更多
登录 后发表回答