QTP : Important operations
DATASHEET:
To : Fetch only those cells from localsheet which has been mentioned in Global sheet .ie., fetch
only 3 and 1 cell in the same order from local sheet .
Output: ca
rowcount =
DataTable.GetSheet("Global").GetRowCount
for i=1 to rowcount step 1
DataTable.GetSheet("Global").SetCurrentRow(i)
val=DataTable.Value("A","Global") '
DataTable.GetSheet("Local").SetCurrentRow(val)
msgbox
(DataTable.Value("A","Local")
next
WEBTABLE
r=Browser("Google").Page("title:=.*").WebTable(“name:=
TTable").RowCount
c=Browser("Google").Page("title:=.*").WebTable(“name:=TTable").ColumnCount(r)
strData=
Browser("Google").Page("title:=.*").WebTable(“name:=TTable").GetCellData(1,1)
Set ChldItm =
Browser("Google").Page("title:=.*").WebTable(“name:=TestTable,"index:=0").ChildItem(1,1,"micclass",index)
if(ChldItm
.GetRoproperty("micclass")<>"Page") then
.....
....
end if
EXCEL:
Set xl = createobject("excel.application")
xl.Visible = True
Set Wb= xl.Workbooks.Open("C:\qtp1.xls")
Set ws=Wb.Worksheets("Sheet1")
Row=ws.UsedRange.Rows.Count
data = ws.cells(1,1).value
wb.saveas" "
wb.save
wb.close
xl.quit
DATABASE
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
con.open"Driver={SQL
Server};server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs"
rs.open "select * from emp",con
Do while not rs.eof
VbWindow("Form1").VbEdit("val1").Set
rs.fields("v1")
VbWindow("Form1").VbEdit("val2").Set
rs.fields("v2")
VbWindow("Form1").VbButton("ADD").Click
rs.movenext
Loop
'Release objects'Release objects
Set rs= nothing
Set con= nothing
FILES , FOLDERS
Set
fso=createobject("Scripting.FileSystemObject")
Set ctrl__folder=fso.GetFolder(Sourcefolder)
Set
sub_folder=get_folder.SubFolders
Set sub_files
=get_folder.Files
for each i in sub_folder
sub_folder.name
next
TEXT FILE
Set txt=fso.CreateTextFile("C:\qtptest.txt")
Set ctrl_file=fso.getfile("C:\qtptest.txt")
Set txt_file=ctrl.openastextstream(1)
Do while txt_file.AtEndOfStream <> true
Msgbox
txt_file.ReadLine
Loop
----------------------------------------------------------------------------
·
mid("ABC",1,2) 'answer=AB
·
instr(1,"ABC","B")
'answer=2
·
len("ABC") 'answer=3
·
ubound(a,2) ' a(2)(3) ---answer=3