Ask a Question

Browser exists, yet it does not. How is that possible?

SOLVED
marinb
Contributor

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:

TClog.jpg

 

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).

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: Browser exists, yet it does not. How is that possible?

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

6 REPLIES 6
tristaanogre
Community Hero

Re: Browser exists, yet it does not. How is that possible?

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
marinb
Contributor

Re: Browser exists, yet it does not. How is that possible?

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)

 

tristaanogre
Community Hero

Re: Browser exists, yet it does not. How is that possible?

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

marinb
Contributor

Re: Browser exists, yet it does not. How is that possible?

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

tristaanogre
Community Hero

Re: Browser exists, yet it does not. How is that possible?

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.

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
marinb
Contributor

Re: Browser exists, yet it does not. How is that possible?

Yeah, the startBrowser(x) function first closes all browsers of type x, unless you specify you do not want to. Nothing more annoying than connecting to a test agent and finding 34 browsers opened.

 

cancel
Showing results for 
Search instead for 
Did you mean: