Starting an Application from Within a Script

Typically, when you record a script, a base state is automatically recorded that starts the application that you want to test. However, if your script tests multiple applications or you turn off the Execute base state functionality for any reason, you must start the test application from within your script.

  1. Open the script in which you want to include the code to start the application.
  2. Type Imports System.Diagnostics at the beginning of the script.
  3. To define the application as a new process, type:
     Dim applicationProcess As New Process() 
    where applicationProcess is the name of the application that you want to start. For example, to start Internet Explorer, type:
    Dim ieProcess As New Process()
  4. Define the full path to the application by typing the following code:
    Dim psi As New ProcessStartInfo()
    psi.FileName = "applicationexecutable.exe"
    where applicationexecutable.exe is the name of the executable file that launches your test application. For example to start Internet Explorer, type:
    Dim psi As New ProcessStartInfo()
    psi.FileName = "C:\Program Files\Internet Explorer\iexplore.exe"
    Note: If the executable for the application that you want to test is in the same directory as Silk Test Workbench, you do not need to specify the full path.
  5. To initially go to a certain Web page, set the ProcessStartInfo.Arguments property to the URL. For example, to start Internet Explorer and go to Google.com, add the following line after the Filename line:
    psi.Arguments = "http://www.google.com"
  6. Specify the code to start the process. For example, to start ieProcess that was defined in step 1, type:
    ieProcess.StartInfo = psi
    ieProcess.Start()
  7. Save the script.
The entire script to start Internet Explorer and go to Google.com looks like the following:
Imports System
Imports System.Diagnostics

Public Module Main
	
  Public Sub Main()
    Dim _desktop As Desktop = Agent.Desktop
    Dim ieProcess As New Process()
    Dim psi As New ProcessStartInfo()
    psi.FileName = "C:\Program Files\Internet Explorer\iexplore.exe"
    psi.Arguments = "http://www.google.com"
    ieProcess.StartInfo = psi
    ieProcess.Start()

  End Sub
End Module