onlogerror event in testcomplete

150 views Asked by At

I have a function which compares 2 array values. As soon as a mismatch value is found the execution stops , but i want to only when all comparison have been done and if error has been found. There is OnLogError in testcomplete but do not know how to use it

function compare() {
  for (var i = 0; i < arrActualIntendedVal.length; i++) {
    if (val1[i] != val2[i]) {
        Log.Error("Value " + val1[intArrIndex] + " do not match to Actual Value " +
        val2[intArrIndex]);
        Runner.Stop(0);
    }
  }
  return true;
}

1

There are 1 answers

0
Dmitry Nikolaev On

You just need to "remember" that there was an error and post the corresponding info after your loop is finished.

function compare() {
  var errors = new Array();
  for (var i = 0; i < arrActualIntendedVal.length; i++) {
    if (val1[i] != val2[i]) {
        errors.push("Value " + val1[intArrIndex] + " do not match to Actual Value " + val2[intArrIndex]);
    }
  }

  if (errors.length > 0) {
      Log.Error("Error when comparing arrays", errors.join("\r\n"));
      Runner.Stop();
  }

  return true;
}