Browser exists, yet it does not. How is that possible?
To properly kill any process before starting my tests, I've added this bit of code (part of a bigger loop):
browser = Sys.WaitProcess(eachBrowser, 1000); if (browser.exists) { logMessage.debug(' - Browser exists. Trying to terminate...'); try { Sys.Process(eachBrowser).Terminate(); } catch (err) { logMessage.debug('Error on terminating [' + eachBrowser + ']: ' + err.message); }
}
This results in this log:
How can this happen? It does not exist, so it should not move into the if clause. Furthermore, it generates an error, but it's in a try/catch. I thought try/catch mechanisms are specifically made to prevent errors from being written to the log because you intercept them in the catch?
I find it hard to believe that the process stopped to exist right in the same millisecond the code went into the exist clause.
Are there easier/more trustworthy methods to kill your browser? The Browser.Close is just too shaky since it does not properly close pages if a browser process runs in the background for some reason (internet explorer has a way of running itself in the background without the browser actually being opened).
We do all our testing in IE so our code is IE centric... however, this is what we're doing:
function closeIEInstance() { var counter = 0; var browser; browser = Sys.WaitBrowser('iexplore', 1000); while((browser.Exists) && (counter < 60)){ counter++; browser.Terminate(); browser = Sys.WaitBrowser('iexplore', 1000); }
Note that, instead of process, we're using "WaitBrowser". See if this works better for you.