我正在运行自动化UI测试,这些测试依赖于每次运行的干净构建。
我想添加一个预操作运行脚本,清除Application Support目录中的任何内容(例如/Users/username/Library/Application Support/iPhone Simulator/7.1/Applications/58A5DCF7-689B-4D13-B178-A88CDE33512/Library/Application Support
)
是否有一个Xcode变量可以轻松访问该目录?像$(BUILD_DIR)这样的东西?
答案 0 :(得分:1)
这对我有用:
#!/斌/庆典
# `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
取自:https://stackoverflow.com/a/14811280/1041311
另请注意,它首次胜出,因为您需要允许Xcode修改文件夹。首次运行时会出现一个对话框,它将带您进入系统首选项,您需要为Xcode提供权限。