activities
latest
false
UiPath logo, featuring letters U and I in white
Workflow Activities
Last updated Nov 18, 2024

VerifyTextEquivalence

Verifies if two texts are equivalent, using multiple comparison options, including the following comparison types:
  • Comparing words.
  • Comparing lines.
  • Comparing characters as char variables.

VerifyTextEquivalence(string, string, ComparisonType, ComparisonOptions)

VerifyTextEquivalence(
    string baselineText,
    string targetText,
    [ComparisonType comparisonType],
    [ComparisonOptions opts]
)VerifyTextEquivalence(
    string baselineText,
    string targetText,
    [ComparisonType comparisonType],
    [ComparisonOptions opts]
)
baselineText String
The base text that is used as a reference for comparison.
targetText String
The text that is compared against the base text.
comparisonType ComparisonType (Optional)
The type of comparison to use when comparing texts. The following options are available:
  • ComparisonType.Char: Compares every character (char) in the texts.
  • ComparisonType.Line: Compares every line in the texts.
  • ComparisonType.Word: Compares every word in the texts.
opts CompareDocumentsOptions
The specific comparison options that should be used for this operation. To create an object of type CompareDocumentsOptions, use the TestingOptions.CompareText Class.

Return value

ComparisonResult

The result of the comparison action, stored within a ComparisonResult variable. You can call the AreEquivalent or Differences properties on the ComparisonResult to display if they are equivalent, and if not, to display the differences.

Examples

Check the following examples for using the VerifyTextEquivalence API:
  1. Comparing text by character:
    In this example, we are comparing two string variables, initialText and modifiedText. The comparison is done at the character level. 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 R?d and the regex rule (f|F)ox allow us to ignore certain words that are present in the variables, such as Red, and Fox. In this scenario, the usePlaceholder parameter was set to false, because we do not want to have a placeholder name for the ignored patterns.
    The WithGenerateHtml method outputs an HTML report highlighting the differences.
    var initialText = "Red fox jumps over the lazy fox";
    var modifiedText = "Blue fox leaps over the lazy dog";
    
    var charCompareResult = testing.VerifyTextEquivalence(
        initialText, modifiedText, 
        ComparisonType.Character, 
        TestingOptions.CompareText()
            .WithGenerateHtml(@".\HtmlCompareResults\CharacterTextCompare.html")
            .WithIgnoreWildcardRule("WildcardRule", "R?d", false)
            .WithIgnoreRegexRule("RegexRule", @"(f|F)ox", false)
    );
    
    // Log any differences
    foreach (var diff in charCompareResult.Differences)
    {
        Log(diff.Operation.ToString());
        Console.WriteLine(diff.Text);
        Console.WriteLine("------------------------------------------------------------------------------");
    }var initialText = "Red fox jumps over the lazy fox";
    var modifiedText = "Blue fox leaps over the lazy dog";
    
    var charCompareResult = testing.VerifyTextEquivalence(
        initialText, modifiedText, 
        ComparisonType.Character, 
        TestingOptions.CompareText()
            .WithGenerateHtml(@".\HtmlCompareResults\CharacterTextCompare.html")
            .WithIgnoreWildcardRule("WildcardRule", "R?d", false)
            .WithIgnoreRegexRule("RegexRule", @"(f|F)ox", false)
    );
    
    // Log any differences
    foreach (var diff in charCompareResult.Differences)
    {
        Log(diff.Operation.ToString());
        Console.WriteLine(diff.Text);
        Console.WriteLine("------------------------------------------------------------------------------");
    }
    
  2. Comparing text by line:
    In this example, we are comparing two string variables, initialText and modifiedText. The comparison is done at the line level. 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 R?d and the regex rule (f|F)ox allow us to ignore certain words that are present in the variables, such as Red, and Fox. In this scenario, the usePlaceholder parameter was set to true, because we want to have a placeholder name for the ignored patterns.
    The WithGenerateHtml method outputs an HTML report highlighting the differences.
    var initialText = @"Red fox jumps over the lazy fox";
    var modifiedText = @"Blue fox leaps over the lazy dog";
    
    var lineCompareResult = testing.VerifyTextEquivalence(
        initialText, modifiedText, 
        ComparisonType.Line, 
        TestingOptions.CompareText()
            .WithGenerateHtml(@".\HtmlCompareResults\LineTextCompare.html")
            .WithIgnoreWildcardRule("WildcardRule", "R?d", true)
            .WithIgnoreRegexRule("RegexRule", @"(f|F)ox", true)
    );
    
    // Log any differences
    foreach (var diff in lineCompareResult.Differences)
    {
        Log(diff.Operation.ToString());
        Console.WriteLine(diff.Text);
        Console.WriteLine("------------------------------------------------------------------------------");
    }var initialText = @"Red fox jumps over the lazy fox";
    var modifiedText = @"Blue fox leaps over the lazy dog";
    
    var lineCompareResult = testing.VerifyTextEquivalence(
        initialText, modifiedText, 
        ComparisonType.Line, 
        TestingOptions.CompareText()
            .WithGenerateHtml(@".\HtmlCompareResults\LineTextCompare.html")
            .WithIgnoreWildcardRule("WildcardRule", "R?d", true)
            .WithIgnoreRegexRule("RegexRule", @"(f|F)ox", true)
    );
    
    // Log any differences
    foreach (var diff in lineCompareResult.Differences)
    {
        Log(diff.Operation.ToString());
        Console.WriteLine(diff.Text);
        Console.WriteLine("------------------------------------------------------------------------------");
    }
    
  3. Comparing text by word:
    In this example, similar to the previous one, we are comparing two string variables: initialText and modifiedText. The comparison is done at the word level. 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 R?d and the regex rule (f|F)ox allow us to ignore certain words that are present in the variables, such as Red, and Fox.
    The WithGenerateHtml method outputs an HTML report highlighting the differences.
    var initialText = "Red fox jumps over the lazy fox";
    var modifiedText = "Blue fox leaps over the lazy dog";
    
    var wordCompareResult = testing.VerifyTextEquivalence(
        initialText, modifiedText, 
        ComparisonType.Word, 
        TestingOptions.CompareText()
            .WithGenerateHtml(@".\HtmlCompareResults\LineWordCompare.html")
            .WithIgnoreWildcardRule("WildcardRule", "R?d", false)
            .WithIgnoreRegexRule("RegexRule", @"(f|F)ox", true)
    );
    
    // Log any differences
    foreach (var diff in wordCompareResult.Differences)
    {
        Log(diff.Operation.ToString());
        Console.WriteLine(diff.Text);
        Console.WriteLine("------------------------------------------------------------------------------");
    }var initialText = "Red fox jumps over the lazy fox";
    var modifiedText = "Blue fox leaps over the lazy dog";
    
    var wordCompareResult = testing.VerifyTextEquivalence(
        initialText, modifiedText, 
        ComparisonType.Word, 
        TestingOptions.CompareText()
            .WithGenerateHtml(@".\HtmlCompareResults\LineWordCompare.html")
            .WithIgnoreWildcardRule("WildcardRule", "R?d", false)
            .WithIgnoreRegexRule("RegexRule", @"(f|F)ox", true)
    );
    
    // Log any differences
    foreach (var diff in wordCompareResult.Differences)
    {
        Log(diff.Operation.ToString());
        Console.WriteLine(diff.Text);
        Console.WriteLine("------------------------------------------------------------------------------");
    }
    
The returned result from VerifyTextEquivalence includes a Differences property, which you can use to print out the differences between texts.

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.