您好我有以下html文件
<!DOCTYPE html>
<html>
<head>
<title>Report</title>
<style type='text/css'>
.body {width: 100%;height: 100%;}
.left {border-right: groove;width: 20%;height: 100%;float: left;}
.right {width: 79%;height: 100%;float: right;}
.upperLeft {height: 28.2%;border-bottom: groove;}
.lowerLeft {top: 30%;height: 70%;}
#moduleList, #scriptList {font-weight: bold;}
table{margin-left:auto;margin-right:auto;font-size:90%;}
td{margin:0px;border:1px solid #31708f;padding:1px;height:32px;border-radius:2px;}
</style>
</head>
<body>
<div class='body' id='bodyDiv'>
<div class='left'>
<div class='upperLeft'>
<h2 style="color: grey; text-align: center;"><u>Modules</u></h2>
<ul id='moduleList'>
</ul>
</div>
<div class='lowerLeft'>
<h2 style="color: grey; text-align: center;"><u>Test Cases</u></h2>
<ul id='scriptList'>
</ul>
</div>
</div>
<div class='right'>
<table width=550 align=center id="testSummary">
<tr>
<td colspan=2 bgcolor='#286090' style='color:white;'> <b><center> Test Execution Summary</center></b></td>
</tr>
<tr>
<td bgcolor='#5bc0de' WIDTH='65%'>Total Test Cases Executed</td>
<td id='stbl_total' align='center'>-</td>
</tr>
<tr>
<td bgcolor='#5bc0de'>Total Pass Count</td>
<td id='stbl_pass' align='center' Style='Color:green'>-</td>
</tr>
<tr>
<td bgcolor='#5bc0de'>Total Fail Count</td>
<td id='stbl_fail' align='center' Style='Color:red'>-</td>
</tr>
<tr>
<td bgcolor='#5bc0de'>Start Time</td>
<td align=center>-</td>
</tr>
<tr>
<td bgcolor='#5bc0de'>End Time</td>
<td id='stbl_endtime' align='center' Style='Color:#264D73'>-</td>
</tr>
</table>
<hr>
<div class="testTableDiv">
<table width=800 align=center id="testTable">
<tr>
<td colspan=4 bgcolor='#286090' style='color:white;'> <b><center> Test Execution Details</center></b></td>
</tr>
<tr class="tableHeading">
<td bgcolor='#5bc0de' WIDTH='10%' align=center>Sl. No.</td>
<td bgcolor='#5bc0de' WIDTH='30%' align=center>Step Name</td>
<td bgcolor='#5bc0de' WIDTH='50%' align=center>Step Detail</td>
<td bgcolor='#5bc0de' WIDTH='10%' align=center>Status</td>
</tr>
</table>
</div>
</div>
</div>
<script type='text/javascript'>
var xmlData = '<Execution><MODULE Name="Billing Payments" StartTime="2:45:31 PM" EndTime="2:45:39 PM"><TESTCASE Name="BP01_One_Time_Payment" StartTime="2:45:31 PM" EndTime="2:45:36 PM"><ITERATION ID="1" StartTime="2:45:31 PM" EndTime="2:45:34 PM"><STEPRESULT Status="PASS" StepName="Test Step Pass 1" StepDetails="Test Step Details Pass 1" ScreenshotPath=""></STEPRESULT><STEPRESULT Status="PASS" StepName="Test Step Pass 2" StepDetails="Test Step Details Pass 2" ScreenshotPath="ScreenShot_Path_1"></STEPRESULT><STEPRESULT Status="FAIL" StepName="Test Step Failed 1" StepDetails="Test Step Details Failed 1" ScreenshotPath="ScreenShot_Path_2"/><STEPRESULT Status="DONE" StepName="Test Step Done 1" StepDetails="Test Step Details Done 1" ScreenshotPath=""/><STEPRESULT Status="DONE" StepName="Test Step Done 2" StepDetails="Test Step Details Done 2" ScreenshotPath=""/><STEPRESULT Status="DONE" StepName="Test Step Done 3" StepDetails="Test Step Details Done 3" ScreenshotPath=""/><SCREENSHOT Status="Screenshot" StepName="Screenshot for Navigation" ScreenshotPath="ScreenShot_Path_5"></SCREENSHOT><STEPRESULT Status="PASS" StepName="Test Step Pass 3" StepDetails="Test Step Details Pass 3" ScreenshotPath="ScreenShot_Path_3"></STEPRESULT><STEPRESULT Status="FAIL" StepName="Test Step Failed 2" StepDetails="Test Step Details Failed 1" ScreenshotPath="ScreenShot_Path_4"/><STEPRESULT Status="TERMINATE" StepName="Execution for the current iteration terminated due to failure in above step" StepDetails="Test Step Details Failed 1" ScreenshotPath=""/></ITERATION><ITERATION ID="2" StartTime="2:45:34 PM" EndTime="2:45:36 PM"><STEPRESULT Status="PASS" StepName="Test Step Pass 1" StepDetails="Test Step Details Pass 1" ScreenshotPath=""></STEPRESULT><STEPRESULT Status="PASS" StepName="Test Step Pass 2" StepDetails="Test Step Details Pass 2" ScreenshotPath="ScreenShot_Path_6"></STEPRESULT><STEPRESULT Status="FAIL" StepName="Test Step Failed 1" StepDetails="Test Step Details Failed 1" ScreenshotPath="ScreenShot_Path_7"/><STEPRESULT Status="DONE" StepName="Test Step Done 1" StepDetails="Test Step Details Done 1" ScreenshotPath=""/><STEPRESULT Status="DONE" StepName="Test Step Done 2" StepDetails="Test Step Details Done 2" ScreenshotPath=""/><STEPRESULT Status="DONE" StepName="Test Step Done 3" StepDetails="Test Step Details Done 3" ScreenshotPath=""/><SCREENSHOT Status="Screenshot" StepName="Screenshot for Navigation" ScreenshotPath="ScreenShot_Path_8"></SCREENSHOT><STEPRESULT Status="PASS" StepName="Test Step Pass 2" StepDetails="Test Step Details Pass 3" ScreenshotPath="ScreenShot_Path_9"></STEPRESULT><STEPRESULT Status="FAIL" StepName="Test Step Failed 2" StepDetails="Test Step Details Failed 1" ScreenshotPath="ScreenShot_Path_10"/></ITERATION></TESTCASE><TESTCASE Name="BP02_Enroll_Paperless" StartTime="2:45:36 PM" EndTime="2:45:39 PM"><ITERATION ID="1" StartTime="2:45:36 PM" EndTime="2:45:39 PM"><STEPRESULT Status="PASS" StepName="Test Step Pass 4" StepDetails="Test Step Details Pass 4" ScreenshotPath=""></STEPRESULT><STEPRESULT Status="PASS" StepName="Test Step Pass 5" StepDetails="Test Step Details Pass 5" ScreenshotPath="ScreenShot_Path_11"></STEPRESULT><STEPRESULT Status="FAIL" StepName="Test Step Failed 3" StepDetails="Test Step Details Failed 3" ScreenshotPath="ScreenShot_Path_12"/><STEPRESULT Status="DONE" StepName="Test Step Done 4" StepDetails="Test Step Details Done 4" ScreenshotPath=""/><STEPRESULT Status="DONE" StepName="Test Step Done 5" StepDetails="Test Step Details Done 5" ScreenshotPath=""/><STEPRESULT Status="DONE" StepName="Test Step Done 6" StepDetails="Test Step Details Done 6" ScreenshotPath=""/><SCREENSHOT Status="Screenshot" StepName="Screenshot for Navigation" ScreenshotPath="ScreenShot_Path_15"></SCREENSHOT><STEPRESULT Status="PASS" StepName="Test Step Pass 3" StepDetails="Test Step Details Pass 3" ScreenshotPath="ScreenShot_Path_13"></STEPRESULT><STEPRESULT Status="FAIL" StepName="Test Step Failed 4" StepDetails="Test Step Details Failed 4" ScreenshotPath="ScreenShot_Path_14"/></ITERATION></TESTCASE></MODULE><MODULE Name="Profile Management" StartTime="2:45:40 PM" EndTime="2:45:43 PM"><TESTCASE Name="PM01_Forgot_Username" StartTime="2:45:40 PM" EndTime="2:45:41 PM"><ITERATION ID="1" StartTime="2:45:40 PM" EndTime="2:45:41 PM"><STEPRESULT Status="PASS" StepName="Test Step Pass 6" StepDetails="Test Step Details Pass 6" ScreenshotPath=""></STEPRESULT><STEPRESULT Status="PASS" StepName="Test Step Pass 7" StepDetails="Test Step Details Pass 7" ScreenshotPath="ScreenShot_Path_16"></STEPRESULT><STEPRESULT Status="FAIL" StepName="Test Step Done 5" StepDetails="Test Step Details Failed 5" ScreenshotPath="ScreenShot_Path_17"/></ITERATION></TESTCASE><TESTCASE Name="PM02_Edit_Profile" StartTime="2:45:41 PM" EndTime="2:45:43 PM"><ITERATION ID="1" StartTime="2:45:42 PM" EndTime="2:45:43 PM"><STEPRESULT Status="PASS" StepName="Test Step Pass 8" StepDetails="Test Step Details Pass 6" ScreenshotPath=""></STEPRESULT><STEPRESULT Status="PASS" StepName="Test Step Pass 9" StepDetails="Test Step Details Pass 7" ScreenshotPath="ScreenShot_Path_16"></STEPRESULT><STEPRESULT Status="DONE" StepName="Test Step Done 8" StepDetails="Test Step Details Done 8" ScreenshotPath=""/><STEPRESULT Status="DONE" StepName="Test Step Done 9" StepDetails="Test Step Details Done 9" ScreenshotPath=""/><STEPRESULT Status="DONE" StepName="Test Step Done 10" StepDetails="Test Step Details Done 10" ScreenshotPath=""/></ITERATION></TESTCASE></MODULE></Execution>';
var startUp = function() {
document.getElementById('bodyDiv').style.height = window.screen.height+'px';
if (window.DOMParser){
parser=new DOMParser();
xmlDoc=parser.parseFromString(xmlData,"text/xml");
}
else { // Internet Explorer{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(xmlData);
}
var headNode = xmlDoc.getElementsByTagName('Execution');
var count = 1;
for(var i=0; i<headNode.length; i++) {
var modules = headNode[i].getElementsByTagName('module'.toUpperCase());
for(var j=0; j<modules.length; j++) {
document.getElementById("moduleList").appendChild(document.createElement("li")); // Creating li tags
// Getting total childs available in ul and writting desired data.
document.getElementById('moduleList').childNodes[j+1].innerHTML
= "<a onclick=updateModuleSummary('"+(modules[j].attributes['0'].value).replace(' ','_')+"')>"+ modules[j].attributes['0'].value +"</a>";
var testCases = modules[j].getElementsByTagName('testcase'.toUpperCase());
for(var k=0; k<testCases.length; k++) {
document.getElementById("scriptList").appendChild(document.createElement("li"));
var testCaseName = testCases[k].attributes['0'].value;
document.getElementById('scriptList').childNodes[count].innerHTML
= "<a onclick=updateTestCaseDetails('"+testCases[k].attributes['0'].value+"')>" + testCases[k].attributes['0'].value +"</a>";
//console.log(testCases[k].attributes['0'].value);
count++;
}
}
}
}();
function updateModuleSummary(moduleName) {
moduleName = moduleName.replace('_',' ');
var testCount = 0, passCount = 0, failCount = 0, warningCount = 0 ;
var headNode = xmlDoc.getElementsByTagName('Execution');
for(var i=0; i<headNode.length; i++) {
var modules = headNode[i].getElementsByTagName('module'.toUpperCase());
for(var j=0; j<modules.length; j++) {
if (moduleName === modules[j].attributes['0'].value) {
document.getElementById('testSummary').getElementsByTagName('tbody')[0].childNodes[8].innerHTML =
"<tr><td bgcolor='#5bc0de' WIDTH='65%'>Start Time</td><td bgcolor='white' align=center>"+modules[j].attributes['1'].value+"</td></tr>";
document.getElementById('testSummary').getElementsByTagName('tbody')[0].childNodes[10].innerHTML =
"<tr><td bgcolor='#5bc0de' WIDTH='65%'>End Time</td><td bgcolor='white' align=center>"+modules[j].attributes['2'].value+"</td></tr>";
var testCases = modules[j].getElementsByTagName('testcase'.toUpperCase());
for(var k=0; k<testCases.length; k++) {
var iterations = testCases[k].getElementsByTagName('iteration'.toUpperCase());
for(var l=0; l<iterations.length; l++) {
var stepDetails = iterations[l].getElementsByTagName('stepresult'.toUpperCase());
for(var m=0; m<stepDetails.length; m++) {
var stepStatus = stepDetails[m].attributes['0'].value;
testCount++;
if (stepStatus === 'FAIL')
failCount++;
else if(stepStatus === 'TERMINATE')
warningCount++;
else
passCount++;
}
}
}
}
}
}
//console.log(testCount+" "+passCount+" "+failCount+" "+warningCount);
document.getElementById('testSummary').getElementsByTagName('tbody')[0].childNodes[2].innerHTML =
"<tr><td bgcolor='#5bc0de' WIDTH='65%'>Total Test Cases Executed</td><td bgcolor='white' align=center>"+testCount+"</td></tr>";
document.getElementById('testSummary').getElementsByTagName('tbody')[0].childNodes[4].innerHTML =
"<tr><td bgcolor='#5bc0de' WIDTH='65%'>Total Pass Count</td><td bgcolor='white' align=center style='color: blue;'>"+passCount+"</td></tr>";
document.getElementById('testSummary').getElementsByTagName('tbody')[0].childNodes[6].innerHTML =
"<tr><td bgcolor='#5bc0de' WIDTH='65%'>Total Fail Count</td><td bgcolor='white' align=center style='color: red;'>"+failCount+"</td></tr>";
}
/* Updating all test case results */
function updateTestCaseDetails(testCaseName) {
var headNode = xmlDoc.getElementsByTagName('Execution');
var count = 1;
for(var i=0; i<headNode.length; i++) {
var modules = headNode[i].getElementsByTagName('module'.toUpperCase());
for(var j=0; j<modules.length; j++) {
var testCases = modules[j].getElementsByTagName('testcase'.toUpperCase());
for(var k=0; k<testCases.length; k++) {
if (testCaseName === testCases[k].attributes['0'].value) {
document.getElementById('testTable').getElementsByTagName('tbody')[0].childNodes[0].innerHTML =
"<tr><td colspan=4 bgcolor='#286090' style='color:white;'> <b><center> Test Execution Details :: "+testCaseName+"</center></b></td></tr>";
var iterations = testCases[k].getElementsByTagName('iteration'.toUpperCase());
for(var l=0; l<iterations.length; l++) {
var stepDetails = iterations[l].getElementsByTagName('stepresult'.toUpperCase());
for(var m=0; m<stepDetails.length; m++) {
document.getElementById("testTable").getElementsByTagName('tbody')[0].appendChild(document.createElement("tr"));
var stepName = stepDetails[m].attributes['1'].value;
var stepDetail = stepDetails[m].attributes['2'].value;
var stepStatus = stepDetails[m].attributes['0'].value;
if (stepStatus === 'FAIL' || stepStatus === 'Screenshot') {
var stepScreenshotPath = stepDetails[m].attributes['3'].value;
document.getElementById('testTable').getElementsByTagName('tbody')[0].childNodes[count+2].innerHTML =
"<tr><td bgcolor='white' WIDTH='10%' align=center>"+(count-1)+"</td><td bgcolor='white' WIDTH='30%' align=center>"+stepName+"</td><td bgcolor='white' WIDTH='50%' align=center>"+stepDetail+"</td><td bgcolor='white' WIDTH='10%' align=center ><a href="+stepScreenshotPath+" target=.blank>"+stepStatus+"</a></td></tr>";
}
else
document.getElementById('testTable').getElementsByTagName('tbody')[0].childNodes[count+2].innerHTML =
"<tr><td bgcolor='white' WIDTH='10%' align=center>"+(count-1)+"</td><td bgcolor='white' WIDTH='30%' align=center>"+stepName+"</td><td bgcolor='white' WIDTH='50%' align=center>"+stepDetail+"</td><td bgcolor='white' WIDTH='10%' align=center>"+stepStatus+"</td></tr>";
count++;
}
}
}
}
}
}
}
</script>
</body>
</html>
我想替换var xmlData =&#34;信息&#34;我使用vbscript从另一个xml文件中读取数据(正如我在HP UFT中所做的那样)请建议如何操作?
我有另一个xml文件,我已经阅读并存储在一个arraylist中,请建议找到这个html中特定行的方法,并使用vbscript将其替换为arraylist内容。
答案 0 :(得分:0)
正如你没有说出为什么使用.load而不是.loadxml不是一个选项(这可以在没有任何编程的情况下解决问题)......
要将文件中的常量字符串替换为另一个,请尝试使用:
sAll = Replace(sAll, "var xmlData = ""info""", sXML)
如果旧的不是常数,则需要一个RegExp来指定要替换的内容;对于结构化内容(如HTML或XML),这种天真的字符串操作可能会失败((不)改变你(不想)改变的东西。
第二个想法:
.load的文档描述了要加载的内容的参数:
xmlSource
A string containing a URL that specifies the location of the XML file.
但是JScript示例代码(xmlDoc.load("books.xml");
)表明一个简单的文件规范可以正常运行&#39;。所以在尝试解决other problems之前,请给.load一个机会。