Sometime, our tests need to be parameterizedwith multiple sets of data selected from database. For example:
Browser("Browser").Page("Experiments Listing").Link("I-1019”).Click
In this sentence, we’re trying to parameterize the link color inREDin order to locate specific record we want. Obviously, it is no way to parameterize the link directly on itself, because QTP need identify object from object repository when you run the test every time. If the object you’ve parameterized doesn’t exist, error message alert.
Firstly, we need to know the regular discipline of the link. It’s an ascending queue? descending queue? or sorted by date? by alphabet? by updated etc. and make your expression based on this.
Subsequently, we intent to parameterized the link by usingdescribing programand let QTP doesn’t look up object from object repository any more:
Browser("Browser").Page("Experiments Listing").Link("text:=I-1019").Click
Here I made a sample scrīpt for selecting Experiments record on RMTS, FYI.
Notice, 1.make sure the data table “exp0” has existed
2. change the configuration part in colorREDto your own.
'*************login the VPN
Browser("Browser").Dialog("Connect to webdev").WinEdit("User name:").Set "Theravance\jfang"
Browser("Browser").Dialog("Connect to webdev").WinEdit("User name:").Type micTab
Browser("Browser").Dialog("Connect to webdev").WinEdit("Password:").SetSecure "458702cde80f2dd36e8c89416e0012a10be23b658a410073fdafe5c9d530"
Browser("Browser").Dialog("Connect to webdev").WinEdit("Password:").Type micReturn
'*************select data from MySQL database
SetConn= CreateObject("ADODB.Connection" )
str="DRIVER={MySQL ODBC 3.51 Driver};SERVER=webdev;DATABASE=intranet;user id=root; password=xxxx"
Conn.open str
Set Rs = CreateObject ("ADODB.Recordset" )
sql = "select * from `experiment` order by 'experimentID' desc limit 1;"
Rs.open sql,conn,1,3
While Not Rs.eof
For i=0 to 0
'************* write to data table
DataTable("exp"&i,"Global") = Rs(i)
next
Rs.movenext
wend
Rs.close
Set Rs = Nothing
Conn.close
SetConn= Nothing
''************* locate the link by using programmatic descrīptions
Dim i
i=DataTable("exp0","Global")
Browser("Browser").Page("Experiments Listing").Link("text:="&i).Click