Call SilkTest Classic test scripts from within SilkTest Workbench

Silk Test

Silk Test
Master the automation of complex technologies for your most critical applications.

Silk Test Knowledge Base

Call SilkTest Classic test scripts from within SilkTest Workbench

It is possible to call SilkTest classic scripts via the command line, information on how this can be done can be found in the SilkTest Classic help topic "Starting SilkTest from the command line". Within a Workbench .Net Script - command line commands can be called via the "Shell" function.

In the example below, we pass the exact path of the SilkTest Classic script to the ClassicExecute function. This function then checks if there is a text (.txt) file in the same directory as the specified test script, that has the same name as the test (.t) script, if there is - it deletes this before running the test script. The reason for doing this is that when executing the test script we use the resextract switch for partner, this creates a .txt file as the results of the test script, which is easier for SilkTest Workbench to query. by deleting any .txt files with the same name, we ensure that we only get the latest results.

Once the function has executed the SilkTest script file - it waits for the results file to exist, which is only done once the test script is finished, and then checks the first line of the results file. If the string "Passed" is found in the first line, then the function writes to the console that the SilkTest classic script has passed, if it does not detect the "Passed" string then it advises to check the results file for any errors.

Public Module Main
 Dim _desktop As Desktop = Agent.Desktop


 Public Sub Main()
  ClassicExecute ("C:\test1.t")
 End Sub



 Function ClassicExecute (sSilkFile As String)
  Dim sTempTxt As String = Left(sSilkFile, sSilkFile.Length-2) & ".txt"
    
  ' If specified test exists - run it
  If System.IO.File.Exists(sSilkFile) = True Then
   
   ' If .txt file exists already - delete it
   If System.IO.File.Exists(sTempTxt) = True Then
    System.IO.File.Delete(sTempTxt)
   End If
  
   ' Execute SilkTest script
   Shell("partner -q -resextract -r " & sSilkFile)
   
   ' wait for the txt file to exist
   While System.IO.File.Exists(sTempTxt) = False
    System.Threading.Thread.Sleep(1000)
   End While
   
   ' once file exists - read the first line
   Dim objReader As New System.IO.StreamReader(sTempTxt)
   Dim TextLine = objReader.ReadLine()
   
   If TextLine.EndsWith("Passed") Then
    Console.WriteLine("Classic Script " & sSilkFile & " Passed")
   Else
    Console.WriteLine("Classic Scipt had errors - see " & sTempTxt)
   End If
  Else
   Console.WriteLine("Specified SilkTest classic test not found")
  End If
  
 End Function 
  
End Module