Forum Discussion

Lagencie's avatar
Lagencie
Frequent Contributor
7 years ago

If Browser throws Exception

I am using the function If Browser to check which browser is running.

 

Problem is that during development phase it always throws the exception that no browser is running - because i dont start the browser, but its already open.

Is there a way to set the browser variable just as a dummy, because from what i understand testcomplete searches for the object anyways and not on the set variable during testrun.

 

when i make Run Browser before the If Browser works - if i just have an open browser it doesnt

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The if-browser operation depends upon TestComplete being in control of the browser execution.  Run Browser or Navigate actually sets the Browsers.CurrentBrowser property to indicate what is the current browser being used by the current keyword test.  So, if either of those operations isn't run, TestComplete doesn't know which of the potentially many browsers that could be open in your Windows environment to check.  You should, at least, use the Navigate method before an "If Browser" call during your development process to signal what browser to use.

    • Lagencie's avatar
      Lagencie
      Frequent Contributor

      well, thanks for the answer, but its still a strange behaviour, especially because testcomplete isnt using the browser it opens himself anyways - but searches over all open browsers during execution

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        If Browser checks that property... well documented... so, if that property is not set, then If Browser won't work.  The only way to set that property is via either the Run Browser or Navigate operations.

         

        While you are correct in TestComplete will operate against any browser open when opened manually, that operation has a very specific use in the feature set for testing across multiple browser types.  It's purpose is so that, if you are running a test case in a browser loop or parameterized web test case, you can control different behaviors if the browser currently in use is a particular browser.

         

        So, for your purposes, in order to develop against that, at least for the short term, add either Run Browser or Navigate before your If Browser call.