QTP Scripts 5

'Test Gmail link
Option explicit
Dim bro, url, x, y
'Launch Google site
bro="C:\Program Files\Internet Explorer\iexplore.exe"
url="http:\\www.google.co.in"
invokeapplication bro&" "&url
'Test Gmail link
with Browser("title:=Google").page("title:=Google")
            x=.link("name:=Gmail").GetROProperty("url")
            .link("name:=Gmail").Click
End with
y=Browser("title:=.*").GetROProperty("url")
If instr(x,y) Then
            Reporter.ReportEvent micPass,"Link url test","Correct"
else
            Reporter.ReportEvent micFail,"Link url test","Incorrect"
End If
Browser("title:=.*").Close

‘Using childobjets verifying links
Option explicit
Dim bro, url, desco, childso, nol, i, x, y
'Launch Web tours site
bro="C:\Program Files\Internet Explorer\iexplore.exe"
url="http://127.0.0.1:1080/WebTours/"
invokeapplication bro&" "&url
'Find links in Web tours for links url check
Set desco=description.Create
desco("micclass").value="Link"
Set childso=Browser("title:=Web Tours").page("title:=Web Tours").ChildObjects(desco)
nol=childso.count
For i=0 to nol-1 step 1
  Set childso=Browser("title:=Web Tours").page("title:=Web Tours").ChildObjects(desco)
            x=childso(i).getroproperty("url")
            childso(i).click
            y=Browser("title:=.*").GetROProperty("url")
            If instr(x,y) Then
                        Reporter.ReportEvent micPass,"Link test",x&" is Correct"
            else
                        Reporter.ReportEvent micFail,"Link test",x&" is Incorrect"
            End If
            Browser("title:=.*").Back
Next
Browser("title:=Web Tours").Close
Set childso=nothing
Set desco=nothing

‘Image types checking
Option explicit
Dim bro, url, desco, childso, noi, i, x,nopi,noib,noil,nodi
bro="c:\program files\internet explorer\iexplore.exe"
url="http://127.0.0.1:1080/WebTours/"
invokeapplication bro&" "&url
Set desco=description.Create
desco("micclass").value="image"
With browser("title:=Web Tours").page("title:=Web Tours")
            Set childso=.ChildObjects(desco)
End With
noi=childso.count
nopi=0
noib=0
noil=0
nodi=0
For i=0 to noi-1 step 1
            x=childso(i).getROproperty("image type")
            Select Case x
            Case "Plain Image"
                        nopi=nopi+1
             Case "Image Button"
                         noib=noib+1
              Case "Image Link"
                          noil=noil+1
             case else
                        nodi=nodi+1
  End Select
Next
print "No: of plain image  is "&nopi
print "No: of image buttons is "&noib
print "No: of image links is "&noil
print "No: of dynamic image  is "&nodi
browser("title:=Web Tours").Close
set childso=nothing
set desco =nothing

‘Verify the image loaded or not
Option explicit
Dim bro, url, desco, childso, noi, i, x, y
bro="c:\program files\internet explorer\iexplore.exe"
url="http://newtours.demoaut.com/"
invokeapplication bro&" "&url
Set desco=description.Create
desco("micclass").value="image"
With browser("title:=Welcome.*").page("title:=Welcome.*")
            Set childso=.ChildObjects(desco)
End With
noi=childso.count
For i=0 to noi-1 step 1
            x=childso(i).getroproperty("name") 'Get identification
            y=childso(i).object.complete 'get native
            If y=true Then
                        Reporter.ReportEvent micPass,"Image load test",x&" loaded"
            else
                        Reporter.ReportEvent micFail,"Image load test",x&" not loaded"
                        childso(i).highlight
            End If
Next
Browser("title:=Welcome.*").Close
Set childso=nothing
Set desco=nothing

‘Image comparison
Option explicit
Dim bro, url, desco, childso, noi, i, ico, x, y
'Launch site
bro="c:\program files\internet explorer\iexplore.exe"
url="http://newtours.demoaut.com/"
invokeapplication bro&" "&url
'Find images
Set desco=description.Create
desco("micclass").value="image"
With browser("title:=Welcome.*").page("title:=Welcome.*")
            Set childso=.ChildObjects(desco)
End With
noi=childso.count
'create compare object
Set ico=createobject("Mercury.Filecompare")
'comparison
For i=0 to noi-1 step 1
            x=childso(i).getroproperty("src")
            y="C:\image"&i&".bmp"
            childso(i).capturebitmap(y)
            If ico.IsEqualBin(x,y,0,1) Then
                        reporter.ReportEvent micPass,"Image content test","Same"
            else
                        reporter.ReportEvent micFail,"Image content test","NotSame"
            End If
Next
'close site
Browser("title:=Welcome.*").Close
Set ico=nothing
Set childso=nothing
Set desco=nothing

‘Using the Web application all items
Option explicit
Dim bro, url
'Launch site
bro="c:\program files\internet explorer\iexplore.exe"
url="http://newtours.demoaut.com/"
invokeapplication bro&" "&url
'Login
With browser("title:=Welcome.*").page("title:=Welcome.*")
            .webedit("name:=userName").set "admin"
            .webedit("name:=password").set "admin"
            .image("name:=login").click
End With
'Journey details
With browser("title:=Find.*").page("title:=Find.*")
            .webradiogroup("name:=tripType").Select("#1")
            .weblist("name:=passCount").Select("2")
            .weblist("name:=fromPort").Select("Paris")
            .weblist("name:=fromMonth").Select("August")
            .weblist("name:=fromDay").Select("20")
            .weblist("name:=toPort").Select("London")
            .weblist("name:=toMonth").Select("June")
            .weblist("name:=toDay").Select("30")
            .webradiogroup("name:=servClass").Select("#1")
            .weblist("name:=airline").Select("#1")
            .image("name:=findFlights").Click
End With
'logout
With browser("title:=Select.*").page("title:=Select.*")
            .Link("name:=SIGN-OFF").Click
End with
'close
browser("title:=Sign.*").Close

‘Get the inner text of element
Option explicit
Dim bro, url, x
'Launch site
bro="c:\program files\internet explorer\iexplore.exe"
url="http://127.0.0.1:1080/WebTours/"
invokeapplication bro&" "&url
'content test
With Browser("title:=Web Tours").page("title:=Web Tours")
            With .frame("name:=info")
x=.webelement("html tag:=BLOCKQUOTE").getroproperty("innertext")
            End With
            End With
If instr(x,"Welcome to the Web Tours site.") Then
            reporter.ReportEvent micPass,"Content test","Correct"
else
            reporter.ReportEvent micFail,"Content test","Incorrect"
End If
Browser("title:=Web Tours").Close

14 comments:

  1. Thank u and i wish u the same to u, keep posting u r valuable comments and suggestions..

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Whatever we gathered information from the blogs, we should implement that in practically then only we can understand that exact thing clearly, but it’s no need to do it, because you have explained the concepts very well. It was crystal clear, keep sharing..
    Java Training in Chennai
    Java course in Chennai
    Java Training Institute in Chennai
    Best Java Training Institute in Chennai
    Java Training
    Java Classes in Chennai
    Core Java Training in Chennai

    ReplyDelete
  4. Excellent post! keep sharing such a post

    Education

    wblogin

    ReplyDelete