Generating Comparison and Logical Expressions

Applies to TestComplete 14.60, last modified on April 22, 2021

Custom actions created with script extensions can generate code that compares two expressions or performs a logical operation over them. To generate such an expression, do the following:

  • Create syntax elements corresponding to the expressions to be placed on the left and right sides of the operator.

  • Create a ConditionSyntax object using the Syntax.CreateCondition object.

  • Use the OperatorType property of the created ConditionSyntax object to specify the comparison or logical operator to be used in the expression: >, <, >=, logical AND, and so on.

  • Use the Left and Right properties of the ConditionSyntax object to specify the operands.

    Note: In the logical NOT operation, only the Right operand is required.

After you have configured the ConditionSyntax object, you can pass it to the Syntax.GenerateSource method to get the actual script code of the comparison or logical expression.

The following example demonstrates how to generate script code that checks whether the value of the variable x is greater than y.

JScript

function ShowConditionStatement()
{
    var oXName = Syntax.CreateInvoke();
    oXName.InvokeName = "x";
    oXName.IsProperty = true;

    var oYName = Syntax.CreateInvoke();
    oYName.InvokeName = "y";
    oYName.IsProperty = true;

    var oCondition = Syntax.CreateCondition();
    oCondition.OperatorType = oCondition.otGreater;
    oCondition.Left = oXName;
    oCondition.Right = oYName;

    var strCode = Syntax.GenerateSource(oCondition);
    aqDlg.ShowMessage(strCode);
}

VBScript

Sub ShowConditionStatement
    Dim oXName, oYName, oCondition, strCode

    Set oXName = Syntax.CreateInvoke
    oXName.InvokeName = "x"
    oXName.IsProperty = True

    Set oYName = Syntax.CreateInvoke
    oYName.InvokeName = "y"
    oYName.IsProperty = True

    Set oCondition = Syntax.CreateCondition
    oCondition.OperatorType = oCondition.otGreater
    oCondition.Left = oXName
    oCondition.Right = oYName

    strCode = Syntax.GenerateSource(oCondition)
    aqDlg.ShowMessage strCode
End Sub

The generated code is as follows:

JavaScript, JScript

x > y

Python

x > y

VBScript

x > y

DelphiScript

x > y

C++Script, C#Script

x > y

See Also

Generating Script Code
Generating Conditional Statements
ConditionSyntax Object
CreateCondition Method

Highlight search results