forked from toursprung/iOS-Screenshot-Automator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun
executable file
·136 lines (104 loc) · 4.55 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env osascript
on run argv
-- Set all devices you want to use for screenshots here
-- (has to match one of the names returned by 'instruments -w x' command)
-- Possible options for iOS 7.1
-- iPhone - Simulator - iOS 7.1
-- iPhone Retina (3.5-inch) - Simulator - iOS 7.1
-- iPhone Retina (4-inch) - Simulator - iOS 7.1
-- iPhone Retina (4-inch 64-bit) - Simulator - iOS 7.1
-- iPad - Simulator - iOS 7.1
-- iPad Retina - Simulator - iOS 7.1
-- iPad Retina (64-bit) - Simulator - iOS 7.1
set allDevices to {"iPhone Retina (4-inch) - Simulator - iOS 7.1", "iPhone Retina (3.5-inch) - Simulator - iOS 7.1" , "iPad Retina - Simulator - iOS 7.1"}
-- Set all languages your app is translated to.
set allLanguages to {"zh-Hans", "en", "fr", "de", "it", "ja", "ru", "es", "tr", "uk" }
set iOSVersion to "7.1"
setupFolders()
set userName to short user name of (system info)
if count of argv < 2 then
logEvent("Usage: ./run TestScript.js AppName")
error number -128
end
set scriptName to item 1 of argv
set appName to item 2 of argv
set automationTemplatePath to "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
set applicationsFolder to "/Users/" & userName & "/Library/Application Support/iPhone Simulator/" & iOSVersion & "/Applications/"
set applicationsFolderPosix to POSIX file applicationsFolder
tell application "Finder"
set subFolders to every folder of folder applicationsFolderPosix
end tell
repeat with currentFolder in subFolders
tell application "Finder"
set subFiles to every file of currentFolder
end tell
repeat with currentSubfolder in subFiles
-- inside the app
if (currentSubFolder as string) contains (appName & ".app") then
set appFolderName to currentSubFolder
end if
end repeat
end repeat
if not appFolderName as string = "" then
logEvent("Found the app: " & appFolderName)
else
logEvent("Couldn't find the app you were looking for")
error number -128
end if
set unixPathToApplication to (the POSIX path of (appFolderName as alias))
logEvent("Unix Path: " & unixPathToApplication)
set errorLog to " "
repeat with currentDevice in allDevices
repeat with currentLang in allLanguages
do shell script "./changeLanguage " & currentLang
logEvent("Changed language to " & currentLang)
set instrumentsCommand to "instruments -w \"" & currentDevice & "\" -t " & automationTemplatePath & " \"" & unixPathToApplication & "\" -e UIASCRIPT \"" & scriptName & "\" -e UIARESULTSPATH Results"
logEvent("Executing " & instrumentsCommand)
set currentResults to do shell script instrumentsCommand
if (currentResults as string) contains "Fail:" then
set errorLog to (errorLog & currentResults)
end if
logEvent("Results: " & currentResults)
try
do shell script "mv Results/Run\\ 1/* Latest/"
do shell script "rm -rf Results/Run\\ 1"
on error errMsg
logEvent(errMsg)
end try
tell application "iPhone Simulator" to quit
end repeat
end repeat
do shell script "rm -rf ./instrumentscli*"
if length of errorLog > 10 then
logEvent("Some errors occurred: " & errorLog)
do shell script "echo '" & errorLog & "' > Latest/errorLog.txt"
end if
end run
on logEvent(themessage)
-- All the recent events, results and error can be found at the give path
-- It can easily be opened with the regular "Console" app
set theLine to (do shell script "date +'%Y-%m-%d %H:%M:%S'" as string) & " " & themessage
do shell script "echo '" & theLine & "' >> ~/Library/Logs/AppleScript-events.log"
end logEvent
on setupFolders()
-- Clear useless instrumentscli files and copy the screenshots to the proper folder
-- If you prefer other folder names, just change it here.
do shell script "rm -rf ./instrumentscli*"
try
do shell script "mkdir Results"
on error errMsg -- to ignore errors when the folder already exists
end try
do shell script "rm -rf Results/Run*"
do shell script "mkdir Results/Build-" & (do shell script "date +'%Y.%m.%d-%H:%M:%S'" as string)
-- Create the link to the latest build
try
do shell script "rm Latest"
on error errMsg -- to ignore errors when the folder was not yet created
end try
do shell script "ln -s Results/Build-" & (do shell script "date +'%Y.%m.%d-%H:%M:%S'" as string) & " Latest"
try
do shell script "mv Results/Run* Results/Build-" & (do shell script "date +'%Y.%m.%d-%H:%M:%S'" as string) & "/"
on error errMsg
logEvent(errMsg)
end try
end setupFolders