Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Collecting files that will be picked up by SCTM after a Silk Test Workbench execution

Collecting files that will be picked up by SCTM after a Silk Test Workbench execution

When a test is run from Silk Central Test Manager (SCTM), SCTM creates an environment variable '#SCTM_TEST_RESULTS_DIR' which stores the value of the results directory where the run results are to be stored for upload to SCTM.  SilkTest Workbench supports the VB.NET environment variable method GetEnvironmentVariable which we can used to retrieve the value of the environment variable at run-time.

Below is a function 'MoveToSCTMResultDir' that will move a specified file to the SCTM results directory at run-time.  The function takes the full path to the file and a second parameter to determine whether to keep the original file (i.e. Copy or Move).  When you run the script from SCTM, the specified file will now be part of the list of files in the SCTM run results Files tab.

Imports System.IO

Public Module Main
    Public Sub Main()
        'Set the paths to the file that will be copied/moved to the SCTM result directory
        Dim path As String = "path-to-file"
        'Call the MoveToSCTMResultDir function to move the files from current to destination directory.
        MoveToSCTMResultDir(path, False)
    End Sub
    'Function to move files to the SCTM result director.
    'Note, third parameter KeepOriginal is optional, by default the value is True to perform a copy action.
    'If you specify False for the KeepOriginal parameter, the file is moved to destination folder
    'and Not kept In the original location
    Public Function MoveToSCTMResultDir(ByVal FullPathCurrent As String, Optional ByVal KeepOriginal As Boolean = True) As Boolean
        'Function success condition
        Dim bSuccess = False
        'Get the SCTM result directory path at runtime from the #SCTM_TEST_RESULTS_DIR environment variable name
        Dim sEnvPath As String = Environment.GetEnvironmentVariable("#SCTM_TEST_RESULTS_DIR")
        Dim FullPathDestination = sEnvPath & "\" & Path.GetFileName(FullPathCurrent)
            If File.Exists(FullPathCurrent) = False Then
                'This statement ensures that the file is created,
                'but the handle is not kept.
                Dim fs As FileStream = File.OpenRead(FullPathCurrent)
            End If
            'Ensure that the same file does not exists in the destination.
            If File.Exists(FullPathDestination) Then
            End If
            'Move or copy the file.
            If KeepOriginal.Equals(False) Then
                File.Move(FullPathCurrent, FullPathDestination)
                bSuccess = True
                File.Copy(FullPathCurrent, FullPathDestination)
                bSuccess = True
            End If
        Catch ex As Exception
            Console.WriteLine("The process failed: {0}", ex.ToString())
        End Try
        Return bSuccess
    End Function
End Module


Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-07-08 10:42
Updated by:
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.