HOWTO: Get defect number from Excel file using TestComplete

So, right now we have a requirement, for every failure within our automated test case, we have to report a defect number next to the failing step. We can place a defect number by printing out the results and writing a number by hand, but I find it too tedious.

So, to reduce the "manual labor", I've decided to use the following approach, which seems to work very well. I've created an Excel file, which contains 2 columns: Error message and a defect number. The Error message is the message that my script is displaying and a defect number is a defect that is associated with a current condition.
After creating a file, I've written a small function that is checking if a defect for a current condition exists and returns defect number.
Here's the code:

function GetDefectNumber (errorString) {
   var driverName = "";
   var retVal = "";
 
   try {
      var driver = DDT.ExcelDriver(m_defectsFile, m_defectsSheet);
      driverName = driver.Name;
 
      while (!driver.EOF()) {
         var value = driver.Value(0);
         if (value == errorString) {
            retVal = "(" + driver.Value(1) + ")";
            break;
         }
         driver.Next();
      }
   }
   catch (ex) { }
   finally {
      if (driverName != "") {
         DDT.CloseDriver(driverName);
      }
      return retVal;
   }
}

So, when I write my results to a file, I call this function on a fail reason and, if return value is not an empty string, I append a defect number.

What do you guys think about this approach? Are you using something different?

Comments and questions are always welcomed!

Comments