Writing a Results File from SilkTest Workbench

When running a scripted test in SilkTest Workbench the IDE provides a pass or fail indication but there are no native methods for creating a printed results file. The attached filePrint.dll will, when referenced from your VB script, enable you to create a results file that will output either a plain text file or a webpage with colour. You can add print comments to the results file in a similar fashion to the Print(), LogError() and LogWarning() statements that are available in SilkTest Classic. If you specify an HTML out put this dll also allows you to specify foreground and background colours, font name and three font styles – bold, italic and bolditalic.

Closing the results file will automatically calculate the length of time taken to run the testcase and, if required, automatically display the results file.

Finally, wherever you see the statement ‘if param(x) is specified then param(y) is required’, a blank string is an acceptable parameter e.g. for the writeFile method with HTML output

writeFile(“data”,”blue”,””,””,”italic”)

 will print the word ‘data’ in blue italics on a white background using the default Arial font.


Adding the filePrint reference to the project

Copy filePrint.dll to a folder on your hard drive. A suggested place is to create a new folder in your SilkTest installation called ‘Workbench modules’; note that if you uninstall Silktest this folder will not be deleted.

You will need to add a reference to the filePrint.dll in your Workbench project to enable usage of the class libraries.

1.      From the  Workbench script IDE select the ‘Properties’ tab.

2.      Right-click on ‘References’ and select ‘Add Reference’

3.      ‘Browse’ to wherever you have placed filePrint.dll and select it

4.      Click ‘Open’

5.      Click ‘Okay’

The class library is now ready for use. 


filePrint Prototypes

First, create a new instance of the filePrint.dll.
Dim [object name] as new filePrint.results()

e.g. Dim results as New filePrint.results()


Print commands
openFile(param1, param2, param3, [optional] param4, [optional] param5, [optional] param6)

where
            param1 = name of the testcase
            param2 = the path to and the name of the results file. Acceptable file suffixes are htm,
html and txt.
            param3 = append or new (new = overwrite if the file exists, append will create the
file if it does not exist
            param4 = automatically open the results file at the end of the testcase. Parameters are "yes" or "no" - default is "yes". 
The following optional parameters are only used for html output:
param5 = font typeface. If the requested font does not exist on the system then the output will revert to the browser’s default font. This typeface only affects the name of the testcase which is written when the results file is created or re-opened. Default is ‘arial’.
param6 = font size. The font size declared here affects the entire results file output. Note that the testcase name will always be printed one size larger and in bold e.g. a font size of 4 will print the testcase name at size 3/bold. Default = 2.

The html and htm suffixes will automatically create webpage output. If the file suffix does not correspond to one of these three suffixes then an 'Invalid file suffix' error message will be thrown. The name of the testcase will be printed white-on-black for webpage output.
If param4 is required then param3 is required.
If param5 is required then param4 and param3 are required.

writeFile(param1, [optional] param2, [optional] param3, [optional] param4, [optional] param5)

where
            param1 = the information to be printed (string input only).
The following optional parameters are only used for html output: 
param2 = the font forecolour if HTML output has been specified in openFile. Default is black.
param3 = the font backcolour if HTML output has been specified in openFile. Default is white.
param4 = the font typeface if HTML output has been specified in openFile. If the requested font does not exist on the system then the output will revert to the browser’s default font. This typeface only affects the current line. Default is ‘arial’.
param5 = the font style where style can be ‘bold’, ‘italic’ or ‘bolditalic’. Default is no font style. This only affects the current line.
If param3 is specified then param2 is required.
If param4 is specified then param2 and param3 are required.
If param5 is specified then param2, param3 and param4 are required.
If param1 is prefixed with either LogWarning or LogError (both are case-insensitive)
e.g. writeFile("Logerror: failed to find window X")
then if HTML output has been specified filePrint will automatically print white-on-red for LogError and white-on-amber for LogWarning.

Please note that the amber used as the background in LogWarning is a user-defined colour (#FF8420). User-defined colours can be used directly whereas the sixteen pre-defined web colours have to be passed as a string. Suppose you had generic string variables called 'forecolour' and 'backcolour'; the user-defined amber would be passed as follows:
dim amber as string = "#FF8420"
dim forecolour as string=""
dim backcolour as string=""

forecolour=amber
whereas a pre-defined web colour must be passed as
backcolour="black"
e.g. writeFile("Customer name incorrect",forecolour,backcolour)

You can change the forecolour without changing the backcolour as follows:
e.g. writeFile("Customer name incorrect",forecolour)
will, in this case, print amber on white. You can also change the backcolour without changing the forecolour:
e.g. writeFile("Customer name incorrect",””,backcolour)
which will print black on black if the forecolour has not been previously changed.


closeFile([optional] param1)

where
param1 = ‘true’ or ‘false’. If ‘true’ (default) then fileprint will calculate and print the elapsed time for the testcase.

If webpage output has been specified and the elapsed time is required then start time, end time and elapsed time will all be displayed as white-on-navy. Elapsed time is calculated in milliseconds and is displayed as hours/minutes/seconds/remaining milliseconds.