Friday 19 November 2010

QTP - DataBase Testing (Demo1)

Leave a Comment

QT_Flight32 is the DSN created for QTP – Flight Application.
Aim:
To connect to the DSN= QT_Flight32
Establish the connection using ADODB
Check the DSN= QT_Flight32 connection
Execute the query = Select * from Orders
Get the number of columns and column names
Get the number of rows
Add a separate column for each column name in QTP-Flight DB
Write rows data in the corresponding columns of the excel sheet

' Sample DataBase Test Script

dim conn,rs
Set conn=createobject("ADODB.Connection")
Set rs=createobject("ADODB.recordset")
strconnection="dsn=QT_Flight32"
conn.open strconnection

If conn.state=1 Then
            Reporter.ReportEvent micpass, "DB Connection sucesful" , "Passed"
            else
            Reporter.ReportEvent micpass, "DB Connection is not sucesful" , "Failed"
End If

Set rs=conn.execute("Select * from Orders")
' To Parameterize the script
'Set rs=conn.execute(DataTable("SQL",dtGlobalSheet))

Set flds=rs.fields
DataTable.SetCurrentRow (0)
 For k= 0 to  flds.count-1
  rs= flds(k).name
  print rs
      datatable.GetSheet("Action1").Addparameter  rs,""
 Next

' Adding query values into excel
set  rs = conn.Execute("  Select * from Orders")
'Set rs=conn.execute(DataTable("SQL",dtGlobalSheet))
   rs.movefirst
 i=1
   While not  rs.eof
  DataTable.SetCurrentRow (i)
  For j=0 to flds.count-1
   DataTable( flds(j).name,"Action1")= rs.Fields( flds(j).name)
  next
  i=i+1
   rs.movenext
 Wend

Results:






0 comments:

Post a Comment

Friday 19 November 2010

QTP - DataBase Testing (Demo1)


QT_Flight32 is the DSN created for QTP – Flight Application.
Aim:
To connect to the DSN= QT_Flight32
Establish the connection using ADODB
Check the DSN= QT_Flight32 connection
Execute the query = Select * from Orders
Get the number of columns and column names
Get the number of rows
Add a separate column for each column name in QTP-Flight DB
Write rows data in the corresponding columns of the excel sheet

' Sample DataBase Test Script

dim conn,rs
Set conn=createobject("ADODB.Connection")
Set rs=createobject("ADODB.recordset")
strconnection="dsn=QT_Flight32"
conn.open strconnection

If conn.state=1 Then
            Reporter.ReportEvent micpass, "DB Connection sucesful" , "Passed"
            else
            Reporter.ReportEvent micpass, "DB Connection is not sucesful" , "Failed"
End If

Set rs=conn.execute("Select * from Orders")
' To Parameterize the script
'Set rs=conn.execute(DataTable("SQL",dtGlobalSheet))

Set flds=rs.fields
DataTable.SetCurrentRow (0)
 For k= 0 to  flds.count-1
  rs= flds(k).name
  print rs
      datatable.GetSheet("Action1").Addparameter  rs,""
 Next

' Adding query values into excel
set  rs = conn.Execute("  Select * from Orders")
'Set rs=conn.execute(DataTable("SQL",dtGlobalSheet))
   rs.movefirst
 i=1
   While not  rs.eof
  DataTable.SetCurrentRow (i)
  For j=0 to flds.count-1
   DataTable( flds(j).name,"Action1")= rs.Fields( flds(j).name)
  next
  i=i+1
   rs.movenext
 Wend

Results:






No comments:

Post a Comment