QTP Scripts 4

‘Display the particular data in database
Option explicit
Dim cono, rso, noc, i, cn
Set cono=createobject("ADODB.Connection")
cono.Open("DSN=QT_Flight32")
Set rso=createobject("ADODB.Recordset")
rso.Open "select * from orders",cono
noc=rso.Fields.Count
For i=0 to noc-1 step 1
            cn=rso.Fields(i).Name
            print cn
Next
rso.Close
cono.Close
Set rso=nothing
Set cono=nothing

‘Import the data from database to excel
Option explicit
Dim exo, wbo, wso, cono, rso, noc, i, j
'create excel file
Set exo=createobject("Excel.Application")
exo.Visible=true
Set wbo=exo.Workbooks.Add
Set wso=wbo.Worksheets("Sheet1")
'Connect to DB and get data
Set cono=createobject("adodb.connection")
cono.Open("DSN=qt_flight32")
Set rso=createobject("adodb.recordset")
rso.Open "select * from orders",cono
noc=rso.Fields.Count
'create columns in excel
For i=0 to noc-1 step 1
            wso.cells(1, i+1)=rso.Fields(i).Name
Next
'Rows storing
j=2
While rso.EOF<>true
            For i=0 to noc-1 step 1
                        wso.cells(j, i+1)=rso.Fields(i).Value
            Next
            rso.MoveNext
            j=j+1
Wend
wbo.SaveAs("C:\mydb.xls")
rso.Close
cono.Close
exo.Quit
Set rso=nothing
Set cono=nothing
Set wso=nothing
Set wbo=nothing
Set exo=nothing

‘Import the data from database to dateable
Option explicit
Dim cono, rso, noc, i, j, x
'Connect to DB and get data
Set cono=createobject("adodb.connection")
cono.Open("DSN=qt_flight32")
Set rso=createobject("adodb.recordset")
rso.Open "select * from orders",cono
noc=rso.Fields.Count
'create columns in Datatable
For i=0 to noc-1 step 1
            x=rso.Fields(i).Name
            datatable.GetSheet(1).AddParameter x,""
Next
j=1
'Rows storing
While rso.EOF<>true
            datatable.GetSheet(1).SetCurrentRow(j)
            For i=0 to noc-1 step 1
                        y=rso.Fields(i).Value
                        datatable.Value(i+1,1)=y
            Next
            rso.MoveNext
            j=j+1
Wend
rso.Close
cono.Close
Set rso=nothing
Set cono=nothing

‘Count the number of columns in database table
Option explicit
Dim cono, rso, noc
Set cono=createobject("ADODB.connection")
cono.open("Provider=SQLOLEDB; Server=SYS; Database=master; Trusted_Connection=yes;")
Set rso=createobject("ADODB.recordset")
rso.Open "select * from DBO.Spt_values", cono
noc=rso.Fields.Count
print "no. of columns in data table" &noc
rso.Close
cono.close

‘Count the number of opened browsers using
Option explicit
Dim desco, childso, nob, bot, i
Set desco=description.Create
desco("micclass").value="Browser"
set childso=desktop.ChildObjects(desco)
nob=childso.count
For i=0 to nob-1 step 1
            bot=childso(i).getroproperty("title")
            If bot<>"Google" Then
                        childso(i).close
            End If
Next
Set childso=nothing
Set desco=nothing

'Child objects
Option explicit
Dim bro, url, childso, desco, nob, c, bot, i
Set desco=description.Create
desco("micclass").value="Browser"
Set childso=desktop.ChildObjects(desco)
nob=childso.count
c=0
For i=0 to nob-1 step 1
bot=childso(i).getroproperty("title")
If bot="Google"  Then
            c=cint(c)+1
            If cint(c)>1 Then
                        childso(i).close
            End If
else
            childso(i).close
End If
Next
If cint(c)=0 Then
            bro="C:\Program Files\Internet Explorer\iexplore.exe"
            url="http:\\www.google.co.in"
            invokeapplication bro&" "&url
End If
Set childso=nothing
Set desco=nothing

‘Spelling checking using word document
Option explicit
Dim bro, url, wo, desco, childso, nol, i, ln
'Launch Google site
bro="C:\Program Files\Internet Explorer\iexplore.exe"
url="http:\\www.google.co.in"
invokeapplication bro&" "&url
'Create word object
Set wo=createobject("Word.Application")
wo.Visible=true
'Find links in Google page for links names spell check
Set desco=description.Create
desco("micclass").value="Link"
Set childso=Browser("title:=Google").page("title:=Google")
                                                                                                                                                                                                                                    .ChildObjects(desco)
nol=childso.count
For i=0 to nol-1 step 1
            ln=childso(i).getroproperty("name")
            wo.WordBasic.filenew
            wo.WordBasic.insert ln
            If wo.ActiveDocument.SpellingErrors.count>0 Then
reporter.ReportEvent micFail,"Link name test","Wrong spelling in "&ln
            else
reporter.ReportEvent micPass,"Link name test","Correct spelling in"&ln
            End If
            wo.ActiveDocument.Close(False)
Next
'Close Google
Browser("title:=Google").Close
wo.Quit
Set childso=nothing
Set desco=nothing
Set wo=nothing


Click to continue QTP Scripts 5







No comments:

Post a Comment