0

Hi I have the following html file

<!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>

I want to replace the var xmlData = " info " with data I read from another xml file using vbscript (as I am doing this in HP UFT) please suggest how to do it?

I have the other xml file which I have read and stored in an arraylist please suggest ways to find the particular line in this html and replace it with the arraylist contents using vbscript.

Pritam Panda
  • 45
  • 1
  • 1
  • 11
  • (1) Why don't you use `xmlDoc.load` (and the equivalent method of DOMParser) to load the .xml directly? (2) `xmlDoc.loadXML` expects a string, why did you store your .xml in an ArrayList? – Ekkehard.Horner Feb 25 '15 at 11:19
  • I have stored the xml data in a string now . How do I replace the varxmlData with this string by finding searching the varxmlData = "info" in my html file . please suggest – Pritam Panda Feb 25 '15 at 11:46

1 Answers1

0

As you didn't say why using .load instead of .loadxml is not an option (which would solve the problem without any programming) ...

To replace a constant string in a file with another, try to get away with:

  1. Read file into memory: .OpenTextFile, .ReadAll
  2. Replace old with new: sAll = Replace(sAll, "var xmlData = ""info""", sXML)
  3. Write it (sAll) back: .CreateTextFile, .Write

If old isn't constant, you need a RegExp to specify what to replace; for structured content (like HTML or XML), such naive string operations may fail ((not) changing the things you (don't) want to change).

On second thought:

The docs for .load describe the parameter for the content to load by:

xmlSource

A string containing a URL that specifies the location of the XML file.

but the JScript sample code (xmlDoc.load("books.xml");) shows that a simple file specification 'works'. So before trying to solve other problems, give .load a chance.

Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • Thank You for the help..The issue is my xml file is in a local file and not on any server so that I can use its url to load it directly..could you please help me how to load the local xml file to html?? Or can you please help me with creating a regex for the above var xmldata ?? – Pritam Panda Feb 26 '15 at 07:25
  • My xml file is getting generated and stored in a local file....Is there any way I can load this xml to a html file? I have tried many methods as both the html and xml need to be in the same server or hosted in the same web server to load the xml contents into the html I am stuck badly. – Pritam Panda Feb 27 '15 at 03:15