0

I am running automated UI tests that depend on a clean build for every run.

I'd like to add a pre-action run script that clears out anything in the Application Support directory (e.g. /Users/username/Library/Application Support/iPhone Simulator/7.1/Applications/58A5DCF7-689B-4D13-B178-A88CDE33512/Library/Application Support)

Is there an Xcode variable that makes it easy to get to that directory? Anything like $(BUILD_DIR)?

dKrawczyk
  • 329
  • 1
  • 2
  • 10
  • Although the answer from @user1041311 does clear out the Application Support directory, it also forces the entire simulator to be restarted. Any chance someone else knows a variable that gets to the "Application Support" directory? – karlbecker_com Jan 30 '15 at 22:40

1 Answers1

1

Here is what works for me:

#!/bin/bash

# `menu_click`, by Jacob Rus, September 2006
# 
# Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
# Execute the specified menu item.  In this case, assuming the Finder 
# is the active application, arranging the frontmost folder by date.

osascript <<SCRIPT

on menu_click(mList)
    local appName, topMenu, r

    -- Validate our input
    if mList's length < 3 then error "Menu list is not long enough"

    -- Set these variables for clarity and brevity later on
    set {appName, topMenu} to (items 1 through 2 of mList)
    set r to (items 3 through (mList's length) of mList)

    -- This overly-long line calls the menu_recurse function with
    -- two arguments: r, and a reference to the top-level menu
    tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
        (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
    local f, r

    -- `f` = first item, `r` = rest of items
    set f to item 1 of mList
    if mList's length > 1 then set r to (items 2 through (mList's length) of mList)

    -- either actually click the menu item, or recurse again
    tell application "System Events"
        if mList's length is 1 then
            click parentObject's menu item f
        else
            my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
        end if
    end tell
end menu_click_recurse

application "iPhone Simulator" activate    
menu_click({"iPhone Simulator", "iOS Simulator", "Reset Content and Settings…"})

tell application "System Events"
    tell process "iPhone Simulator"
        tell window 1
            click button "Reset"
        end tell
    end tell
end tell

SCRIPT

Taken from: https://stackoverflow.com/a/14811280/1041311

Also note that it wonk work for the first time, since you need to allow Xcode to modify folders. At first run there will be dialog which will take you to System preferences where you need to give Xcode that permissions.

Community
  • 1
  • 1