Verify broken links in TestComplete

TestComplete is a functional automated testing tool from SmartBear. Using TestComplete we can automate both desktop, web and mobile applications. It come up with rich features like record and playback, distributed testing, scripted testing etc.

Here we're talking about how to verify the broken links in a web page.

Function VerifyWebObject accepts two arguments,
1. link 
URL to be verified, You can call this function in an iterative model so that we can verify all the urls in a web page
2. expectedObjectData -
Empty value, this value compared with http response data. In switch case you can add other web status to fit your requirements
function VerifyWebObject(link, expectedObjectData)
{
  try
  {
    var httpObj = Sys.OleObject("MSXML2.XMLHTTP");
    httpObj.open("GET", link, true);
    httpObj.send();

    while (httpObj.readyState != 4)
    Delay(100);

    switch (httpObj.status)
    {
      case 200:
      case 302:

      if (httpObj.responseText != expectedObjectData)
      {
        Log.Message("The link is valid "+link);
        return true;
      }
      break;
      default:
       Log.Error("The link is invalid " + link);
        return false;
    }
      return true;
  }
  catch(e)
  {
    Log.Error(e.description+"link is "+link);
  }
}

Share this