-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
174 lines (159 loc) · 7.43 KB
/
script.js
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Uncomment for local tests and disable browser file CORS security, avoid to drag & drop the file each time
/*var request = new XMLHttpRequest();
//request.open("GET", "./playmode-results-all-ok.xml", true);
request.open("GET", "./playmode-results-some-failed.xml", true);
request.onreadystatechange = function () {
if (request.readyState == 4) {
if (request.status == 200) {
ProcessXMLDocument(request.responseXML);
}
}
}
request.send();*/
const report = document.getElementById("report");
report.hidden = true;
const fileInput = document.getElementById("fileInput");
function clicHandler(ev) {
if(document.createEvent) {
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, false);
fileInput.dispatchEvent(evt);
}
}
function fileChangeHandler(ev) {
if (ev.target.files[0]) {
ProcessFile(ev.target.files[0]);
}
}
function dragOverHandler(ev) {
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
}
function dropHandler(ev) {
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
[...ev.dataTransfer.items].forEach((item, i) => {
// If dropped items aren't files, reject them
if (item.kind === "file") {
const file = item.getAsFile();
ProcessFile(file);
}
});
} else {
// Use DataTransfer interface to access the file(s)
[...ev.dataTransfer.files].forEach((file, i) => {
console.log(`… file[${i}].name = ${file.name}`);
});
}
}
function ProcessFile(file) {
if (file.type === "text/xml") {
var reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function (evt) {
const parser = new DOMParser();
const xmlDocument = parser.parseFromString(evt.target.result, file.type);
ProcessXMLDocument(xmlDocument);
}
reader.onerror = function (evt) {
document.getElementById("fileContents").innerHTML = "error reading file";
}
}
}
function ProcessXMLDocument(xmlDocument) {
const testCases = xmlDocument.getElementsByTagName("test-case");
var passsedTestCases = xmlDocument.createDocumentFragment();
var failedTestCases = xmlDocument.createDocumentFragment();
var skippedTestCases = xmlDocument.createDocumentFragment();
for (var i = 0; i < testCases.length; i++) {
if (testCases[i].attributes["result"].value === "Passed") {
passsedTestCases.appendChild(testCases[i].cloneNode(true));
} else if (testCases[i].attributes["result"].value === "Failed") {
failedTestCases.appendChild(testCases[i].cloneNode(true));
} else if (testCases[i].attributes["result"].value === "Skipped") {
skippedTestCases.appendChild(testCases[i].cloneNode(true));
}
}
report.hidden = false;
document.getElementById("test-cases").textContent = '';
ProcessSummary(xmlDocument);
ProcessFailedTests(failedTestCases);
ProcessSkippedTests(skippedTestCases);
ProcessPassedTests(passsedTestCases);
}
function ProcessSummary(xmlDocument) {
document.getElementById("total-count").innerText = "Tests: " + xmlDocument.firstChild.attributes["testcasecount"].value;
document.getElementById("failed-count").innerText = "Failed: " + xmlDocument.firstChild.attributes["failed"].value;
document.getElementById("passed-count").innerText = "Passed:" + xmlDocument.firstChild.attributes["passed"].value;
document.getElementById("inconclusive-count").innerText = "Inconclusive: " + xmlDocument.firstChild.attributes["inconclusive"].value;
document.getElementById("skipped-count").innerText = "Skipped: " + xmlDocument.firstChild.attributes["skipped"].value;
document.getElementById("date").innerText = "Date: " + xmlDocument.firstChild.attributes["start-time"].value;
document.getElementById("duration").innerText = "Duration: " + xmlDocument.firstChild.attributes["duration"].value;
}
function ProcessFailedTests(failedTestCases) {
const template = document.getElementById("template-failed");
const root = document.getElementById("test-cases");
for (var i = 0; i < failedTestCases.childNodes.length; i++) {
const testCase = failedTestCases.childNodes[i];
let testCaseHtml = template.content.cloneNode(true);
const elements = testCaseHtml.children[0].children;
elements[0].textContent = testCase.attributes["fullname"].value;
elements[1].childNodes[3].textContent = "Duration: " + testCase.attributes["duration"].value;
elements[3].textContent = testCase.getElementsByTagName("failure")[0].getElementsByTagName("message")[0].textContent;
const output = testCase.getElementsByTagName("output")[0];
if (output !== undefined) {
elements[7].textContent = output.textContent;
} else {
testCaseHtml.children[0].removeChild(elements[7]);
testCaseHtml.children[0].removeChild(elements[6]);
}
const stackTrace = testCase.getElementsByTagName("failure")[0].getElementsByTagName("stack-trace")[0];
if (stackTrace !== undefined) {
elements[5].textContent = stackTrace.textContent;
} else {
testCaseHtml.children[0].removeChild(elements[5]);
testCaseHtml.children[0].removeChild(elements[4]);
}
root.appendChild(testCaseHtml);
}
}
function ProcessSkippedTests(skippedTestCases) {
const template = document.getElementById("template-skipped");
const root = document.getElementById("test-cases");
for (var i = 0; i < skippedTestCases.childNodes.length; i++) {
const testCase = skippedTestCases.childNodes[i];
let testCaseHtml = template.content.cloneNode(true);
const elements = testCaseHtml.children[0].children;
elements[0].textContent = testCase.attributes["fullname"].value;
elements[1].childNodes[3].textContent = "Duration: " + testCase.attributes["duration"].value;
const reason = testCase.getElementsByTagName("reason")[0].getElementsByTagName("message")[0];
if (reason !== undefined) {
elements[3].textContent = reason.textContent;
} else {
testCaseHtml.children[0].removeChild(elements[3]);
testCaseHtml.children[0].removeChild(elements[2]);
}
root.appendChild(testCaseHtml);
}
}
function ProcessPassedTests(passsedTestCases) {
const template = document.getElementById("template-passed");
const root = document.getElementById("test-cases");
for (var i = 0; i < passsedTestCases.childNodes.length; i++) {
const testCase = passsedTestCases.childNodes[i];
let testCaseHtml = template.content.cloneNode(true);
const elements = testCaseHtml.children[0].children;
elements[0].textContent = testCase.attributes["fullname"].value;
elements[1].childNodes[3].textContent = "Duration: " + testCase.attributes["duration"].value;
const output = testCase.getElementsByTagName("output")[0];
if (output !== undefined) {
elements[3].textContent = output.textContent;
} else {
testCaseHtml.children[0].removeChild(elements[3]);
testCaseHtml.children[0].removeChild(elements[2]);
}
root.appendChild(testCaseHtml);
}
}