How do I stop SilkTest DefaultBaseState invoking two instances of the AUT?
If you are encountering an issue using the DefaultBaseState where SilkTest is invoking two instances of the application under test (AUT) during test run, use Shell commands to invoke the application following the sample below:
dll "shell32"testcase OPEN_APP() appstate none
int ShellExecuteW (int iHandle, String lpOperation, String lpFile, String lpParameters, String lpDirectory, int nShowCmd)
// Sets iHandle = to the window handle for the desktop
iHandle = Desktop.GetHandle()
// The operation that is to be carried out
lpOperation = "open"
// The file on which this operation will be carried out
lpFile = "filename.exe"
// Any additional parameters to the commandline
lpParameters = " "
// The working directory in which this will be run
lpDirectory = "C:\directory_path_to_application"
// a flag that determines how the command will be shown
iShowCmd = 5
// Open application
Once you have ensured that the shell script successfully invokes a single instance of your application, create an appstate in your frame file and place the above script in the appstate (remove any previously recorded actions if you recorded an appstate to generate the appstate declaration).
Now you should be able to create a testcase based on this appstate to invoke your application.
If you find that during test execution, that SilkTest continues to invoke a second instance of the application, this is because SilkTest is again calling the DefaultBaseState from the DefaultTestcaseExit function.
DefaultTestCaseExit (BOOLEAN bException)
DefaultTestcaseExit (BOOLEAN bException) – logs an exception to the results file when a testcase exits because of an exception. The function then executes the SetBaseState function, which calls a base state function that you have defined or the DefaultBaseState function.
To work around this, you would have to override DefaultTestcaseExit function in the default.inc file by creating a TestcaseExit () function in your frame file as below:
TestCaseExit (BOOLEAN bException)
Key here is that we have removed the SetBaseState() call, therefore, DefaultTestcaseExit() is not called, but the value of bException is used to determine if an error occurred during the testcase execution.