html
测试报告The test report
js
function addLog(message, logType, isTitle) {
if (isTitle == 1) {
addTitle(message)
} else {
if (logType == 0) {
addNoneLog(message)
} else if (logType == 1) {
addInfoLog(message)
} else if (logType == 2) {
addPrimaryLog(message)
} else if (logType == 3) {
addWarnLog(message)
} else if (logType == 4) {
addDangerLog(message)
} else if (logType == 5) {
addMessageLog(message)
} else if (logType == 6) {
addDetailLog(message)
}
}
return logType
}
function createDOMElement(message, className) {
var reportContent = document.getElementById("reportContent");
var titleBox = document.createElement("div")
titleBox.innerHTML = message
titleBox.className = className
reportContent.appendChild(titleBox)
window.scrollTo(0, document.body.offsetHeight)
}
function addTitle(message) {
createDOMElement(message, "title log-none")
}
function addNoneLog(message) {
createDOMElement(message, "log-font log-none")
}
function addInfoLog(message) {
createDOMElement(message, "log-font log-info")
}
function addPrimaryLog(message) {
createDOMElement(message, "log-font log-primary")
}
function addWarnLog(message) {
createDOMElement(message, "log-font log-warn")
}
function addDangerLog(message) {
createDOMElement(message, "log-font log-danger")
}
function addMessageLog(message) {
createDOMElement(message, "log-font log-message")
}
function addDetailLog(message) {
createDOMElement(message, "log-font log-detail")
}
function logResult(result) {
result = result.toLowerCase();
if (result.search("pass") != -1) {
return "pass";
} else if (result.search("fail") != -1) {
return "fail";
} else if (result.search("shutdown") != -1) {
return "log-warn";
} else {
return "log-none";
}
}
function changeResultColor(result) {
var reportContent = document.getElementById("reportContent");
var seperate = document.createElement("br")
reportContent.appendChild(seperate)
var noneList = getElementsByClassName("log-none", reportContent, 'div')
for (var i = 0; i < noneList.length; i++) {
var className = noneList[i].className
index = className.search("log-none")
noneList[i].className = className.slice(0, index) + logResult(result);
if (noneList[i].className.search("title") != -1) {
noneList[i].innerHTML += " ... " + result
}
}
}
function getElementsByClassName(searchClass, node, tag) {
if (document.getElementsByClassName) {
var nodes = (node || document).getElementsByClassName(searchClass),
result = [];
for (var i = 0; node = nodes[i++];) {
if (tag !== "*" && node.tagName === tag.toUpperCase()) {
result.push(node)
}
}
return result
} else {
var node = node || document;
var tag = tag || "*";
var result = [];
var classes = searchClass.split(" "),
elements = (tag === "*" && node.all) ? node.all : node.getElementsByTagName(tag),
patterns = [],
current,
match;
var i = classes.length;
while (--i >= 0) {
patterns.push(new RegExp("(^|\\s)" + classes[i] + "(\\s|$)"));
}
var j = elements.length;
while (--j >= 0) {
current = elements[j];
match = false;
for (var k = 0, kl = patterns.length; k < kl; k++) {
match = patterns[k].test(current.className);
if (!match) break;
}
if (match) result.push(current);
}
return result;
}
}
function destroyAllElement() {
var reportContent = document.getElementById("reportContent");
reportContent.innerHTML = ""
}