Ask a Question

How to set the browser as the top level window

guoguo
Contributor

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 5
SmartBearDan
Staff

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

vondie
Contributor

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

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

 

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

 

 

I raised a support ticket about it not bringing browser objects to the front.

 

SmartBear were able to reproduce the problem and a fix should be included in the next release. (Which may already be available, just back at work so not checked yet ...)

cancel
Showing results for 
Search instead for 
Did you mean: