Currently part of my testing includes verifying web pages. Basically, I'm given a list of urls, and I have to validate that they are good. Right now, each of the urls are taken from a text file, and then loaded into the browser
using the "ToURL" method. I then check the inner Text or HTML for certain criteria to identify if it is valid. Sometimes the list I have to go through is very large, and verifying the web pages this way can take very long.
Basically all I need to know is if the web page returns a 404 error, so ideally I would rather have TestComplete check for that, other than having to search each page for certain text. Has anyone done this with TestComplete? Is this possible?
Here is a little link checker script that I came across online and converted from ASP. Works great, just verified it in TC actually. Obviously you can iterate through this using different URLs if necessary, as long as the core code remains the same.
<font class="small">Code:</font><hr /><pre>
thisURL = "http://www.google.ca"
thisStatus = 0
if len(trim(thisURL)) > 0 then
Set obj = CreateObject("MSXML2.XMLHTTP.4.0")
on error resume next
obj.open "GET", trim(thisURL), False
if err.number = 0 then
thisStatus = obj.Status
on error goto 0
if iStatus = 200 then
Log.Message "<p>The URL " & thisURL & " is valid, status is " & thisStatus & "</p>" & vbCRLF
Log.Message "<p>The URL " & thisURL & " is invalid, status is " & thisStatus & "</p>" & vbCRLF