Viewing Information Returned from WSH

To collect results of a WSH execution, the WSH script must generate a file called output.xml in the current working directory of the WSH test. All files residing in this directory are stored in the database and are downloadable through the list of files for the test execution. Files are excluded from storage when their extensions are defined under the file extensions to ignore in results property in the Projects area.

Note: The current working directory is dynamically created for each WSH execution. Do not use an absolute path when creating the file. Any relative path used will correctly refer to the current working directory.

Any information that a script writes to the WSH standard output goes into the log.txt text file that resides in the current working directory. This file is stored in the database and can be viewed as it is included in the file list of the test execution.

The following example shows how to print log information from a script:

 WScript.Echo "This info will be written to the log.txt file"

The XML structure of output.xml begins with an element ResultElement that defines an attribute named TestItem, which specifies the name of the ResultElement.

The ResultElement must contain an element named ErrorCount, optionally an element named WarningCount, and a list of Incident elements.

The ErrorCount and WarningCount elements must contain a positive number or zero. The ErrorCount and WarningCount of the top-level ResultElement are used for evaluating success conditions, which determine if a test has passed or failed. The XML file might contain additional elements that are not visible in the Silk Central GUI. The output.xml file is however stored in the database and is viewable as it is included in the file list of the executed test.

The Incident element represents an event that happened during the execution of the WSH test. Message and Severity are shown in the messages list of test executions in the Silk Central GUI. An Incident element must contain a Message and a Severity element.

The Severity element must hold one of the following values:

You can store additional information in the result file. The ResultElement may contain any number of sub-ResultElements, so information can be easily grouped. Sub-ResultElements make the result file easier to read. For compatibility reasons related to unit tests, JUnit and NUnit, ResultElement can be named TestSuite or Test.

The ResultElement may contain the following additional elements:

The Incident element may contain a list of Detail elements.

The Detail element represents detailed information about an Incident. It must define a TestName element and an Info element. The TestName is used to give detailed information about where the Incident happened. The Info element holds detailed information about the Incident, for example a stack trace.

Note: Up through Silk Central 8.1, the value of the Message and Info elements had to be URL encoded (ISO-8859-1). Since version 8.1.1, URL encoding is no longer allowed.

Sample Result File

<ResultElement TestItem="WshOutputTest">
  <ErrorCount>1</ErrorCount> 
  <WarningCount>1</WarningCount>
  <Incident>
    <Message>some unexpected result</Message>
    <Severity>Error</Severity>
    <Detail>
      <TestName>function main()</TestName>
      <Info>some additional info; eg. stacktrace</Info>
    </Detail>
  </Incident>
  <Incident>
    <Message>some warning message</Message>
    <Severity>Warning</Severity>
    <Detail>
      <TestName>function main()</TestName>
      <Info>some additional info; eg. stacktrace</Info>
    </Detail>
  </Incident>
</ResultElement>

Java Script Sample

The following script was used to generate the sample result file. To try this script save it with the extension .js.

function dumpOutput(dumpFile)
{
  dumpFile.WriteLine("<ResultElement TestItem=\"WshOutputTest\">");
  dumpFile.WriteLine("  <ErrorCount>1</ErrorCount>");
  dumpFile.WriteLine("  <WarningCount>1</WarningCount>");
	dumpFile.WriteLine("  <Incident>");
	dumpFile.WriteLine("    <Message>some unexpected result</Message>");
	dumpFile.WriteLine("    <Severity>Error</Severity>");
	dumpFile.WriteLine("    <Detail>");
	dumpFile.WriteLine("      <TestName>function main()</TestName>");
	dumpFile.WriteLine("      <Info>some additional info; eg. stacktrace</Info>");
	dumpFile.WriteLine("    </Detail>");
	dumpFile.WriteLine("  </Incident>");
	dumpFile.WriteLine("  <Incident>");
	dumpFile.WriteLine("    <Message>some warning message</Message>");
	dumpFile.WriteLine("    <Severity>Warning</Severity>");
	dumpFile.WriteLine("    <Detail>");
	dumpFile.WriteLine("      <TestName>function main()</TestName>");
	dumpFile.WriteLine("      <Info>some additional info; eg. stacktrace</Info>");
	dumpFile.WriteLine("    </Detail>");
	dumpFile.WriteLine("  </Incident>");
  dumpFile.WriteLine("</ResultElement>");
}

function main()
{
  var outFile;
  var fso;
  fso = WScript.CreateObject("Scripting.FileSystemObject");
  outFile = fso.CreateTextFile("output.xml", true, true); 
  outFile.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
  
  dumpOutput(outFile);
  outFile.Close();
  WScript.Echo("Test is completed");	
}

main();
WScript.Quit(0);

Visual Basic Script Sample

The following Visual Basic script also generates the sample result file, and saves it as Output.xml. To try this script save it with the extension .vbs.

WScript.Echo "starting"

Dim outFile
Dim errCnt
Dim warningCnt

outFile = "output.xml"
errCnt = 1 ' retrieve that from your test results
warningCnt = 1 ' retrieve that from your test results

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oTX = FSO.OpenTextFile(outFile, 2, True, -1) ' args: file, 8=append/2=overwrite, create, ASCII

oTX.WriteLine("<?xml version=""1.0"" encoding=""UTF-16""?>") 
oTX.WriteLine("<ResultElement TestItem=""PerlTest"">")
oTX.WriteLine("  <ErrorCount>" & errCnt & "</ErrorCount>")
oTX.WriteLine("  <WarningCount>" & warningCnt & "</WarningCount>")
oTX.WriteLine("  <Incident>")
oTX.WriteLine("    <Message>some unexpected result</Message>")
oTX.WriteLine("    <Severity>Error</Severity>")
oTX.WriteLine("    <Detail>")
oTX.WriteLine("      <TestName>function main()</TestName>")
oTX.WriteLine("      <Info>some additional info; eg. stacktrace</Info>")
oTX.WriteLine("    </Detail>")
oTX.WriteLine("  </Incident>")
oTX.WriteLine("  <Incident>")
oTX.WriteLine("    <Message>some warning message</Message>")
oTX.WriteLine("    <Severity>Warning</Severity>")
oTX.WriteLine("    <Detail>")
oTX.WriteLine("      <TestName>function main()</TestName>")
oTX.WriteLine("      <Info>some additional info; eg. stacktrace</Info>")
oTX.WriteLine("    </Detail>")
oTX.WriteLine("  </Incident>")
oTX.WriteLine("</ResultElement>")