Monday 8 August 2011

How to get the vaues from combobox in QTP?

'Get the count of items from windows combo box
n=Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount()
For i=0 to n-1
datatable.SetCurrentRow (i)
'Get the items from the windows combobox
val =Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i)
datatable("Flight",dtLocalsheet)=val
Next
datatable.ExportSheet "d:\sam.xls","Action1"

How to use Dynamic Descriptive program in QTP?

 We can create objects by passing the property values dynamically to the function and create the objects so that the function can separate from the objects and used on any application

Set myDialog = Description.Create()
myDialog("Text").value = "Login"
mydialog("Enabled").value = "True"

Set Agent = Description.Create()
Agent("Attached text").value="Agent Name:"

Set password = Description.Create()
password("Attached text").value="Password:"

Set btnOK = Description.Create()
btnOK("Text").value = "OK"

call fnDialogLogin(myDialog,Agent,password,btnOk,"Test","mercury")

msgbox "Execution completed"


Function fnDialogLogin(objDialog,objUserid,objPassword,objLogin,strUserid,strPassword)
    Dialog(objDialog).winEdit(objUserid).Set strUserid '"test"
    Dialog(objDialog).winEdit(objPassword).Setsecure strPassword' "4e3bb8c872c2f2b9b5bdf31a221035f1747d7aac"
    Dialog(objDialog).winButton(objLogin).Click
End Function

How to delete cookies in QTP?

Function fnRemoveCookies
uName=Environment.Value("UserName")
Dim oShell
Set oShell=CreateObject("WScript.shell")
oShell.run("cmd /C cd C:\Documents and Settings\" & uName & "\cookies & del *.txt")
Set oshell=nothing
End Function

how to create excel file and add sheets to it in QTP?

Set suitExcelobj= CreateObject("Excel.Application")
Set myFSO = CreateObject("Scripting.filesystemobject")
If myFSO.FileExists("C:\Testdata.xls") Then
    msgbox "file found"
    Set suitExcelWorkbook=suitExcelobj.Workbooks.Open("C:\Testdata.xls")
Else
    msgbox "file not found"
    Set suitExcelWorkbook=suitExcelobj.Workbooks.Add()
    suitExcelWorkbook.saveas("C:\Testdata.xls")
End If
   
    Set suitExcelWorkSheet=suitExcelWorkbook.Worksheets(1)
    suitExcelWorkSheet.name="Scenario1"

suitExcelWorkbook.close()
set suitExcelWorkbook=nothing
Set suitExcelobj=nothing