简体   繁体   中英

Can't run UIAutomationTest from command line

I have an iOS application, and I want to put it in continuous integration. The strategy I'm using to do that is trying to run the tests from the command line.

I'm trying to do it using the following script:

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 is a simple javascript file that I can run in Instrumentation inside Xcode and it works. I build my application using:

xcodebuild -alltargets -sdk iphonesimulator5.1

and this generates the MyApp.app. I can run the application from Xcode in the simulator just fine, however, when I try to run by the instruments, I get a box saying that there is an unknown error and in the command line it prints:

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.

Can anyone give me any help/suggestions about what might be happening and how can I fix this?

Also, it always open the iPad simulator? Can I make it that it opens any simulator I want?

I was getting this same error and nearly pulled my hair out trying to solve it. The error messages are completely unhelpful.

What ended up being the problem for me was the .app file that I was pointing to. Once I found the "right" .app file that was deeply buried in the 5.1 Simulator folder, I was able to finally run UIAutomation tests from the command line with Xcode 4.3.

The path to the .app that worked for me:

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

Here is the full command I'm using to run UIAutomation tests from the command line with Xcode 4.3:

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

Hope this helps someone else, as the documentation out there for this is extremely lacking.

Update

Note that as of Xcode 4.5.2, the automation template location has changed from that on my original answer:

/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

The paths for the command line invocation of UIAutomation has changed slightly over the past couple of years. I have written a few bash shell scripts that work together which can launch your UIAutomation test file in a way that works with Xcode 4.4.1.

See this gist: https://gist.github.com/3605692#comments

In a nutshell, the key command ends up being:

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

My scripts show the variable substitutions needed. The other benefit is that iOS simulator apps have often changing GUID as part of their path. My script will find them, so you don't have to hard code the temporary GUID in your builds / scripts / command line invocations.

sorry, my english is very bad. As the easiest way to run this script from Teamtsity? Each assembly - the numbers and letters are different. Not the easiest way:

  1. clean the simulator prior to assembly
  2. find the folder with the program, and it contains these numbers and letters, written in the variable.
  3. This variable, such as writing the script.

Maybe there's a way easier to take from these numbers?

The Build Configuration should be debug than Release. That was the reason for the error in my case. You can change Build Configuration in 'Edit Schemes' and by choosing the Profile tab. Verify that build tab also is in debug mode.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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