Forum Discussion
If you're using JScript or JavaScript, it is case sensitive. Make sure you're checking "Exists" not "exists". If that doesn't fix it, let us know.
As for try/catch... they don't catch object exists errors because they are not script coding errors. What I would do, though, is use browser.Terminate() in your try block to make sure, if it DOES exist, that you actually are closing the instance of chrome found initially in your WaitProcess.
- tristaanogre7 years agoEsteemed Contributor
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.
That code looks a bit neater than ours. I will try it that way as well.
I stopped using waitBrowser because waitBrowser does not recognize iexplore processes running without an actual page interface. Too many times, this code:
browser = waitBrowser(browserName, 1000); if (!browser.Exists) { Log.Message ('Browser does not exist, I am going to start it...'); Browsers.Item(browserName).Run(url) }
lead to log:
Browser exists, I am going to start it
Browser already running!
said 'there is no browser running, I am going to start one...'
and then 'Browser already running' when doing
- tristaanogre7 years agoEsteemed Contributor
Actually, in our case, WaitBrowser finds the IE processes just fine. Give it a shot and see if it works for you.
Something else to consider doing is making sure all browsers are closed at the start of a tst case as well before running the browser... close everything, then run.
Well, if there was a browser, it also went into the browser.exists clause, so exists or Exists apparently doesn't make a difference.
I could change the process.Terminate to browser.Terminate, but that as well shouldn't make a difference I guess? If there are 3 browsers open and he finds one but kills another, he simply loops till they are all gone. (around the code snippet, there is another loop)