Can SilkTest click on a window it cannot recognise? (Low level approach solution)

Can SilkTest click on a window it cannot recognise? (Low level approach solution)

SilkTest can have difficulty recognising customised applications (Customised Components). If there is a window that SilkTest cannot recognise and you require to click a button on it to continue your test, this technique could solve your problem.

Using the user32.dll we can obtain the window identifier for the foreground window. We can then move the window to a designated position on the screen and click the button using relative coordinates to the main window.

The script below has been written for the test application (All Programs | SilkTest | Sample Applications | TestApp.exe)

The first part of the script selects the menu item Menu | The Item

And clicks the OK button using window identifiers and tags recorded by SilkTest

The second part of the script selects the menu item Menu | The Item as before, but moves the message box to the screen position 0,0 and clicks the mouse at a position relative to the main window. This is achieved by finding the windows identifier for the foreground window(GetForegroundWindow()), moving this window to the screen position 0,0 (MoveWindow( )) and using the main window to click a position on the screen relative to it (TestApplication1.click(1,100,60)).

[-] dll "user32.dll"
    [ ] LONG GetForegroundWindow()
    [ ] Long MoveWindow(Long hWnd,long X,long Y,long nWidth,long nHeight,long bRepaint)
    [ ] 
[ ] 
[-] testcase test1()
    [ ] LONG lWinID,lresult
    [ ] 
    [ ] TestApplication.SetActive ()
    [ ] TestApplication.Maximize ()
    [ ] TestApplication.Menu.TheItem.Pick ()
         [ ] //set the dialog box active
    [ ] TestApplication1.SetActive ()
    [ ] //click the object using the object name
    [ ] TestApplication1.OK.Click ()
    [ ] 
    [ ] Sleep(3)
    [ ] 
    [ ] TestApplication.SetActive ()
    [ ] TestApplication.Menu.TheItem.Pick ()
    [ ] 
    [ ] //find the window identifier for the foreground window
    [ ] lWinID=GetForegroundWindow()
    [ ] Sleep(2)
    [ ] //Move the window to the top of the screen coordinate 0,0
    [ ] lresult= MoveWindow(lWinID,0,0,250,120,1)
    [ ] Sleep(3)
    [ ] //using the main window, click relative to it
    [ ] TestApplication1.SetActive ()
    [ ] //TestApplication1.click()
    [ ] TestApplication1.click(1,100,60)
    [ ] Sleep(3)

 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:17
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.