GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Testing  >  Test Automation
Go To First  |  Previous Question  |  Next Question 
 Test Automation  |  Question 68 of 140    Print  
how can you check all the URLS / Links are connected and working correctly throughout the application with the help of scripting in Quick Test Professional Automation tools

  
Total Answers and Comments: 10 Last Update: June 18, 2008     Asked by: vishalsdg-325 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Neeraj Chauhan
 
Function CheckLinks2 (BrowserObject, BrowserPage)
    CheckLinks2 = True

    sPage = "micclass:=Page"
    sBrowser = "creationtime:="
    Dim orgURL, orgCreationTime
    Dim i_Link, l_hWnd
    Dim b_newBrowser
    Dim s_LinkOuterText, s_LinkInnerText, s_Linkhref

    s_URL = BrowserPage.GetROProperty("url")
    l_hWnd = BrowserObject.GetROProperty("hwnd")

    i_CreationTime = 1

    i_LinkCount = BrowserPage.Object.links.Length - 1

    For i_Link = 0 To i_LinkCount

        If Trim(BrowserPage.Object.links(i_Link).target) = "" _
                And InStr(BrowserPage.Object.links(i_Link).href, "javascript:") = 0 Then
            b_newBrowser = False
        Else
            b_newBrowser = TRUE
        End If

        s_LinkOuterText = BrowserPage.Object.links(i_Link).outerText
        s_LinkInnerText = BrowserPage.Object.links(i_Link).innerText
        s_Linkhref = BrowserPage.Object.links(i_Link).href

        BrowserPage.Object.links(i_Link).click

        'Doing Browser.Exist with CreationTime:=1 when the browser does not
        'exist will give TRUE so i though of work around to compare the windows
        'handle for the old browser and the new browser with CreationTime:=1.
        'If they are same that mean no other window was opened.
        If b_newBrowser Then
            sBrowser = "CreationTime:=" & i_CreationTime
            l_newhWnd = CLng(Browser(sBrowser).GetROProperty("hwnd"))
            If CLng(l_hWnd) = l_newhWnd Then
                b_newBrowser = False
            End If
        End If

        On Error Resume Next
        If b_NewBrowser Then
            sBrowser = "CreationTime:=" & i_CreationTime
            Browser(sBrowser).sync
            Browser(sBrowser).Page(sPage).sync
        Else
            BrowserObject.sync
            BrowserPage.sync
        End If
        On Error GoTo 0

        Dim s_LinkDetails

        If b_NewBrowser Then
            sBrowser = "CreationTime:=" & i_CreationTime
            IHTML = Browser(sBrowser).Page(sPage).Object.Body.innerHTML
        Else
            IHTML = BrowserPage.Object.Body.innerHTML
        End If

        'Check if page was not able to be displayed you can update this code any time
        If (InStr(IHTML, "HTTP 404") <> 0) Or (InStr(IHTML, "cannot be displayed") <> 0) Then
            s_LinkDetails = "Link Broken" + vbCrLf + "Link Details:" + vbCrLf
            s_LinkDetails = s_LinkDetails + "OuterText: " + s_LinkOuterText + vbCrLf
            s_LinkDetails = s_LinkDetails + "InnerText: " + s_LinkInnerText + vbCrLf
            s_LinkDetails = s_LinkDetails + "href: " + s_Linkhref + vbCrLf
            s_LinkDetails = s_LinkDetails + "Links Open in New Browse: " & bNewBrowser & vbCrLf
            Reporter.ReportEvent micWarning, "Check Link(" & i_Link & ") -> " & s_LinkOuterText , s_LinkDetails
            CheckLinks2 = FALSE
        Else
            s_LinkDetails = "Link Working" + vbCrLf + "Link Details:" + vbCrLf
            s_LinkDetails = s_LinkDetails + "OuterText: " + s_LinkOuterText + vbCrLf
            s_LinkDetails = s_LinkDetails + "InnerText: " + s_LinkInnerText + vbCrLf
            s_LinkDetails = s_LinkDetails + "href: " + s_Linkhref + vbCrLf
            s_LinkDetails = s_LinkDetails + "Links Open in New Browse: " & bNewBrowser & vbCrLf
            Reporter.ReportEvent micPass, "Check Link(" & i_Link & ") -> " & s_LinkOuterText , s_LinkDetails
        End If

        If b_NewBrowser Then
            sBrowser = "CreationTime:=" & i_CreationTime
            While CLng(Browser(sBrowser).GetROProperty("hwnd"))<>l_hwnd
                On Error Resume Next
                Browser(sBrowser).Sync
                Browser(sBrowser).Page(sPage).Close
                On Error GoTo 0
                Browser(sBrowser).Close
                'Tackle links that open a new browser and also opens a popup using that
                'i_CreationTime=i_CreationTime + 1
            Wend

            i_CreationTime = 1

        Else
            On Error Resume Next
            BrowserObject.Navigate s_URL
            BrowserObject.Sync
            BrowserObject.Page.Sync
            On Error GoTo 0
        End If
    Next
End Function

'*********************  In QTP **************
Set BrowserObject = Browser("micClass:=Browser", "CreationTime:=0")
Set BrowserPage = BrowserObject.Page("micClass:=Page")
CheckLinks2 BrowserObject, BrowserPage
'********************************************

Above answer was rated as good by the following members:
krisscool
April 05, 2006 06:23:33   
Vivek        

RE: how can you check all the URLS / Links are connec...
you can use automated tools and websites available to test broken links.Just give the URL of the website and it will generate a report.
 
Is this answer useful? Yes | No
April 05, 2006 14:58:49   
Vishal Asthana        

RE: how can you check all the URLS / Links are connec...
You can only thoes links which have been connected through that page suppose one link is like when you clik on that link a new uirl has been openedso how can you check
 
Is this answer useful? Yes | No
April 25, 2006 02:18:38   
schittoor@gmail.com Member Since: March 2006   Contribution: 24    

RE: how can you check all the URLS / Links are connec...

hi This is srinivasulu. my answer is only system testing time you can check all the URL is perfectly working or not.

if one project u can connected one url but sub-sequence url so many .

suppose u can take 10 sub url's in one project. Each sub Url is one application once finished testing for all the applications. u test system testing that time we combined all the applications and we did and we find its working or not.

if u want any clarification let me know.

Thanks

Srinivasulu.chittoor


 
Is this answer useful? Yes | No
April 25, 2006 15:48:42   
amar_win Member Since: April 2006   Contribution: 39    

RE: how can you check all the URLS / Links are connec...

Simple task like this should be automated. write perl script and check if a link is valid or not.

Pros:

1. You can even check dynamically created links

2. You can create an exe out of this script and run on any platform without perl installed on it ( please remember this is not portable meaning a windows created exe can be used on 95 98 2k xp....only not on unix. but unix machnied always has perl these days )


 
Is this answer useful? Yes | No
June 03, 2006 09:19:56   
Sriharsha        

RE: how can you check all the URLS / Links are connec...

hi....

Im Afraid what u people might not be correct ( Plz note : m not offending anyone)

Checking URL's is called as Link Testing.

Now we use Xenu or Link alarm to check for Broken Links

We use Infocus or A-prompt too for these resons.

thers is a bit of diff between link alarm and infous.


 
Is this answer useful? Yes | No
June 05, 2006 16:27:26   
Vishal        

RE: how can you check all the URLS / Links are connec...
but u cant check the java script page and applet pages.
 
Is this answer useful? Yes | No
September 12, 2006 20:01:57   
Nikki        

RE: how can you check all the URLS / Links are connec...
Cant we check links in Quick Test Pro using Page checkpoint??
 
Is this answer useful? Yes | No
October 31, 2007 18:26:50   
ven Member Since: November 2005   Contribution: 10    

RE: how can you check all the URLS / Links are connec...
We can check the number of images links load time using page checkpoint.
once a page checkpoint is created after runing script in test analysis pane gives detailed count of links images ..

 
Is this answer useful? Yes | No
January 28, 2008 05:48:34   
ankurvohra Member Since: January 2007   Contribution: 3    

RE: how can you check all the URLS / Links are connected and working correctly throughout the application with the help of scripting in Quick Test Professional Automation tools
Hi

I heard that various open tool web spiders exist in the market which can crawl the application and check for the broken links in the web application.

Currently I can not access any open source tool so I was thinking is there any way we can do the same job of web spiders or crawlers using QTP.

I have found out that using Page checkpoint in QTP we can know the number of links and there load time with expected urls in the QTP this web page checkpoint also checks for the broken links in the web application..
But somehow when I tried this on the web page its not working fine .

Randomly its showing number of web links as checked and number of then as Not checked under broken link.

here I am not sure of following :-

A) Not checked URL by QTP is really a broken link or not?
B) Is it possible to navigate full web application for broken link and url using qtp or its page specific only.

While I am trying to find out the answers to my query by further analyzing the test results I have got …

it would be great if someone can help me with the correct way of doing it If someone has tried this before of QTP

Many Thanks
Ankur

 
Is this answer useful? Yes | No
June 18, 2008 06:33:07   
Neeraj Chauhan Member Since: January 2008   Contribution: 5    

RE: how can you check all the URLS / Links are connected and working correctly throughout the application with the help of scripting in Quick Test Professional Automation tools
Function CheckLinks2 (BrowserObject BrowserPage)
CheckLinks2 True

sPage "micclass: Page"
sBrowser "creationtime: "
Dim orgURL orgCreationTime
Dim i_Link l_hWnd
Dim b_newBrowser
Dim s_LinkOuterText s_LinkInnerText s_Linkhref

s_URL BrowserPage.GetROProperty("url")
l_hWnd BrowserObject.GetROProperty("hwnd")

i_CreationTime 1

i_LinkCount BrowserPage.Object.links.Length - 1

For i_Link 0 To i_LinkCount

If Trim(BrowserPage.Object.links(i_Link).target) "" _
And InStr(BrowserPage.Object.links(i_Link).href "javascript:") 0 Then
b_newBrowser False
Else
b_newBrowser TRUE
End If

s_LinkOuterText BrowserPage.Object.links(i_Link).outerText
s_LinkInnerText BrowserPage.Object.links(i_Link).innerText
s_Linkhref BrowserPage.Object.links(i_Link).href

BrowserPage.Object.links(i_Link).click

'Doing Browser.Exist with CreationTime: 1 when the browser does not
'exist will give TRUE so i though of work around to compare the windows
'handle for the old browser and the new browser with CreationTime: 1.
'If they are same that mean no other window was opened.
If b_newBrowser Then
sBrowser "CreationTime: " & i_CreationTime
l_newhWnd CLng(Browser(sBrowser).GetROProperty("hwnd"))
If CLng(l_hWnd) l_newhWnd Then
b_newBrowser False
End If
End If

On Error Resume Next
If b_NewBrowser Then
sBrowser "CreationTime: " & i_CreationTime
Browser(sBrowser).sync
Browser(sBrowser).Page(sPage).sync
Else
BrowserObject.sync
BrowserPage.sync
End If
On Error GoTo 0

Dim s_LinkDetails

If b_NewBrowser Then
sBrowser "CreationTime: " & i_CreationTime
IHTML Browser(sBrowser).Page(sPage).Object.Body.innerHTML
Else
IHTML BrowserPage.Object.Body.innerHTML
End If

'Check if page was not able to be displayed you can update this code any time
If (InStr(IHTML "HTTP 404") <> 0) Or (InStr(IHTML "cannot be displayed") <> 0) Then
s_LinkDetails "Link Broken" + vbCrLf + "Link Details:" + vbCrLf
s_LinkDetails s_LinkDetails + "OuterText: " + s_LinkOuterText + vbCrLf
s_LinkDetails s_LinkDetails + "InnerText: " + s_LinkInnerText + vbCrLf
s_LinkDetails s_LinkDetails + "href: " + s_Linkhref + vbCrLf
s_LinkDetails s_LinkDetails + "Links Open in New Browse: " & bNewBrowser & vbCrLf
Reporter.ReportEvent micWarning "Check Link(" & i_Link & ") -> " & s_LinkOuterText s_LinkDetails
CheckLinks2 FALSE
Else
s_LinkDetails "Link Working" + vbCrLf + "Link Details:" + vbCrLf
s_LinkDetails s_LinkDetails + "OuterText: " + s_LinkOuterText + vbCrLf
s_LinkDetails s_LinkDetails + "InnerText: " + s_LinkInnerText + vbCrLf
s_LinkDetails s_LinkDetails + "href: " + s_Linkhref + vbCrLf
s_LinkDetails s_LinkDetails + "Links Open in New Browse: " & bNewBrowser & vbCrLf
Reporter.ReportEvent micPass "Check Link(" & i_Link & ") -> " & s_LinkOuterText s_LinkDetails
End If

If b_NewBrowser Then
sBrowser "CreationTime: " & i_CreationTime
While CLng(Browser(sBrowser).GetROProperty("hwnd"))<>l_hwnd
On Error Resume Next
Browser(sBrowser).Sync
Browser(sBrowser).Page(sPage).Close
On Error GoTo 0
Browser(sBrowser).Close
'Tackle links that open a new browser and also opens a popup using that
'i_CreationTime i_CreationTime + 1
Wend

i_CreationTime 1

Else
On Error Resume Next
BrowserObject.Navigate s_URL
BrowserObject.Sync
BrowserObject.Page.Sync
On Error GoTo 0
End If
Next
End Function

'********************* In QTP **************
Set BrowserObject Browser("micClass: Browser" "CreationTime: 0")
Set BrowserPage BrowserObject.Page("micClass: Page")
CheckLinks2 BrowserObject BrowserPage
'********************************************

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape