NOTICE: Our Community is moving. Get more information. Updated information on a New Login Process
The reason that we have to use parameters in this situation is because when a Visual Test calls a VB.NET script, if we try to use the System.Reflection namespace to call GetCallingAssembly, this returns our script engine, MicroFocus.SilkTest.Scripting, this is correct in the sense that the script engine handles the script call and any parameters used. However, to get the Visual Test name to the VB.NET script, we have to use the reserved variable for the Visual Test name which we can pass to the VB.NEt script as a parameter.Firstly, we need to determine how to get the Visual Test name. In a VB.NET script, we can get the executing assembly by using the System.Reflection namespace's GetExecutingAssembly.GetName().Name (also Me.Name) property as detailed in the following article:-
In a Visual Test, we can also get the Visual Test name from the Reserved Variable 'st_VisualTest' which returns the name of the executing Visual Test.Below are the steps required to setup a VB.NET script that displays in a messagebox the calling Visual Test and also allows the Visual Test to display in a messagebox the VB.NET script that was called:1) Create a blank VB.NET script file2) Create an input parameter called 'CallingVisualTestName'3) Create an output parameter called 'ExecutedDotNETScriptName'4) Copy the script below into the VB.NET script fileImports System.ReflectionPublic Module Main Dim _desktop As Desktop = Agent.Desktop Public Sub Main(args As IDictionary(Of String, Object)) Dim CallingVisualTestName As String = args("CallingVisualTestName") 'display in a messagebox the calling Visual Test MsgBox ("Calling Visual Test Name = " + CallingVisualTestName, MsgBoxStyle.OkOnly, "Calling Visual Test") args("ExecutedDotNETScriptName") = "Executed .NET Script Name = " + Assembly.GetExecutingAssembly.GetName().Name End SubEnd Module5) Save the VB.NET script file6) Create a simple Visual Test7) Create a local variable at the <> step of the Visual Test, name it 'ExecutedDotNETScriptName'8) Insert a step to call the VB.NET script file created above. The playback settings for the VB.NET script file should require an input and an output variable9) Right-click the step created to playback the VB.NET script file and select properties10) In the properties dialog of the step, you should be able to identify the input and output parameters created in the VB.NET script which are now being referenced in the Visual Test.11) Click the select button for the input parameter 'CallingVisualTestName' and select Expression12) In the Expression Designer dialog, select 'st_VisualTest' from the Select a variable (local or reserved) dropdown menu and click the < Add <>button. This will ensure that the Visual Test name is passed to the VB.NET script13) Again in the properties dialog of the step to playback the VB.NET script, locate the Output parameter, which should be named 'ExecutedDotNETScriptName'14) Click the dropdown of the Output parameter and select the local variable created in step 7) called 'ExecutedDotNETScriptName'. The contents of the executed VB.NET script will be passed to this variable at runtime15) Create a step in the Visual Test to insert a messagebox to display the contents of the Visual Test local variable 'ExecutedDotNETScriptName'16) Save the Visual Test
Now when the Visual Test is executed, you will receive a messagebox when the Visual Test calls the VB.NET script indicating the calling Visual Test and vice versa when the VB.NET script returns its name to the Visual Test to be displayed in the messagebox created in the Visual Test.
Note: Feel free to edit the script steps as you prefer should you wish to remove the messagebox prompts as this was used just for testing purposes.