How do I pass parameters in a Silk Test Workbench dotNet script?

How do I pass parameters in a Silk Test Workbench dotNet script?

 A Silk Test Workbench expects the Main() call to have no parameters. Any attempt to add parameters will result in the playback error:-

However, Main() is overloaded and can be called from itself. For this example, first you will need to define two input parameters in the Properties tab:

The following script will take the arguments dictionary and will pass it to the overloaded version of Main(args):-

Public Module Main

    Dim _desktop As Desktop = Agent.Desktop

    Public Sub Main()
        
        Dim args = New IDictionary(Of String, Object)
        args("myParam") = "test value"
        args("myParam2") = "another test value"
        Main(args)
    
    End Sub
    
    Public Sub Main(args)
        
        Dim myArg1 As String = Nothing
        Dim myArg2 As String = Nothing
        
        myArg1=args("myParam")
        myArg2=args("myParam2")
        
        console.writeline(myArg1)
        console.writeline(myArg2)
    End Sub

End Module

On the face of it, it doesn't look right in that there are two Main() calls. However, the second one has an overload (args), so Silk Test will ignore it in favour of the first, non-overloaded version. The first Main() then calls the overloaded Main(args) and passes across the key-pair contents of the Dictionary. Whatever you have defined as the contents of the argument string(s) in the first Main() call is what will be passed to the overloaded version. Although we have hard-coded them here, there is nothing to stop you reading data from an ActiveData source or a text file before passing the information to the overloaded Main() call.

DISCLAIMER:

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:
‎2018-06-12 21:30
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.