activities
latest
false
Workflow Activities
Last updated Oct 31, 2024

VerifyDocumentsEquivalence

Verifies if two documents are equivalent, using multiple comparison options, including the following comparison types:
  • Comparing words.
  • Comparing lines.
  • Comparing characters as char variables.
Note: The supported document type is PDF.

Definition

Namespace: UiPath.Testing.API

Assembly: UiPath.Testing.Activities.Api (in UiPath.Testing.Activities.Api.dll)

VerifyDocumentsEquivalence(string, string, ComparisonType, CompareDocumentsOptions)

ComparisonResult VerifyDocumentsEquivalence(
    string baselinePath,
    string targetPath,
    [ComparisonType comparisonType],
    [CompareDocumentsOptions opts])ComparisonResult VerifyDocumentsEquivalence(
    string baselinePath,
    string targetPath,
    [ComparisonType comparisonType],
    [CompareDocumentsOptions opts])
baselinePath String
The path of the base document that is used as a reference for comparison.
targetPath String
The path of the document that is compared against the base document.
comparisonType ComparisonType (Optional)
The type of comparison to use when comparing documents. The following options are available:
  • ComparisonType.Char: Compares every character (char) in the documents.
  • ComparisonType.Line: Compares every line in the documents.
  • ComparisonType.Word: Compares every word in the documents.
opts CompareDocumentsOptions
The specific comparison options that should be used for this operation. To create an object of type CompareDocumentsOptions, use theTestingOptions.CompareDocuments Class.

Return value

ComparisonResult

The result of the comparison action, stored within a ComparisonResult variable.

Examples

  1. Comparing PDFs by characters:
    In this example, we are comparing two PDF files, a light bill and a water bill. The comparison is done at the character level. The paths of these PDF files are represented by the firstBill and secondBill variables. The wildcard rule and regex rule provided along with WithIgnoreWildcardRule and WithIgnoreRegexRule methods are used to ignore specific patterns in the comparison. For instance, the wildcard rule 2022 and the regex rule \d{1,2}/\d{1,2}/\d{4} ignore dates (assuming they are in the MM/DD/YYYY format) in the comparison, since they might differ in two separate bills and aren't relevant to the structure of the bills.
    Once the comparison is done, the WithGenerateHtml method creates an HTML report of the comparison and any differences found are recorded in the logs using the method Log.
    var firstBill = @"C:\bills\2024.10\pdfs for compare\(electricity_bill.pdf";
    var secondBill = @"C:\bills\2024.10\pdfs for compare\(water_bill.pdf";
    
    var identicalCharCompareResult = testing.VerifyDocumentsEquivalence(
        firstBill, secondBill, 
        ComparisonType.Character, 
        TestingOptions.CompareDocuments()
            .WithGenerateHtml(@".\HtmlCompareResults\PDFCharCompare.html")
            .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
            .WithIgnoreRegexRule("RegexRule", @"\d{1,2}/\d{1,2}/\d{4}", true)
    );
    
    Log("pdf compare by char " + identicalCharCompareResult.AreEquivalent.ToString(),LogLevel.Error);var firstBill = @"C:\bills\2024.10\pdfs for compare\(electricity_bill.pdf";
    var secondBill = @"C:\bills\2024.10\pdfs for compare\(water_bill.pdf";
    
    var identicalCharCompareResult = testing.VerifyDocumentsEquivalence(
        firstBill, secondBill, 
        ComparisonType.Character, 
        TestingOptions.CompareDocuments()
            .WithGenerateHtml(@".\HtmlCompareResults\PDFCharCompare.html")
            .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
            .WithIgnoreRegexRule("RegexRule", @"\d{1,2}/\d{1,2}/\d{4}", true)
    );
    
    Log("pdf compare by char " + identicalCharCompareResult.AreEquivalent.ToString(),LogLevel.Error);
    
  2. Comparing PDFs by word:
    In this example, we are comparing the same PDF files as in the previous example: a light bill and a water bill. The comparison is done at the word level. The paths of these PDF files are represented by the firstBill and secondBill variables. The wildcard rule and regex rule provided along with WithIgnoreWildcardRule and WithIgnoreRegexRule methods are used to ignore specific patterns in the comparison. For instance, the wildcard rule 2022 ignore dates (assuming they are in the MM/DD/YYYY format) in the comparison, since they might differ in two separate bills and aren't relevant to the structure of the bills. The regex rule [$]\d+\.\d{2} ignores currency values, assuming they are in a format similar to $XX.XX.
    Once the comparison is done, the WithGenerateHtml method creates an HTML report of the comparison and any differences found are recorded in the logs using the method Log.
    var firstBill = @"C:\bills\2024.10\pdfs for compare\(electricity_bill.pdf";
    var secondBill = @"C:\bills\2024.10\pdfs for compare\(water_bill.pdf";
    
    var differentWordCompareResult = testing.VerifyDocumentsEquivalence(
        firstBill, secondBill, 
        ComparisonType.Word, 
        TestingOptions.CompareDocuments()
            .WithGenerateHtml(@".\HtmlCompareResults\PDFWordCompareDiff.html")
            .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
            .WithIgnoreRegexRule("RegexRule", @"[$]\d+\.\d{2}", true)
    );
    
    Log("pdf compare by Word " + differentWordCompareResult.AreEquivalent.ToString(), LogLevel.Error);var firstBill = @"C:\bills\2024.10\pdfs for compare\(electricity_bill.pdf";
    var secondBill = @"C:\bills\2024.10\pdfs for compare\(water_bill.pdf";
    
    var differentWordCompareResult = testing.VerifyDocumentsEquivalence(
        firstBill, secondBill, 
        ComparisonType.Word, 
        TestingOptions.CompareDocuments()
            .WithGenerateHtml(@".\HtmlCompareResults\PDFWordCompareDiff.html")
            .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
            .WithIgnoreRegexRule("RegexRule", @"[$]\d+\.\d{2}", true)
    );
    
    Log("pdf compare by Word " + differentWordCompareResult.AreEquivalent.ToString(), LogLevel.Error);
    
  3. Comparing PDFs by line:
    In this example, similar to the previous one, we are comparing two PDF files, a light bill and a water bill. In this scenario, the comparison is done at the line level. The paths of these PDF files are represented by the firstBill and secondBill variables. The wildcard rule and regex rule provided along with WithIgnoreWildcardRule and WithIgnoreRegexRule methods are used to ignore specific patterns in the comparison.
    For instance, the wildcard rule 2022 ignore dates (assuming they are in the MM/DD/YYYY format) in the comparison, since they might differ in two separate bills and aren't relevant to the structure of the bills. The regex rule [$]\d+\.\d{2} ignores currency values, assuming they are in a format similar to $XX.XX.
    Once the comparison is done, the WithGenerateHtml method creates an HTML report of the comparison and any differences found are recorded in the logs using the method Log.
    var firstBill = @"C:\bills\2024.10\pdfs for compare\(electricity_bill.pdf";
    var secondBill = @"C:\bills\2024.10\pdfs for compare\(water_bill.pdf";
    
    var largeLineCompareResult = testing.VerifyDocumentsEquivalence(
        firstBill, secondBill, 
        ComparisonType.Line, 
        TestingOptions.CompareDocuments()
            .WithGeneratePdf(@".\PDFCompareResults",@".\PDFCompareResults")
            .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
            .WithIgnoreRegexRule("RegexRule", @"[$]\d+\.\d{2}", true)
    );
    
    Log("Pdf compare by line " + largeLineCompareResult.AreEquivalent.ToString(), LogLevel.Error);var firstBill = @"C:\bills\2024.10\pdfs for compare\(electricity_bill.pdf";
    var secondBill = @"C:\bills\2024.10\pdfs for compare\(water_bill.pdf";
    
    var largeLineCompareResult = testing.VerifyDocumentsEquivalence(
        firstBill, secondBill, 
        ComparisonType.Line, 
        TestingOptions.CompareDocuments()
            .WithGeneratePdf(@".\PDFCompareResults",@".\PDFCompareResults")
            .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
            .WithIgnoreRegexRule("RegexRule", @"[$]\d+\.\d{2}", true)
    );
    
    Log("Pdf compare by line " + largeLineCompareResult.AreEquivalent.ToString(), LogLevel.Error);
    
In all examples, the AreEquivalent property returns whether the documents are equal or not.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.