Monday 27 January 2014

UFT- How to connect to SQL without DSN?

Set oDbCon=createobject("ADODB.connection")

oDbCon.open="Provider=SQLOLEDB;Data Source=computerName; Trusted_Connection=Yes;Initial Catalog=database_name;User ID=username;Password=password;"

set oData=oDbCon.execute("select * from table_name")

oFields=oData.fields.count

For oFld=0 to oFields-1

 fldName=oData.fields(oFld).name
   
 oval=""
   
  While not oData.eof
   oval=oval&oData(fldName)&vbnewline
   oData.movenext
  Wend
   
 msgbox oval,vbokonly,fldName
 oData.movefirst
   
Next
  

Tuesday 7 January 2014

UFT/QTP- Difference between ChildObjects, ChildItem and Getcelldata in QTP





childitem method syntax in qtp, childobjects and child items in qtp, childobjects syntax in qtp, getcelldata method in qtp, getcelldata qtp example


ChildObjects method is to access total child objects from an object using description object. In other words, it returns the collection of child objects contained within the object.

Syntax:- object.ChildObjects ([Description])

eg: for the count of No of links present in a page we can use Child objects method

set odesc = Description.Create()
odesc("Class Name").Value = "oLinks"
set oLinks=Browser("title:=.*").Page("title:=.*").ChildObjects("odesc")
msgbox oLinks.count
  
ChildItem method is to access child objects from a web table cell in web table object without using description object. In other words, it returns a test object from the cell by type and index.

Syntax:-object.ChildItem (Row, Column, MicClass, Index)

EG:

set a = Browser("A").Page("B").WebTable("C").WebTable("Item").ChildItem(2,2,"WebElement",0)
b = a.GetROProperty("value")
MsgBox b

Getcelldata method is to retrieve data from a web table cell in web table object.

Syntax:-object.GetCellData (Row, Column)

EG:

Dim i,j
For i=1 to Row count
  For j=1 to column count

     msgbox browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").WebTable("Yahoo! ID:").GetCellData (i,j)

  Next
Next

UFT/QTP- Read Excel using ADODB connection

qtp adodb connection excel, qtp excel database, Read Excel using ADODB connection




Const adOpenStatic=3
Const adLockOptimistic=3
Const adCmdText= &H001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

Sqlquery="Select  UserName,Password  FROM [SheetName$] where UserName='Vadivel.sekar'"

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source="&"Excel Path" & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"

objRecordset.Open Sqlquery, objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF         

msgbox objRecordset.Fields.Item("UserName")
msgbox objRecordset.Fields.Item("Password")
objRecordset.MoveNext                                                
                                               

Loop

Note: e.g. Excel Path=D:\Login Info\Sample.xls