Modifying the Base State in a Script

You can edit the base state in a script to specify how Silk4NET starts an application under test (AUT) during replay. You can specify the executable location of the AUT, the working directory, the URL and the connection string for a web application, and so on. For example, if you want to execute tests on a production web site, which have already been executed on a staging web site, you can simply change the URL in the base state and the tests are executed against the new web site.

Note: To specify how Silk4NET starts an application under test (AUT) during recording and replay, edit the base state from the user interface. For additional information, see Modifying the Base State from the User Interface.

To edit the base state in a script:

  1. Open the script.
  2. Change the baseState method. You can add your code between creating the base state and executing it:
    ' VB code
    ' Go to web page 'demo.borland.com/InsuranceWebExtJS'
    BrowserBaseState baseState = new BrowserBaseState()
    ' <-- Insert your changes here!
    baseState.Execute()
    // C# code
    //Go to web page 'demo.borland.com/InsuranceWebExtJS'
    BrowserBaseState baseState = new BrowserBaseState();
    // <-- Insert your changes here!
    baseState.Execute();
  3. Use the following code to specify the executable name and file path of the application that you want to test:
    ' VB code
    baseState.Executable=executable
    // C# code
    baseState.Executable=executable;
    For example, to specify the Calculator, type the following:
    ' VB code
    baseState.Executable = "C:\\Windows\\SysWOW64\\calc.exe"
    // C# code
    baseState.Executable = "C:\\Windows\\SysWOW64\\calc.exe";
    To specify Mozilla Firefox, type the following:
    ' VB code
    baseState.Executable = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"
    // C# code
    baseState.Executable = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
  4. Use the following code to specify command line arguments:
    ' VB code
    baseState.CommandLineArguments = commandLineArguments
    // C# code
    baseState.CommandLineArguments = commandLineArguments;
    For example, to start Mozilla Firefox with the profile myProfile, type the following:
    ' VB code
    baseState.CommandLineArguments = "-p myProfile"
    // C# code
    baseState.CommandLineArguments = "-p myProfile";
  5. You can use the following code to specify a different working directory:
    ' VB code
    baseState.WorkingDirectory = workingDirectory
    // C# code
    baseState.WorkingDirectory = workingDirectory;
  6. If you want to use an executable pattern, use the following code:
    ' VB code
    baseState.ExecutablePattern = executablePattern
    // C# code
    baseState.ExecutablePattern = executablePattern;
    For example, if you want to specify an executable pattern for the Calculator, type:
    ' VB code
    baseState.ExecutablePattern = "*\\calc.exe"
    // C# code
    baseState.ExecutablePattern = "*\\calc.exe";
  7. If you want to use a command line pattern in combination with the executable file, use the following code:
    ' VB code
    baseState.CommandLinePattern = commandLinePattern
    // C# code
    baseState.CommandLinePattern = commandLinePattern;
    For example, if the command line of the application ends with com.example.MyMainClass you might want to use *com.example.MyMainClass as the command line pattern:
    ' VB code
    baseState.CommandLinePattern = "*com.example.MyMainClass"
    // C# code
    baseState.CommandLinePattern = "*com.example.MyMainClass";
  8. If you are testing a web application or a mobile web application, and you have not set an application configuration for the current project, specify one of the installed browsers or mobile browsers. For example, to specify Google Chrome, type the following:
    ' VB code
    baseState.BrowserType = BrowserType.GoogleChrome
    // C# code
    baseState.BrowserType = BrowserType.GoogleChrome;
  9. If you are testing a web application or a mobile web application, and you have not set an application configuration for the current project, specify the address of the web application that you want to test:
    ' VB code
    baseState.Url = url
    // C# code
    baseState.Url = url;
    For example, type the following:
    ' VB code
    baseState.Url = "demo.borland.com/InsuranceWebExtJS/"
    // C# code
    baseState.Url = "demo.borland.com/InsuranceWebExtJS/";
  10. If you want to test a web application on a desktop browser, you can specify the height and width of the browser window:
    ' VB code
    baseState.ViewportHeight = viewportHeight
    baseState.ViewportWidth = viewportWidth
    // C# code
    baseState.ViewportHeight = viewportHeight;
    baseState.ViewportWidth = viewportWidth;
  11. If you want to test a web application or a mobile native application on a remote location, specify the connection string:
    ' VB code
    New MobileBaseState(connectionString)
    // C# code
    new MobileBaseState(connectionString);
    For information on the connection string, see Connection String for a Remote Desktop Browser or Connection String for a Mobile Device.
  12. To edit the capabilities for Mozilla Firefox or Google Chrome , you can also use the connection string. For example, to set the download folder for Mozilla Firefox, type the following:
    ' VB code
    baseState.ConnectionString = "moz:firefoxOptions= {\"prefs\": { \"browser.download.dir\":\"C:/Download/\"}};"
    // C# code
    baseState.ConnectionString = "moz:firefoxOptions= {\"prefs\": { \"browser.download.dir\":\"C:/Download/\"}};";
    For additional information, see Setting Options and Capabilities for Web-Driver Based Browsers.