Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9074513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:39:08+00:00 2026-06-16T18:39:08+00:00

Did anyone succeed in setting up automated UIAutomation tests in Xcode? I’m trying to

  • 0

Did anyone succeed in setting up automated UIAutomation tests in Xcode?

I’m trying to set up a target in my Xcode project that should run all the UIAutomation scripts I prepared. Currently, the only Build Phase of this target is this Run Script block:

TEMPLATE="/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
MY_APP="/Users/Me/Library/Application Support/iPhone Simulator/6.0/Applications/564ED15A-A435-422B-82C4-5AE7DBBC27DD/MyApp.app"
RESULTS="/Users/Me/Projects/MyApp/Tests/UI/Traces/Automation.trace"
SCRIPT="/Users/Me/Projects/MyApp/Tests/UI/SomeTest.js"
instruments -t $TEMPLATE $MY_APP -e UIASCRIPT $SCRIPT -e UIARESULTSPATH $RESULTS

When I build this target it succeeds after a few seconds, but the script didn’t actually run. In the build log I get these errors:

instruments[7222:707] Failed to load Mobile Device Locator plugin
instruments[7222:707] Failed to load Simulator Local Device Locator plugin
instruments[7222:707] Automation Instrument ran into an exception while trying to run the script.  UIATargetHasGoneAWOLException
+0000 Fail: An error occurred while trying to run the script.
Instruments Trace Complete (Duration : 1.077379s; Output : /Users/Me/Projects/MyApp/Tests/UI/Traces/Automation.trace)

I am pretty sure, that my javascript and my run script are both correct, because if I run the exact same instruments command in bash it works as expected.
Could this be a bug in Xcode?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:39:09+00:00Added an answer on June 16, 2026 at 6:39 pm

    I finally found a solution for this problem. It seems like Xcode is running the Run Scripts with limited rights. I’m not entirely sure, what causes the instruments command to fail, but using su to change to your user will fix it.

    su $USER -l -c <instruments command>
    

    Obviously, this will ask you for your password, but you can’t enter it when running as a script. I didn’t find a way to specify the password for su, however if you run it as root, you don’t have to specify one. Luckily sudo can accept a password via the pipe:

    echo <password> | sudo -S su $USER -l -c <instruments command>
    

    If you don’t want to hardcode your password (always a bad idea), you could use some AppleScript to ask for the password.

    I posted the resulting script below. Copy that to a *.sh file in your project and run that script from a Run Script.

    #!/bin/bash
    
    # This script should run all (currently only one) tests, independently from
    # where it is called from (terminal, or Xcode Run Script).
    
    # REQUIREMENTS: This script has to be located in the same folder as all the
    # UIAutomation tests. Additionally, a *.tracetemplate file has to be present
    # in the same folder. This can be created with Instruments (Save as template...)
    
    # The following variables have to be configured:
    EXECUTABLE="TestApp.app"
    
    # Optional. If not set, you will be prompted for the password.
    #PASSWORD="password"
    
    # Find the test folder (this script has to be located in the same folder).
    ROOT="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    
    # Prepare all the required args for instruments.
    TEMPLATE=`find $ROOT -name '*.tracetemplate'`
    EXECUTABLE=`find ~/Library/Application\ Support/iPhone\ Simulator | grep "${EXECUTABLE}$"`
    SCRIPTS=`find $ROOT -name '*.js'`
    
    # Prepare traces folder
    TRACES="${ROOT}/Traces/`date +%Y-%m-%d_%H-%M-%S`"
    mkdir -p "$TRACES"
    
    # Get the name of the user we should use to run Instruments.
    # Currently this is done, by getting the owner of the folder containing this script.
    USERNAME=`ls -l "${ROOT}/.." | grep \`basename "$ROOT"\` | awk '{print $3}'`
    
    # Bring simulator window to front. Depending on the localization, the name is different.
    osascript -e 'try
        tell application "iOS Simulator" to activate
    on error
        tell application "iOS-Simulator" to activate
    end try'
    
    # Prepare an Apple Script that promts for the password.
    PASS_SCRIPT="tell application \"System Events\"
    activate
    display dialog \"Password for user $USER:\" default answer \"\" with hidden answer
    text returned of the result
    end tell"
    
    # If the password is not set directly in this script, show the password prompt window.
    if [ -z "$PASSWORD" ]; then
        PASSWORD=`osascript -e "$PASS_SCRIPT"`
    fi
    
    # Run all the tests.
    for SCRIPT in $SCRIPTS; do
        echo -e "\nRunning test script $SCRIPT"
        COMMAND="instruments -t \"$TEMPLATE\" \"$EXECUTABLE\" -e UIASCRIPT \"$SCRIPT\""
        COMMAND="echo '$PASSWORD' | sudo -S su $USER -l -c '$COMMAND'"
        echo "$COMMAND"
        eval $COMMAND > results.log
    
        SCRIPTNAME=`basename "$SCRIPT"`
        TRACENAME=`echo "$SCRIPTNAME" | sed 's_\.js$_.trace_g'`
        mv *.trace "${TRACES}/${TRACENAME}"
    
        if [ `grep " Fail: " results.log | wc -l` -gt 0 ]; then
            echo "Test ${SCRIPTNAME} failed. See trace for details."
            open "${TRACES}/${TRACENAME}"
            exit 1
            break
        fi
    
    done
    
    rm results.log
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did anyone succeed in building BNFC with ghc-7.2.1 and alex-3? I was trying to
I'm trying to get the django-cms to work on google-app-engine. Did anyone succeed in
Did anyone get that to work? I mean, unit testing .Net CF apps on
I have started using the Three20 project for an iPhone/iPad application. Did anyone face
Did anyone set up something like this for himself using the existing node.js REPL?
Did anyone come across a free data generator that can create synthetic data to
Did anyone knows regular expression that validate the string against following criteria: Names can
I'm pretty sure that's a very difficult task. Did anyone out there know how
did anyone encountered a problem with excel_reader2, that the script got aborted by a
Did anyone try to read programmatically an Alibre Design CAD file? I see that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.