Forum Discussion

slaugier's avatar
slaugier
Occasional Contributor
7 years ago

How to get the pixel tolerance value?

Hello, 

 

I compare 2 files. My goal is to set a warning message if the pixel tolerance is below a certain value. An error message if it is up to this value.

How can I get the exact pixelTolerance value?

 

Here is my code. I want to update it and put an If condition before the Log.Warning line


     

if (!pic_1.Compare(pic_2, false, 5, false, 5, 0))     
{
// Images are differents
// Post image differences to the log
imgError = pic_1.Difference(pic_2, false, 5, false, 5, 0);
Log.Picture(imgMaskError);

//png file with errors
imgError.SaveToFile(sDirectoryPath + sReportName + "_error_p"
+ aqConvert.IntToStr(i+1) + ".png");

// Post a warning message
Log.Warning("Pages " + aqConvert.IntToStr(i+1) + " are differents.");
aqFile.WriteToTextFile(sDirectoryPath + "log.log", "Page "
+ aqConvert.IntToStr(i+1) + " KO : " + sReportName + "_error_p"
+ aqConvert.IntToStr(i+1) + ".png created.\r\n",
aqFile.ctANSI, false);
}

else
{
// Pages are equals
Log.Message("Pages " + aqConvert.IntToStr(i+1) + " are equals.")
aqFile.WriteToTextFile(sDirectoryPath + "log.log",
"Page " + aqConvert.IntToStr(i+1) + " OK.\r\n",
aqFile.ctANSI, false);
}

 

  • I'm not sure of way to get the difference value returned from not matching values, but you specify the tolerance in your compare. 

     

    https://support.smartbear.com/testcomplete/docs/reference/program-objects/picture/compare.html

     

    But for what you're doing I don't think you really even need it. You could just nest compares with varying tolerances.

     

      let maxDifference = 20;
      // check if they're identical
      if(!pic_1.Compare(pic_2)) {
        // if they're more than maxDifference log error
        if(!pic_1.Compare(pic_2, false, maxDifference, false, 5, 0)) {
          Log.Error()
        } else {
          // they're different but acceptable log a warning
          Log.Warning();
        }
      }
  • cunderw's avatar
    cunderw
    Community Hero

    I'm not sure of way to get the difference value returned from not matching values, but you specify the tolerance in your compare. 

     

    https://support.smartbear.com/testcomplete/docs/reference/program-objects/picture/compare.html

     

    But for what you're doing I don't think you really even need it. You could just nest compares with varying tolerances.

     

      let maxDifference = 20;
      // check if they're identical
      if(!pic_1.Compare(pic_2)) {
        // if they're more than maxDifference log error
        if(!pic_1.Compare(pic_2, false, maxDifference, false, 5, 0)) {
          Log.Error()
        } else {
          // they're different but acceptable log a warning
          Log.Warning();
        }
      }