Boolean Expressions

2.7 Boolean Expressions

Boolean expressions facilitate constructions like if/else and for. The following operators are supported:

  • Parenthesis '(' and ')'
  • Greater than '>', greater than or equal to '>=', lower than '<' and lower than or equal to '<='. These operators require numeric arguments.
  • Equal to '==' and not equal to '!=' or '<>'. If at least one of the arguments is not a number (a string enclosed in double-quotes) a plain string comparison is performed. Examples:
    • Result of 'yes == no' will be false
    • Result of 'yes != no' will be true
    • Result of '1.0 == 1' will be true because both arguments can be converted to a number and the numeric values are equal.
  • Operators '&&' and '||' - logical "and" and "or". These operators require Boolean arguments, i.e. other expressions. Example:
    • Expression '1 > 0 || yes != no' will be true because one of the two expressions is true
    • Expression '1 > 0 && yes != no' will be false because one expression is false

Version 2.2 and higher also supports a set of operators allowing to test the existence of variables and compare strings:

  • Unary operator 'exists <variableName>' tests existence of a variable. Example:
    • Expression 'exists _REPORT_FILE' will be true if the script creates a report through the Report command
  • Operator 'contains' tests whether the first string argument contains the other one (case sensitive). Example:
    • Expression '"{_MACHINE}" contains "sourceforge"'will be true if the connected VNC server name contains 'sourceforge'
  • Operator 'startswith' tests whether the first string argument starts with the other one (case sensitive). Example:
    • Expression '"{_DISPLAY}" startswith "localhost"'will be true if the connected VNC desktop name starts with 'localhost', for example, 'localhost:1'.
  • Operator 'endswith' tests whether the first string argument ends with the other one (case sensitive). Example:
    • Expression '"{_DISPLAY}" endswith ":3"'will be true if the connected VNC server runs on port 5903 (which is typically indicated by the ':3' display number in the desktop name).
  • Operator 'matches' compares the first string argument to a java.util.regex.Pattern compliant regular expression. Example:
    • Expression '"{_DATE}" matches "201008[12][1-5]"' will be true if the current date is between 11 and 15 or between 21 and 25 August 2010 .

Boolean expressions are exclusively used by the if/else and for constructions as is shown in the following example. A Boolean expression may be also passed to the Eval command which populates the specified variable with the result of 'true' or 'false'.

# Look for an image on the remote desktop
Compareto "pattern.png" method="search"

# Exit if the image is not found,
if ({_EXIT_CODE} > 0) {
    Exit 1 
}

For more information read the If/Else Statement and For Statement chapters.