Forum Discussion

Deef's avatar
Deef
Occasional Contributor
6 months ago
Solved

How to compare local variables with a reusable script in TestComplete?

I have created the following script that compares the contents of two project variables. Which two variables exactly can be defined through the parameters param1 and param2. This function can be call...
  • rraghvani's avatar
    6 months ago

    Keep your function as simple as possible. Here's a better approach,

    function CompareVars(var1, var2)
    {
        // equal value and equal type
        if (var1 === var2) {
            Log.Message("Match!");
            return true;
        } else {
            Log.Message("Do not match!");
            return false;
        }
    }
    
    function main()
    {
        CompareVars(Project.Variables.param1, Project.Variables.param2);
        
        CompareVars(Project.Variables.VariableByName("param1"), Project.Variables.VariableByName("param2"));
        
        var str1 = "Hello"
        var str2 = "Hello"
        CompareVars(str1, str2);
        
        var int1 = 10
        var int2 = 11
        CompareVars(int1, int2);    
    }

    The function just compares two variables (and the type), and that's it. You just pass in the appropriate two parameters, and results will be shown as