How to Remove the Authorization Prompt from Command-Line Instances of Instruments (Xcode)

Is there a way to remove the authorization prompt from command-line instances of Instruments (Xcode)?

Here's a wonderful command that may work for you:

security unlock-keychain -p [password] "${HOME}/Library/Keychains/login.keychain"

It's the command-line way to gain access to a keychain on the Mac. I haven't tested it with Automation, but it's how I've integrated my iOS builds with Jenkins.

(Replace [password] with the password)

Instruments wants permission to analyze other processes Jenkins

I just experienced a similar problem, triggered by Fastlane scan command to execute tests.

Following the discussion on this issue and this Apple Support discussion I managed to solve it by enabling "Developer Mode" on my CI machine.

$ DevToolsSecurity -status
Developer mode is currently disabled.

$ DevToolsSecurity -enable
Developer mode is now enabled.

instruments + UIAutomation from shell script

Sounds like something I am going to have to dive into soon myself.

I'd be curious what happens if you add your instruments command to /etc/sudoers and then try to run. Might avoid the auth prompt you're seeing.

To give it a try:

  1. "sudo visudo" in a terminal

  2. Add this line (replacing "yourargs" with the rest of your instruments command)

yourUserName ALL=NOPASSWD: /usr/bin/instruments yourargs

Then try running the command the Jenkins agent is trying to run, prefixing it with "sudo", e.g. "sudo instruments ..."

UIAutomation : Failed to authorize rights with status: -60007

That's the answer I posted at Instruments via command line - jenkins

And here is even a blog post about Xcode command line authorization prompt error

I will explain it again here:

What I did was the following:

  • Mark jenkins user as admin (unfortunately it seems that there is no other way atm)
  • Go to /etc/authorization
  • search for key system.privilige.taskport
  • change value of allow-root to true

    <key>system.privilege.taskport</key>
    <dict>
    <key>allow-root</key>
    <false/> // change to -> <true>
    <key>class</key>
    <string>user</string>
    <key>comment</key>
    <string>Used by task_for_pid(...).
    ...
    </dict>

Now I am being able to use jenkins to run my UIAutomation-Tests via Command Line Script

EDIT

To make jenkins recognize a successfull build, I have not a perfect solution but the following workaround:

...
echo "Run instruments simulator"

instruments -t "$ORDER_AUTOMATION_TEST_TEMPLATE_PATH" "$FILE_DEBUG_APP" -e UIASCRIPT "$ORDER_AUTOMATION_TESTSCRIPT_PATH" -e UIARESULTSPATH "$DIRECTORY_INSTRUMENTS_RESULT"

returnCode=0

if test -a "Run 1/Assertion failed.png"; then
echo "failed"
returnCode=1
else
echo "passed"
returnCode=0
fi

rm -fR "Run 1"

rm -fR "instrumentscli0.trace"

echo "Removing app dir"

echo "$FILE_APPLICATIONS"

rm -fR "$FILE_APPLICATIONS"

echo $returnCode

exit $returnCode

EDIT 2
Better way to check if automation test did run successfully:

# cleanup the tracefiles produced from instruments
rm -rf *.trace

##kill simulator afterwards
killall "iPhone Simulator"

##check if failures occured
# fail script if any failures have been generated
if [ `grep "<string>Error</string>" "$WORKSPACE/Automation Results/Run 1/Automation Results.plist" | wc -l` -gt 0 ]; then
echo 'Build Failed'
exit -1
else
echo 'Build Passed'
exit 0
fi

Run Instruments 4.3 from the cmd line?

The problem is that you're specifying the -w parameter but not supplying a device ID. If you're trying to run from your app in the simulator, then just leave out the -w like so.

xcrun instruments -v \
-t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
/Users/cliff/Src/MyApp/build/MyApp/Build/Products/Debug-iphoneos/MyApp.app \
-e UIASCRIPT /Users/cliff/Src/MyApp/UIAutomation/automation-test.js \
-e UIARESULTSPATH /Users/cliff/Src/MyApp/build/uiautomation

If you really are trying to run this automation script on the device, then you can quickly grab the device ID by using this script I wrote. Hand that ID in to the -w parameter and it should work fine.

Is there a way to send some arguments through the instruments command-line where UI Automation script could access them?

Alas, not at this time. The command line arguments get sent to the application itself (which is the launched process), but the automation script has no access to any command line arguments or even environment variables for that matter. Please file a bug report with Apple about this. The more they hear about it, the higher on their priority list it will go.

Your suggestion to have a shell script execute different automation scripts is what I do and it works well.

Can the UI Automation instrument be run from the command line?

instruments -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/\
PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>

for xcode >= 4.5

instruments -t
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/\
AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>

for xcode >= 6.1

instruments -w <device ID> -t \
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/\
AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>

There a few important things to note though:

  1. the -w parameter is not required unless you want to run the scripts on your device. If you want to run your scripts on the simulator, simply omit this parameter from the command.
  2. full_path_to_application is the path to your .app file that is created by your simulator. For me, the path was

    /Users/fwasim/Library/Application Support/iPhone Simulator/5.0/Applications/AA6BA2E1-D505-4864-BECC-29ADEE28194D/name_of_application.app

    this path might be different for anyone else depending on what iOS version are you running on your simulator. Also remember to put this path in double quotation marks.

  3. The path_to_script.js should be the FULL PATH to where your automation script written in javascript is saved. Also remember to put this path in double quotation marks.

  4. Lastly output results path is the path where you want to save the output results. Also remember to put this path in double quotation marks.

These were the points I had been missing on and thus was getting some of the errors mentioned above.



Related Topics



Leave a reply



Submit