HOWTO: Track test case progress in TestComplete

Right now I'm working on automating test procedures that test the software we're working on. As always, at the end of our automation we need to provide a detailed report with results for every step of the procedure. Since our procedures have two types of steps, Action Step and Verification Step, we need to provide different pass/fail messages. So, to make this happen, I've decided to use the following approach. Create an array that will hold all of the results data; Create couple of functions that will update the results array for every step and a function that will initialize the results array.

Here's the code to initialize the array:

function InitResults(caseName, stepCount, verSteps) {
   // make sure that all required parameter have been accounted for
   if (!verSteps || !stepCount || !caseName) {
      return "All parameters are required!";
   }
 
   // initialize results array
   resultsArr = new Array();
 
   for (var i = 0; i < stepCount; i++) {
      resultsArr[i] = new Array();
      var isVer = ArrayContains(verSteps, i + 1);
      resultsArr[i]["result"] = (isVer == true) ? "Not Verified" : "Not Executed";
      resultsArr[i]["reason"] = "";
      resultsArr[i]["isVerification"] = isVer;
   }
   resultsArr["title"] = caseName;
}
 
function ArrayContains(arr, value) {
   for (var i = 0; i < arr.length; i++) {
      if (arr[i] == value) {
         return true;
      }
   }
   return false;
}

Here's the code to update the array. Please note that GetDefectNumber function is described here

function UpdateResults(resArr, stepNumber, result, reason) {
   if (!reason || (reason == null)) { reason = ""; }   
   var isVer = resArr[stepNumber]["isVerification"];
 
   // update result text
   if (aqString.Find(result, "pass", 0, false) >= 0) {
      result = (isVer == true) ? "Pass" : "Executed";
      reason = "";
   }
   else if (aqString.Find(result, "fail", 0, false) >= 0) {
      result = (isVer == true) ? "Fail" : "Error Observed";
      reason += " " + GetDefectNumber(reason);
      Log.Picture(Sys.Desktop.Picture(), "Step " + stepNumber + "Failed. Reason: " + reason);
   }
 
   resArr[stepNumber]["result"] = result;
   resArr[stepNumber]["reason"] = reason;
}

And, here's the code on how to use this approach. Please note that you could provide the reason regardless of the step's pass/fail status. If step has passed, the reason will get ignored!

function MyTest() {
  var caseName = "My Test Case";
  var stepCount = 2;
  var verSteps = new Array(2);
  var resArray = InitResults(caseName, stepCount, verSteps);
  var actionStep = DoSomething();
  var result = (actionStep == true) ? "Pass" : "Fail";
  UpdateResults(resArray, 1, result, "DoSomething function failed.");
  var verStep = DoSomethingElse();
  var result = (verStep == true) ? "Pass" : "Fail";
  UpdateResults(resArray, 2, result, "DoSomethingElse function failed.");
}

As always, questions, comments, critiques are welcomed!

Comments