cancel
Showing results for 
Search instead for 
Did you mean: 

Why do I get "The Browser is already running." ?

dbaechtel
Contributor

Why do I get "The Browser is already running." ?

I have made a series of Keyword Tests. Each test Closes the Browser at the end of the test. Each Keyword Test runs without error individually.

I have added the Keyword Tests to my Test Project and when I try and run the Test Project, on the start of the 2nd test I get the error "The Browser is already running." and "Cannot obtain the window with the window class 'IEFrame', window caption '*' and index 0." and the test stops.

I have verified that indeed the Browser was closed at the end of the 1st test and before the 2nd test is started. Also no other browsers are running.

Why am I getting this error and how do I get around it so that all tests will run in succession?
11 REPLIES 11
murugans1011
Regular Contributor

RE: Why do I get "The Browser is already running." ?

Verify with the task manager tat the process doesnt exist. try adding code at beginning of 2nd test



 if sys.Waitbrowser().Exists then

        {

  Set browser=Aliases.browser

  browser.close()

      }



to close browser from keyword test try this
ArtemS
Staff

RE: Why do I get "The Browser is already running." ?

Hello,

When a test closes a browser it takes some time to gracefully finish its process.

When TC starts the second test right after the first test, the process of a "previous browser" may still exist as it didn't have enough time to finish.

To run all tests in succession, you may


  • add some delay at the end of each test, after the instructions that close the browser


  • check for any running browsers and close them in the beginning of each test, as per Murugan S and as described in Checking if Browser Is Running


The second variant is preferable, as it can close all running browsers, rather than just one we used in a test.
Artem
SmartBear Technical Writer
-----
I’m not a member of the SmartBear Support Team, I’m just helping users in this community. Any views or opinions expressed do not necessarily represent those of SmartBear Software.
jose_pita
Super Contributor

RE: Why do I get "The Browser is already running." ?

Dude, just use a batch file to kill all the browser processes between tests, problem solved...
lnd_amaral
Contributor

RE: Why do I get "The Browser is already running." ?


while(Sys["WaitProcess"](Project.Variables.application).Exists){


    Sys["Process"](Project.Variables.application).Terminate();


  }

dbaechtel
Contributor

RE: Why do I get "The Browser is already running." ?

Murugan's proposal did not work. 😞

Still getting same errors.

See attached Test Log.



I added it to the top of a script that is called at the beginning of each test.

Still fails on 2nd test.



Browser is not running.

Why does TestComplete says that it is?



dbaechtel
Contributor

RE: Why do I get "The Browser is already running." ?

What is the vbScript equivalent of th followin?


while(Sys["WaitProcess"](Project.Variables.application).Exists){


    Sys["Process"](Project.Variables.application).Terminate();


  }

murugans1011
Regular Contributor

RE: Why do I get "The Browser is already running." ?

did u tried the method available in the link?



http://support.smartbear.com/viewarticle/59603/#Scripts



Sub Check

  While Sys.WaitBrowser().Exists

    Call Sys.WaitBrowser().Close()

  Wend

End sub



Also try to make some delay between the tests.
dbaechtel
Contributor

RE: Why do I get "The Browser is already running." ?

The problem that I see in my tests with the code below is that the Browser.Close has already been executed, but TC still thinks that the Browser is still running for some reason.



With the code below, sometimes the Sys.WaitBrowser() still Exists, but before the Sys.WaitBrowser.Close can be executed, the Browser object being close no longer exists, and I get an error message to that effect. This is an error prone way to handle this.



There needs to be some error free way of running a series of tests in succession that Launch an IE browser at the beginning, and Close the Browser at the end of the tests.



The Browser.Close statement should not return until the Browser is Closed.

The Call Browsers.Item(btIExplorer, "", Browsers.pX64).Run statement should launch a new Browser or use the existing Browser without requiring that ALL Browsers on the system be Closed and Garbage collected Before it is executed.



The workarounds for this issue are just exposing additional levels of errors.



How can I design my tests so that they will run in quick secession without any errors? Each test starts by launching a Browser, and each test ends by Closing the Browser.



How can I make sure that launching the Browser will execute without error?

How can I make sure that the Browser.Close has completed?





Code that does not always work without error:



Sub Check

  While Sys.WaitBrowser().Exists

    Call Sys.WaitBrowser().Close()

  Wend

End sub

jose_pita
Super Contributor

RE: Why do I get "The Browser is already running." ?

Don,



Nowadays browsers have multiple processes, TC can't handle that.

The only way you can do what you want is by running a bat in the beggining of each test that kills all the processes and launches the browser again.



set up a bat with this code (change the name of the browser to the browser you work with):




taskkill /f /im "iexplore.exe"


start iexplore.exe





Add this bat to your TestedApps on TC, on Events->GeneralEvents go to the "Test Engine Events" and on the "OnStartTest" event add the code to run that TestedApp you just added.



I can't put it much better than this.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors