Forum Discussion

guoguo's avatar
guoguo
Contributor
9 years ago

How to set the browser as the top level window

Hi Everyone,

 

Currently, we perform the web tests and other applications on the same server by executing a batch file. We found that the web browser windows are behind the window of the other applications (not belong to the testcomplete test). Because the browser is not active, the tests failed of course.

 

 We want to write code in the test script to enable the brower always be the top level window and active. Does anyone have idea?

 

Regards,

Jie 

5 Replies

  • We are using Python for our scripts, but the SetFocus() method can be used for JScript and VB. 

     

    def Search_Text():
      Sys.Browser("firefox").BrowserWindow(0).SetFocus()
    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      I suspect you may have hit the same problem I raised here:

       

      http://community.smartbear.com/t5/Functional-Web-Testing/Chrome-inconsistent-behaviour-with-TC11-20/m-p/109486#U109486

       

      What version of TC, and what browser are you using?

       

      With the NPAPI plugin for Chrome (pre v45) I didn't have to activate a browser before I used it. Just sending something to one of it's controls would cause it to activate and come to the foreground. Thats no longer the case. When I assign a browser in the background, and then send keys to it, the keys are sent to the browser currently in the foreground. Which is incorrect.

       

      I'm also having to use the BrowserWindow object now to bring the browser I want into focus. Which can be a bit of pain with multiple browser windows open. But it works for now.

       

      I still need to raise a support ticket for this as the behaviour is not the same with the new plugin. Maybe it'll have to stay like this, I don't know. But it was easier with the old version.

      • djadhav's avatar
        djadhav
        Regular Contributor

        Here is an example of how I do it. This applies the always on top setting to the browser window used for testing.

         

         

        Set testWindow = Sys.browser.BrowserWindow(0)
        
        Win32API.SetWindowPos(testWindow.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

         

         

  • SmartBearDan's avatar
    SmartBearDan
    SmartBear Alumni (Retired)

    Hello guoguo,

     

    I would add a step at the beginning of your test or test set to minimize all the applications active in Windows before running your browser.  That way you know the browser has focus.  This can be done by recording the Windows + D shortcut.

     

    WIND.png

     

    -Dan