Thursday, April 29, 2010

Maximize the Browser without error even though it already maximized

With below code we can maximize IE. if Browser already maximized it does not give any error and smothly execute the code.

Code :-

BrHwnd= Browser("Understanding of Automation").GetROProperty("hwnd")

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

'Maximize the Browser

wHwnd = Extern.GetMainWindow(BrHwnd, GA_ROOT)Window("hwnd:=" & wHwnd).Maximize

In Swf List Box check items check box status and turn On / off

In SWF List box items display with Check boxes. Once we selected those items automaticaly checkbox status change from ON to OFF or OFF to ON. In this case first, we can check status and if that is not exepected status then put required stauts.

Code :-
iChkboxcount=SwfWindow("WName").SwfWindow("EditorName").SwfList("ListBoxName").GetItemsCount
Reporter.ReportEvent micDone,"Captured Items count from list box", " ITems count :- " & iChkboxcount
For intItemNameIndex=0 to iChkboxcount-1
sItemname=SwfWindow("WindowName").SwfWindow("EditorName").SwfList("ListBoxname").GetItem(intItemNameIndex)
msgbox sItemname
Reporter.ReportEvent micDone," Selected ITem name","Item name: - " & sItemname
blnStatus=SwfWindow("WindowName").SwfWindow("EditorName").SwfList("ListBoxname").Object.GetItemCheckState(intItemNameIndex)
Reporter.ReportEvent micDone," Selected Item Checked Status"," Status " & blnStatus
Print sItemname&":"&blnStatus
If sItemname="Ecomm Configurator" and blnStatus=0 Then
REporter.ReportEvent micDone," Turned on REquired Check box"," Turned on required Check box"
SwfWindow("WindowName").SwfWindow("EditorName").SwfList("ListBoxname").Select "Give the required item name"
Exit for
End If
Next

Get data from Web Page View Source Tags

Set objDictionary = CreateObject("Scripting.dictionary")
iFlag=0
Set sAllitems=Browser("CreationTime:=1").Page("title:=.*").Object.all.tags("a")
icount= sAllitems.Length
msgbox icount
For i=0 to icount-1
msgbox sAllitems(i)
If Instr(1, sAllitems(i), "http://www.google.com/ncr")<>0 Then
sitemsList=Split(sAllitems(i), "http://www.google.com/")
msgbox sitemsList(1)
sItemsName=Split(sitemsList(1), "'")
Reporter.ReportEvent micDone,"Captured value"," Captured value:- " & sitemsList(0)
sItem=sItemsName(0)
Reporter.ReportEvent micDone," Find Item :- " & sItem, sItem

If Not objDictionary.Exists(sItem) Then
objDictionary.Add sItem, iFlag
iFlag=iFlag+1
End If

End If
Next
'Code to display the Items list
iKeys = objDictionary.Keys
If objDictionary.Count<>0 Then
For sItem = 0 To objDictionary.Count - 1
If sItem=0 Then
msgbox iKeys(sItem)
Else
Msgbox iKeys(sItem)
End If
print iKeys(sItem)
Reporter.ReportEvent micDone,"Items Count:- " ," count" & sItem &" -- - -" & iKeys(sItem)
Next
Else
print "Nothing Exist"
Reporter.ReportEvent micDone,"Items are not exists"," Items are not exists in Open page"
End If
Set objDictionary = Nothing

Wednesday, April 21, 2010

Delete all files in the Temporary Files In Browser

Delete temp internet files in browser. manually we can do it with below navigation (IE 6).
Tools - - > Internet Options --> General - - > Temporary Internet files section - - click on "Delete Files .." button --> turn on " Delete all offline content" check box --> Click "OK" Button -- > Click "OK" Button

Above steps we can do with Below QTP code

Const TEMP_INET_FILES = &H20&
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.Namespace(TEMP_INET_FILES)
Set oFolderItem = oFolder.Self
FolderPath = oFolderItem.Path & "\*.*"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(FolderPath)