Skip to content

Instantly share code, notes, and snippets.

@mbazaliy
Forked from idStar/automation.sh
Created July 24, 2013 15:53
Show Gist options
  • Save mbazaliy/6071859 to your computer and use it in GitHub Desktop.
Save mbazaliy/6071859 to your computer and use it in GitHub Desktop.
#!/bin/bash
# automation.sh
# Created by @idStar - Sohail Ahmed - September 2, 2012
# This script launches the UIAutomation Instrument targeting a pre-existing iOS Simulator app, from the command line.
# Works with Xcode 4.4.1 on Mountain Lion
#
# Usage:
# automation <"App Name.app"> <"testFile.js"> <"base test script path"> <"base iOS Simulator path"> <"results output directory">
#
# Example:
# automation.sh "REPS Pro.app" "/Users/sohail/Developer/appstronomy/repspro/UIAutomation/tests" "wip.js" "/Volumes/xcoderamdisk/iPhone Simulator/5.1/Applications" "/Users/sohail/Developer/appstronomy/repspro/UIAutomation/runs"
# Allow us to use spaces in quoted file names in Bash Shell, per http://stackoverflow.com/a/1724065/535054 (See Dennis Williamson's comment):
saveIFS="$IFS"; IFS='';
# ===== LOCATIONS =====
# START: Determine where this script file is located.
# Credit: http://stackoverflow.com/a/246128/535054
# Reasoning: We assume any other custom scripts we rely on are co-located with us.
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
done
SCRIPTS_PATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# END: Determine where this script file is located.
# UIAutomation Template location - Accurate as at Xcode 4.4.1.
INSTRUMENTS_TEMPLATE="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
# Reanimated command line parameters:
APP_NAME=$1 # The first command line argument is a quoted string, containing the name of app we are to find in the iOS Simulator's dynamic list of app directories
BASE_SCRIPT_PATH=$2 #The second command line argument is a quoted string to the path where test scripts are stored, such as the one passed in as the next argument.
SCRIPT_NAME=$3 # The third command line argument is a quoted string, containing the name of the JavaScript test file to run with Instruments' UIAutomation
BASE_APPS_PATH=$4 # The fourth command line argument is a quoted string, containing the path to a folder under which iOS Simulator apps can be found
RESULTS_PATH=$5 # The fifth command line argument is a quoted string, containing the path to a directory in which UIAutomation test results should be placed
# Derived / Found locations:
SCRIPT_PATH="$BASE_SCRIPT_PATH/$SCRIPT_NAME"
APP_PATH=`$SCRIPTS_PATH/findguid.sh $BASE_APPS_PATH $APP_NAME`
# Switch directory into the output directly, b/c otherwise, occasionally, Instruments will dump a .trace file in the directory from which this script is launched.
cd $RESULTS_PATH
# ===== RUN THE COMMAND =====
instruments -t $INSTRUMENTS_TEMPLATE $APP_PATH -e UIASCRIPT $SCRIPT_PATH -e UIARESULTSPATH $RESULTS_PATH
# Revert to the pre-existing IFS shell variable value so as not to leave shell with unintended side effects.
IFS="$saveIFS"
#!/bin/bash
# findguid.sh
# Created by @idStar - Sohail Ahmed - September 2, 2012
# This script finds the guid for a given iOS simulator app. Use in a pipe to get the full path
#
# Usage:
# findguid <"Base Apps Path"> <"App Name.app">
#
# The Base Apps Paths should be something like: "/Volumes/xcoderamdisk/iPhone Simulator/5.1/Applications"
# It is basically some parent folder under which recursive traversal would eventually find the app sought.
# The App Name should include the .app suffix. It should already be built for the simulator, in order for us to find it.
# Allow us to use spaces in quoted file names in Bash Shell, per http://stackoverflow.com/a/1724065/535054 (See Dennis Williamson's comment):
saveIFS="$IFS"; IFS='';
# ===== LOCATIONS =====
BASE_APPS_PATH=$1
APP_NAME=$2
cd $BASE_APP_PATH
# ===== RUN THE COMMAND =====
FULL_APP_PATH=`find $BASE_APPS_PATH -name $APP_NAME`
# ===== PROVIDE OUTPUT FOR PIPING =====
echo $FULL_APP_PATH
# Revert to the pre-existing IFS shell variable value so as not to leave shell with unintended side effects.
IFS="$saveIFS"
#!/bin/bash
# script_runner.sh
# Created by @idStar - Sohail Ahmed - September 2, 2012
# This script kicks off the automation.sh script, with pre-filled parameters (so the scripts we use can be more generic)
#
# Usage:
# script_runner.sh
#
# The idea is that you modify the variables in the section 'typical modifications' and then run this script from the command line.
# It will call the 'automation.sh' script, which will find your already built app in the iOS Simulator, and run the test file you requested.
# Allow us to use spaces in quoted file names in Bash Shell, per http://stackoverflow.com/a/1724065/535054 (See Dennis Williamson's comment):
saveIFS="$IFS"; IFS='';
# ===== START: TYPICAL MODIFICATIONS =====
# Configurable paths and names as suitable for your app under test:
BASE_APPS_PATH="/Volumes/xcoderamdisk/iPhone Simulator/5.1/Applications"
BASE_SCRIPT_PATH="/Users/sohail/Developer/appstronomy/repspro/UIAutomation/tests"
APP_NAME="REPS Pro.app"
TEST_FILE="wip.js"
RESULTS_PATH="/Users/sohail/Developer/appstronomy/repspro/UIAutomation/runs"
# ===== END: TYPICAL MODIFICATIONS =====
# ===== LOCATIONS =====
# START: Determine where this script file is located.
# Credit: http://stackoverflow.com/a/246128/535054
# Reasoning: We assume any other custom scripts we rely on are co-located with us.
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
done
SCRIPTS_PATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# END: Determine where this script file is located.
# ===== RUN THE COMMAND =====
$SCRIPTS_PATH/automation.sh $APP_NAME $BASE_SCRIPT_PATH $TEST_FILE $BASE_APPS_PATH $RESULTS_PATH
# Revert to the pre-existing IFS shell variable value so as not to leave shell with unintended side effects.
IFS="$saveIFS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment