Checking whether a website is up

This recipe will show you how to check that a site is up, using the XMLHttp object we have seen in action in the Checking whether page links are broken recipe.

Getting ready

We will be using the Web_Functions.vbs function library, seen in the previous recipe, to take advantage of the objXMLHttp global variable, along with the InitXMLHttp() and DisposeXMLHttp() functions. Make sure the library is associated to the test.

How to do it...

Basically, here we will follow the same logic as in the Checking whether page links are broken recipe, but instead of getting the URL from the page links dynamically, we will just pass the URL to the function:

Function checkSiteIsUp(URL)        
    If lcase(typename(oXMLHttp)) <> "xmlhttp" Then    
        initXMLHttp()
    End If
    
    if oXMLHttp.open("GET", URL, false) = 0 then
        oXMLHttp.send()
    
        If oXMLHttp.Status<>200 Then
            reporter.ReportEvent micFail, "Check site is up", "Site " & URL & " is unreachable: " & oXMLHttp.Status
        Else
            reporter.ReportEvent micPass, " Check site is up ", "Site " & URL & " is up"
        End If
    End if                                  
End Function

In Action1, we will invoke the function as follows:

checkSiteIsUp("http://www.advancedqtp.com")

How it works...

As mentioned in this recipe, the logic here is pretty much the same as with checking for broken links. We send an Http Get request and check the status returned by the server.

See also

The Checking whether page links are broken recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset