Thursday, 17 January 2013

Web Links Testing (Internal Links & External Links)



The below is a very simple and interesting code for links count using QTP in DP(Descriptive Programming)  I hope you will find it exciting :-)

This will give you number of internal links, number of external links and number of total links :-)
-----------------------------------------------------------------------------------------------------------------------------
Option explicit
Dim Desco, Childso, I, Ieo, Ilc, Olc, Lc, It
'Launch webtours site
set ieo=createobject("internetexplorer.application")
ieo.visible=true
ieo.navigate ("http://site1.way2sms.com/content/help.html")
window("hwnd:="&ieo.hwnd).maximize
'Find number of links 
Set desco=description.create
Desco("micclass").value= "link"
With browser("creationtime:=0")
Set childso= .page("title:=Way2SMS").childobjects(desco)
End with
'Find number of internal and external links 
ilc=0
olc=0
Lc= childso.count
For i = 0 to Lc -1 step 1
it =childso(i).getroproperty("target")
if it = "_blank" then
    olc= olc+1
else ilc= ilc+1
end if
next
'display output and close site
Print ("Number of internal links are"&ilc)
Print ("Number of external links are"&olc)
Print ("Number of total links are"&Lc)
Ieo.quit
Set childso=nothing
Set desco=nothing
Set ieo=nothing
-----------------------------------------------------------------------------------------------------------------------------