How to check (and close) processes in a loop?
In my keyword tests, I need to check on some active processing before starting execution.
However, if these processes are active, I need to close them.
I do not know how many instances of these processes are active, if they are active.
I used a While loop to close processes (which works), something (while process exists, close process), however when the last process is closed I get an error in the While loop because the process is not found (which is true), and TC gives me an error.
What is the best approach to tackle this situation?
The following works for me using Excel as an example with Keyword tests. In the If Object dialog box, I just typed in the process (Sys.Process("Excel")) I wanted to check. I used a Go Label to make the process 'loop'.
Hi,
> some active processing
If those processes were started as Tested Applications by TestComplete, then CloseAll method (https://support.smartbear.com/viewarticle/68083/) might help.
Otherwise, the pseudocode is like this:
repeat
search for any instance of the process (i.e. ignoring its index)
if the process is found
call Close method for it
loop until the process exists and timeout was not exceeded
wait a bit ( .Delay(500) )
if timeout expired
call Terminate for the process
end of loop
end of if
until the process is found