Start Instruments from the command line

我怕爱的太早我们不能终老 提交于 2019-12-04 10:03: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.

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.

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.

user2461370

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!