Highlighted
Absent Member.
Absent Member.
1817 views

Broken link check using QTP

I want to check broken links for 50 URLs, could you please let me know the options avaiable.

 

 

0 Likes
1 Reply
Highlighted
Absent Member.
Absent Member.

Re: Broken link check using QTP

1. You may use automatic page checkpoint for broken links.
It will automatically check for broken links on each page while recording.
2. Following code can be used to acheive it:
''Find out all the links in the page using ChildObjects
Set oLink = Description.Create
oLink("micclass").Value = "Link"
Set oAllLinks = Browser("Browser").Page("HomePage").ChildObjects(oLink)

'Find out the count of links
iTotalLinks = oAllLinks.Count

'Loop through all the links to find if the link is broken or not
For i=0 to iTotalLinks - 1

'Find out the url for the link
sURL = oAllLinks(i).GetROProperty("url")

'Create a WinHTTP Request using the link's URL
Set objWinHTTP = CreateObject("WinHttp.WinHttpRequest.6.3")
objWinHTTP.Open "GET", sURL, False
objWinHTTP.SetRequestHeader "User-Agent", "Mozilla/5.0 (compatible; Windows NT 6.3)"

'Send the Request to the Server and capture the response
objWinHTTP.Send
iReturnVal = objWinHTTP.Status

'Find out if the Link exists or is broken
If iReturnVal = 200 Then
msgbox "Link - " & sURL & " Exists"
ElseIf iReturnVal = 404 Then
msgbox "Link - " & sURL & " is Broken"
Else
msgbox "Code" - iReturnVal
End If

Set objWinHTTP = Nothing

Next

3. Checking for Broken Link (http://www.learnqtp.com/how-to-identify-broken-links-in-qtp/)

The above link is having detailed steps to validate the broken link in each page while navigating during the run session

We can observe the list of broken links in each page checkpoint results including the name and URL of the broken links ( so that we can check manually)

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.