Skip to content

Commit dae53da

Browse files
author
Jurollet
authored
Merge pull request #2 from applidium/feature/display_application_logs
Feature/display application logs
2 parents 78f7bd6 + 7cebc5b commit dae53da

File tree

4 files changed

+87
-7
lines changed

4 files changed

+87
-7
lines changed

XCTestHTMLReport/XCTestHTMLReport/Classes/HTMLTemplates.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,17 @@ struct HTMLTemplates
193193
flex-direction: column;
194194
}
195195
196-
#logs-iframe {
196+
#test-logs-iframe {
197197
border: 0;
198198
flex: 1;
199199
}
200200
201+
#app-logs-iframe {
202+
display: none;
203+
border: 0;
204+
flex: 1;
205+
}
206+
201207
#design-review {
202208
display: none;
203209
background-color: #F2F2F2;
@@ -908,6 +914,18 @@ struct HTMLTemplates
908914
setDisplayToElementsWithSelector('#right-sidebar', 'none');
909915
}
910916
917+
function showTestLogs(el) {
918+
selectedElement(el);
919+
showElementsWithSelector('#test-logs-iframe');
920+
hideElementsWithSelector('#app-logs-iframe');
921+
}
922+
923+
function showApplicationLogs(el) {
924+
selectedElement(el);
925+
showElementsWithSelector('#app-logs-iframe');
926+
hideElementsWithSelector('#test-logs-iframe');
927+
}
928+
911929
document.querySelectorAll('.device-info')[0].classList.add(\"selected\");
912930
document.querySelectorAll('.run')[0].classList.add(\"active\");
913931
@@ -944,10 +962,12 @@ struct HTMLTemplates
944962
<div id=\"logs\">
945963
<div id=\"logs-header\">
946964
<ul class=\"toolbar toggle-toolbar\">
947-
<li class=\"selected\">All Messages</li>
965+
<li onclick=\"showTestLogs(this);\" class=\"selected\">Test Logs</li>
966+
<li onclick=\"showApplicationLogs(this);\">App Logs</li>
948967
</ul>
949968
</div>
950-
<iframe id=\"logs-iframe\" src=\"logs-[[DEVICE_IDENTIFIER]].txt\"></iframe>
969+
<iframe id=\"test-logs-iframe\" src=\"test-logs-[[DEVICE_IDENTIFIER]].txt\"></iframe>
970+
<iframe id=\"app-logs-iframe\" src=\"app-logs-[[DEVICE_IDENTIFIER]].txt\"></iframe>
951971
</div>
952972
<div id=\"design-review\">
953973
[[TEST_DESIGN_REVIEW]]

XCTestHTMLReport/XCTestHTMLReport/Classes/Models/Run.swift

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ struct Run: HTML
126126
let activityLogs = logs[start..<end]
127127

128128
do {
129-
let file = "\(result.values.first!)/logs-\(runDestination.targetDevice.uniqueIdentifier).txt"
129+
let file = "\(result.values.first!)/test-logs-\(runDestination.targetDevice.uniqueIdentifier).txt"
130130
try activityLogs.write(toFile: file, atomically: false, encoding: .utf8)
131131
}
132132
catch let e {
133133
Logger.error("An error has occured while create the activity log file for \(root). Error: \(e)")
134134
}
135+
136+
generateApplicationLog(from: parentDirectory)
135137
}
136138
}
137139

@@ -153,4 +155,42 @@ struct Run: HTML
153155
]
154156
}
155157

158+
// MARK: - Private
159+
160+
private func generateApplicationLog(from parentDirectory: String) {
161+
// The app log file we are looking for is at :
162+
// ./Diagnostics/<targetName>-X/<targetName>-X/StandardOutputAndStandardError-<bundleId>
163+
// where X is a random identifier
164+
let path = parentDirectory + "/Diagnostics"
165+
166+
guard let appLogsPath = getPath(
167+
from: path,
168+
startingWith: "StandardOutputAndStandardError-"
169+
) else {
170+
return
171+
}
172+
173+
let appLogFile = "\(result.values.first!)/app-logs-\(runDestination.targetDevice.uniqueIdentifier).txt"
174+
do {
175+
let appLogs = try String(contentsOfFile: appLogsPath)
176+
try appLogs.write(toFile: appLogFile, atomically: false, encoding: .utf8)
177+
} catch let e {
178+
Logger.error("An error has occured while create the application log file for \(path). Error: \(e)")
179+
}
180+
}
181+
182+
private func getPath(from parentPath: String, startingWith prefix: String) -> String? {
183+
guard
184+
let enumerator = FileManager.default.enumerator(atPath: parentPath),
185+
var paths = enumerator.allObjects as? [String] else {
186+
return nil
187+
}
188+
paths = paths.filter { $0.contains(prefix) }
189+
190+
guard paths.count == 1, let path = paths.first else {
191+
Logger.error("Should corresponds to a single path")
192+
return nil
193+
}
194+
return parentPath + "/" + path
195+
}
156196
}

XCTestHTMLReport/XCTestHTMLReport/HTML/index.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,17 @@
187187
flex-direction: column;
188188
}
189189

190-
#logs-iframe {
190+
#test-logs-iframe {
191191
border: 0;
192192
flex: 1;
193193
}
194194

195+
#app-logs-iframe {
196+
display: none;
197+
border: 0;
198+
flex: 1;
199+
}
200+
195201
#design-review {
196202
display: none;
197203
background-color: #F2F2F2;
@@ -902,6 +908,18 @@ <h2>No Selected Attachment</h2>
902908
setDisplayToElementsWithSelector('#right-sidebar', 'none');
903909
}
904910

911+
function showTestLogs(el) {
912+
selectedElement(el);
913+
showElementsWithSelector('#test-logs-iframe');
914+
hideElementsWithSelector('#app-logs-iframe');
915+
}
916+
917+
function showApplicationLogs(el) {
918+
selectedElement(el);
919+
showElementsWithSelector('#app-logs-iframe');
920+
hideElementsWithSelector('#test-logs-iframe');
921+
}
922+
905923
document.querySelectorAll('.device-info')[0].classList.add("selected");
906924
document.querySelectorAll('.run')[0].classList.add("active");
907925

XCTestHTMLReport/XCTestHTMLReport/HTML/run.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
<div id="logs">
1717
<div id="logs-header">
1818
<ul class="toolbar toggle-toolbar">
19-
<li class="selected">All Messages</li>
19+
<li onclick="showTestLogs(this);" class="selected">Test Logs</li>
20+
<li onclick="showApplicationLogs(this);">App Logs</li>
2021
</ul>
2122
</div>
22-
<iframe id="logs-iframe" src="logs-[[DEVICE_IDENTIFIER]].txt"></iframe>
23+
<iframe id="test-logs-iframe" src="test-logs-[[DEVICE_IDENTIFIER]].txt"></iframe>
24+
<iframe id="app-logs-iframe" src="app-logs-[[DEVICE_IDENTIFIER]].txt"></iframe>
2325
</div>
2426
<div id="design-review">
2527
[[TEST_DESIGN_REVIEW]]

0 commit comments

Comments
 (0)