SilkTest secrets. Part 1

@ Fr, 25 July, 18:42

There are undocumented features in any computer program. Some of them are added specially (e.g. Easter Eggs), other can be programmers' mistakes, and some of them are just unimplemented features.
In this article we will describe one of the SilkTest's undocumented features, the 2nd argument for LogError function.



LogError function is being used often enough. It is specified in SilkTest Help that this function has only one parameter, error string. However, if you type "LogError(" in the SilkTest Editor, you will see the tooltip like shown below

It is obvious, that this function accepts more than one argument.

Let's pass 2nd argument to LogError and see what will happen.

In the report you can see a small rectangular next to the error message. If you click on it, a message will appear "Command: second argument. Unable to execute command - File not found". SilkTest tries to execute LogError second parameter as if it is command. Let's pass a real command to it.

LogError("Error message", "calc.exe")

If you click the rectangular now, Calculator will start. Here is a simple example of how this feature can be used.

For example, we need to see screenshot when an error occurred. We just need to create a function which will create screenshot and specify needed command as the 2nd argument for LogError function.

[-] STRING CreateScreenShot ()
    [ ] STRING sBitmap
    [ ]
    [-] withoptions
        [ ] BindAgentOption (OPT_BITMAP_MATCH_COUNT, 1)
        [ ] sBitmap = "{GetProgramDir ()}\{GetTestCaseName ()}_{FormatDateTime (GetDateTime (), "_ddmmyyyy_hhnnss")}.bmp"
        [ ] Desktop.CaptureBitmap (sBitmap)
    [ ] return sBitmap

This function creates screenshot in the script folder and returns full path to the created file. And now we need to create new Error function.

[-] void Error (STRING sMsg)
    [ ] LogError (sMsg, "iexplore.exe {CreateScreenShot ()}")

Now you can use Error function instead of LogError in order to be able to open screenshots from SilkTest log.

You must be logged in in order to post comments