activities
latest
false
重要 :
请注意此内容已使用机器翻译进行了部分本地化。
工作流活动
Last updated 2024年10月22日

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.

定义

命名空间: UiPath.Testing.API

程序集: UiPath.Testing.Activities.Api(在 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 字符串
The path of the base document that is used as a reference for comparison.
targetPath 字符串
The path of the document that is compared against the base document.
comparisonType ComparisonType (可选)
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.

返回值

ComparisonResult

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

示例

  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.

此页面有帮助吗?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath Logo White
信任与安全
© 2005-2024 UiPath。保留所有权利。