Forum Discussion

ArmandsBruns's avatar
ArmandsBruns
Frequent Contributor
13 years ago

Convert JScript To VBScript

Hi,



Can you please convert me the following JScript function into its equivalent VBScript (TestComplete)



Thanks

-----------------------------------------------------

function getResults()

{

Log.Message("See Information data in the Additional Info panel", getInformationData());

}





function getInformationData()

{

var tempFolder = aqEnvironment.GetEnvironmentVariable("temp") + "\\" + Math.floor(Math.random() * 10000) + "\\";





aqFileSystem.CreateFolder(tempFolder);

Log.SaveResultsAs(tempFolder, lsXML);



var xDoc = Sys.OleObject("MSXML2.DOMDocument.4.0");

xDoc.load(tempFolder + "Description.tcLog");





// Warning count

var wrnC = VarToInteger(xDoc.selectSingleNode('Nodes/Node[@name="root"]/Prp[@name="warning count"]/@value').text);





//Error count

var errC = VarToInteger(xDoc.selectSingleNode('Nodes/Node[@name="root"]/Prp[@name="error count"]/@value').text);





//Execution time

var startTime = VarToFloat(xDoc.selectSingleNode('Nodes/Node[@name="root"]/Prp[@name="start time"]/@value').text);

var stopTime = VarToFloat(xDoc.selectSingleNode('Nodes/Node[@name="root"]/Prp[@name="stop time"]/@value').text);





aqFileSystem.DeleteFolder(tempFolder, true);



var res =

"Errors: " + errC + "\r\n" +

"Warnings: " + wrnC + "\r\n" +

"Start Time: " + DateTimeToStr(startTime) + "\r\n" +

"Stop Time: " + DateTimeToStr(stopTime) + "\r\n" +

"Run Time: " + aqConvert.DateTimeToFormatStr(stopTime - startTime, "%H:%M:%S");

return res;

}

-----------------------------------------------------
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Armands,


    I was unable to check the correct execution of this script, but you can try something like the script below:



    function getResults()

    result = getInformationData()

    Call Log.Message("See Information data in the Additional Info panel", result)

    end function



    function getInformationData()

    tempFolder = aqEnvironment.GetEnvironmentVariable("temp") + "\\" + Math.floor(Math.random() * 10000) + "\\"



    aqFileSystem.CreateFolder(tempFolder)

    Call Log.SaveResultsAs(tempFolder, lsXML)



    Set xDoc = Sys.OleObject("MSXML2.DOMDocument.4.0")

    xDoc.load(tempFolder + "Description.tcLog")



    ' Warning count

    wrnC = VarToInteger(xDoc.selectSingleNode("Nodes/Node[@name=""root""]/Prp[@name=""warning count""]/@value").text)



    'Error count

    errC = VarToInteger(xDoc.selectSingleNode("Nodes/Node[@name=""root""]/Prp[@name=""error count""]/@value").text)



    ' Execution time

    startTime = VarToFloat(xDoc.selectSingleNode("Nodes/Node[@name=""root""]/Prp[@name=""start time""]/@value").text)

    stopTime = VarToFloat(xDoc.selectSingleNode("Nodes/Node[@name=""root""]/Prp[@name=""stop time""]/@value").text)



    Call aqFileSystem.DeleteFolder(tempFolder, true)



    res = "Errors: " + errC + "\r\n" + "Warnings: " + wrnC + "\r\n" +  "Start Time: " + DateTimeToStr(startTime) + "\r\n" + "Stop Time: " + DateTimeToStr(stopTime) + "\r\n" + "Run Time: " + aqConvert.DateTimeToFormatStr(stopTime - startTime, "%H:%M:%S")

    getInformationData = res

    end function


    Does this work?