Forum Discussion

MB123FinD37's avatar
MB123FinD37
New Contributor
8 years ago

most efficient way to code file comparison checkpoints in large quantities

I'm looking for Suggestions/Tips/Tricks for an upcoming project.  I am attempting to do some very simple file comparisons, but I am attempting to do so for a very large number of files so I would like to find the most efficient method possible.  Efficiency is key given the number of files for the purposes of adding new test cases and for future maintenance.  I will be generating new files on a regular basis that will be compared to previously generated File Checkpoint baselines that will be maintained in the SmartBear store.  The generation of the new files will be handled by a separate automated process I've already configured, so all I need to do is automated the file comparisons in an efficient and easily maintainable way.

 

In other words, one newly generated file in a local directory will be compared against a SmartBear file Store file, and script will produce a warning if the comparison is above the AllowedDifference threshold, or will produce a Test Pass log entry if all is good. 

 

I would like to maintain some sort of list... this list will contain categories like these to identify the files that I'm referencing:

 

1. file directory

2. file name

3. Hash  % of "AllowedDifference" between the new/old files

5. Category of file

6. sub-Category of the file

4. name/location of the baseline file checkpoint in the SmartBear file Store that the newly generated file above file will be compared against.

 

I will iterate over the various test cases in the above list based on the Category/SubCategory supplied.

 

Any suggestions on how I may do this using SmartBear Scripts, keyword tests, File Checkpoints, etc.  I'm wondering if I can use some sort of variable list or a Database to store all the values and maintain them in this list, and some variation of the "Check" method with "AllowedDifference" parameter to verify if the file content of the new files is sufficient for a Test Pass.

 

Any help would be greatly appreciated.

 

Thanks,

K

 

 

  • What kind of files are you going to make ? do you need to compare context in files or just compare byte codes.?

     

    Test Complete will do comparison byte by byte. In some file types eg - PDF if not similar TC will let you know how many byte differs from original only. But TC can show difference between two text files.

     

    To iterate over sort of list you can use DDT drivers. link

  • Thanks NisHera.  Various text file formats, so yes I'll be attempting to use File Vericiation Checkpoints so I can see what has changed.  I'll be attempting to use hash to allow files to pass if there is an acceptable % of difference in certain cases.

     

    Anyway, I think the DDT drivers may be the answer I need.  I need multiple different rows of values in the Excel or CSV driver though, so I may need to load to an Array in the script/keyword test in order to access the various columns/rows of data to get the values I'm after.

     

    A little concerned about the performance if I have thousands of rows/columns in the spreadsheet... have you used this with a large spreadsheet or CSV before, and if so any latency/issues with scripts running to completion.  In other  words, is the loading of the DDT Driver content fast?

     

  • I don't know Python well so forgive me if my syntax is incorrect. 

     

    If I understand correctly, Baseline, as it comes from the DDT driver, is a text string that represents the name of the file in the Files store of TestComplete.  So, you want to compare that file to what is being created as OBFile, right?

     

    If that's the case, then your comparison should look like this:

    # Creates a driver
    Driver = DDT.ExcelDriver("C:\\SmartBear-DDTDrivers\\BulkCustody.xlsx", "Sheet1")
    
    OBFile = aqString.Concat(DDT.CurrentDriver.Value[0], DDT.CurrentDriver.Value[1])
    Baseline = DDT.CurrentDriver.Value[2]
    AllowableDiff = StrToInt(DDT.CurrentDriver.Value[3])
    
    # Perform file comparison for each entry in the Excel file
    if (Files.Items(Baseline).Check(OBFile, AllowableDiff) == False):
      Log.Warning("For BaselineFileName" + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value[2]) + "the file HashCompare is beyond acceptable threshold - Please review OB file and compare against baseline file in SmartBear Repository.", pmHighest)# highest priority
    else:
       Log.Message(aqConvert.VarToStr(DDT.CurrentDriver.Value[2]) + "file was verified and is either identical or within acceptable threshold - No further actoin is needed.")

    The Files.Items method returns the File object with the indicated name.  You can then call the "Check" method of that item as you are doing.

  • NisHera's avatar
    NisHera
    Valued Contributor

    What kind of files are you going to make ? do you need to compare context in files or just compare byte codes.?

     

    Test Complete will do comparison byte by byte. In some file types eg - PDF if not similar TC will let you know how many byte differs from original only. But TC can show difference between two text files.

     

    To iterate over sort of list you can use DDT drivers. link

    • MB123FinD37's avatar
      MB123FinD37
      New Contributor

      Thanks NisHera.  Various text file formats, so yes I'll be attempting to use File Vericiation Checkpoints so I can see what has changed.  I'll be attempting to use hash to allow files to pass if there is an acceptable % of difference in certain cases.

       

      Anyway, I think the DDT drivers may be the answer I need.  I need multiple different rows of values in the Excel or CSV driver though, so I may need to load to an Array in the script/keyword test in order to access the various columns/rows of data to get the values I'm after.

       

      A little concerned about the performance if I have thousands of rows/columns in the spreadsheet... have you used this with a large spreadsheet or CSV before, and if so any latency/issues with scripts running to completion.  In other  words, is the loading of the DDT Driver content fast?

       

    • MB123FinD37's avatar
      MB123FinD37
      New Contributor

      I have it mostly figured out.  One more question...

      One thing that is not working however is I'm unable to call the FileObj.Check if I'm using a variable from the DDT Driver.  when I attempt to pass a variable to the 1st parameter of the File Check method :

      # Creates a driver
      Driver = DDT.ExcelDriver("C:\\SmartBear-DDTDrivers\\BulkCustody.xlsx", "Sheet1")


      OBFile = aqString.Concat(DDT.CurrentDriver.Value[0], DDT.CurrentDriver.Value[1])
      Baseline = DDT.CurrentDriver.Value[2]
      AllowableDiff = StrToInt(DDT.CurrentDriver.Value[3])

      # Perform file comparison for each entry in the Excel file
      if (Files.Baseline.Check(OBFile, AllowableDiff) == False):
        Log.Warning("For BaselineFileName" + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value[2]) + "the file HashCompare is beyond acceptable threshold - Please review OB file and compare against baseline file in SmartBear Repository.", pmHighest)# highest priority
      else:

         Log.Message(aqConvert.VarToStr(DDT.CurrentDriver.Value[2]) + "file was verified and is either identical or within acceptable threshold - No further actoin is needed.")

       

       

      It fails with error on the "if (Files.Baseline.Check(OBFile, AllowableDiff) == False):"  line :

      Python runtime error.

      AttributeError

      the object does not support this property or method

       

       

      I just need a way to pass in the File Object names - I am storing these names in the DDT.ExcelDriver as well since there are so many and they need to correspond with the Files I am comparing against.  Just need a way to represent this as an Object in the script.  Any ideas?

      • baxatob's avatar
        baxatob
        Community Hero

        Files.Baseline.Check()

         

        Files  provides an interface ONLY to the objects created in Stores/Files, however you are trying to get access to the Baseline, which actually is a DDT object.