Forum Discussion

Innovation's avatar
Innovation
New Contributor
8 years ago

Verifying .Pix Files with variable Parts

Hello Smartbearcommunity,

 

i'm trying to verifying 2 .pix files and in thispix files the "id" is changing.

How do i get my script working?

Example PIX File

File1

<? xml version"1.0! encoding="UTF-8"?><!--comment--><METADATA><CONSIGNOR AppVersion="xx.xx.xx" DBStructure="4.0" ID="123"/></METADATA>

File 2

<? xml version"1.0! encoding="UTF-8"?><!--comment--><METADATA><CONSIGNOR AppVersion="xx.xx.xx" DBStructure="4.0" ID="456"/></METADATA>

my DelphiScript

 

function CompareFiles(fileName1, fileName2);
const
  ForReading = 1;
var
  fso, regEx;
  file1, file2;
  fileText1, fileText2, newText1, newText2;
begin
  // Creates the FileSystemObject object
  fso := Sys.OleObject('Scripting.FileSystemObject');

  // Reads the first text file
  file1 := fso.OpenTextFile(fileName1, ForReading);
  fileText1 := file1.ReadAll;
  file1.Close;

  // Reads the second text file
  file2 := fso.OpenTextFile(fileName1, ForReading);
  fileText2 := file2.ReadAll;
  file2.Close;

  // Creates the regular expression object
  regEx := HISUtils.RegExpr;

  // Specifies the pattern for the date/time mask
  // MM/DD/YYYY HH:MM:SSLL (for example: 4/25/2006 10:51:35AM)
  regEx.Expression := '(?i)\d{1,2}.\d{1,2}.\d{2,4}\s\d{1,2}:\d{2}:\d{2}\w{2}';
  
  // Replaces the text matching the specified date/time format with <ignore> 
  newText1 := regEx.Replace(fileText1, '<ignore>');
  newText2 := regEx.Replace(fileText2, '<ignore>');

  // Compares the text
  Result := (newText1 = newText2);
end;

procedure CompareMethodVersuch1;
var
  fileName1, fileName2;
begin
  fileName1 := 'C:\Users\Admin\Desktop\MasterReport.pix';
  fileName2 := 'C:\Users\Admin\Desktop\MasterReport2.pix';

  if CompareFiles(fileName1, fileName2) then
    Log.Message('The files are equal')
  else
    Log.Error('The files are different');
end;

I'm using this Example

 

https://support.smartbear.com/testcomplete/docs/testing-with/checkpoints/files/comparing-with-variable-parts.html

 

I think i have to change this line of code

"regEx.Expression := '(?i)\d{1,2}.\d{1,2}.\d{2,4}\s\d{1,2}:\d{2}:\d{2}\w{2}';"

 

best regards :)

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    OK.... You're asking "how to get my script working".  But you haven't described what's NOT working.

    1) Error messages, either on screen or in log?

    2) Do you have a particular line of code that seems to be failing?

     

    That said... a quick google online notes that PIX files are image files.  But you're posting stuff about XML meta data and such.  Something's not matching here.  Are you comparing two image files? Or are you comparing two text files?

     

     

  • Innovation's avatar
    Innovation
    New Contributor

    I'm sorry for my bad explanation i was in a hurry yeserday.

    I didn't know that .pix was common for images and i'm trying to compare XML data.

    The problem is that i don't know what i have to insert in this line

    regEx.Expression := '(?i)\d{1,2}.\d{1,2}.\d{2,4}\s\d{1,2}:\d{2}:\d{2}\w{2}';

    No matter what i try i end up with the result that the files are equal even when they are not equal.

     

    There are 2 parts where the files differ, the ID and the Date.

    Can you give me an example how i can get the script to ignore the ID wich i showed in the previous post ?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Actually, what I would do is not use a pure file to file comparison like that at all.  These are XML files and you can actually compare node to node and, if there are nodes you don't want to compare, simply skip them.  

       

      I'd write a routine (and I don't have time to do it right now) that would utilize MSXML.DOMDocument objects to grab the two XML files into DOM objects.  Then, you could write a function that would grab a particular child node from one file, grab the related one from the other file, and compare the contents to see if they match.  This even has the advantage that you can target particular sections and compare them rather than having to do the whole file.  For example, your application performs a process that updates only 2 or 3 nodes within the XML file.  Rather than having to compare the whole file, just check those 2 or 3 nodes.

      There's a good bit of documentation out there online on how to utilize the MSXML.DOMDocument objects to compare XML files.

      If you don't want to go the route of a customly created routine, you could always use XMLCheckpoints.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      Regex for the AppVersion can be like this:

      (?-g)AppVersion="(.+)"

      i.e.: search for anything after 'AppVersion' that is enclosed in quotes.

       

      Likewise, the regex for the ID may be like this:

      (?-g)ID="(.+)"

       

      And, instead of

      regEx.Replace(fileText1, '<ignore>');

      something like

      regEx.Replace(fileText1, 'AppVersion="<ignore>"');

      and

      regEx.Replace(fileText1, 'ID="<ignore>"');

      should be used.