Saturday, June 30, 2012

How to verify a Browser Window is minimized

The bad part is  QTP does not support retrieving RO Properties of a browser. If it has supported, then we would have use a method like Browser("Browser Name").GetROProperty("minimized")




















But we can use Extern to use some of the methods from Windows user32.dll
Following are the two ways to verify the window minimized.
Extern.Declare micHwnd, "FindWindow", "user32.dll","FindWindowA", micString,micString 'this method returns a handle
Extern.Declare micLong,"GetWindowMinimizeState", "user32.dll" ,"IsZoomed",micLong 'IsZoomed meaning IsMaximized
hwnd=extern.FindWindow(NULL,"Links - Windows Internet Explorer")
print Extern.GetWindowMinimizeState(hwnd) 'Similar way


Const GA_ROOT = 2
'Declare Function GetAncestor Lib "user32.dll" (ByVal hwnd As Long, ByVal gaFlags As Long) As Long Extern.Declare micLong, "GetMainWindow", "user32" ,"GetAncestor",micLong, micLong
hwnd = browser("name:=Links.*").GetROProperty("hwnd") 'this returns the handle of the Browser Tab hwnd = Extern.GetMainWindow(hwnd , GA_ROOT) 'This returns the handle of the browser(which means handle of the browser)
msgbox Window("hwnd:=" & hwnd ).GetROProperty("minimized")

How to find and fill a color in Excel Cell

Set xlObj=getobject("","Excel.Application")
Set xlWBObj=xlObj.workbooks.open("c:\delete.xls")
set xlWSObj=xlWBObj.worksheets(1)
xlWSObj.cells(1,1).Font.Color=vbRed  'This statement changes the color of the Text in the specified cell
xlWSObj.cells(2,1).Interior.ColorIndex=4 'This method changes the color of the background of the cell
print  xlWSObj.cells(1,1).Font.Color
print xlWSObj.cells(2,1).Interior.ColorIndex
xlWBObj.save
xlWBObj.close
xlObj.application.quit
Set xlObj=nothing