| Cogitek RIATest 3 Documentation | Copyright © Cogitek Inc. |
To check a condition in RIATest use the if statement in one of two ways:
if (condition) statement1; if (condition) statement1 else statement2;
The if statement will check the condition and if true will execute the statement following then. Otherwise if the else part is present the second statement will be executed. For example the following code will check to see if the button is enabled and will click it:
if (myButton=>enabled) myButton=>click();
To perform repetitive actions use one of the loop statements: while, for, do.
The while statement has the following syntax:
while (condition) statement;
For example the following code will keep clicking the button until it becomes disabled:
while (myButton=>enabled) myButton=>click();
Beware that this code will run indefinitely if the button is never disabled as a result of a click action !
The for statement has the following syntax:
for (init_expr;cond_expr;iter_expr) statement;
The init_expr is executed in the beginning and then the statement is executed until cond_expr becomes false. After each execution of statement the iter_expr is executed.
The following code repeats clicks on a button 10 times:
for (var x=1; x<=10; x++) myButton=>click();
The do statement has the following syntax:
do statement while (condition);
This is similar to the while statement except that the statement is executed at least once even if the condition is initially false.
do
{
myButton=>click();
trace("clicked");
} while (myButton=>enabled);
Note the usage of block parenthesis {} to group multiple statements.
return statement is used to return a value from a function. The syntax is the following:
return [expression];
If expression is omitted the result of the function is null.
See also Functions.
The switch statement has the following syntax:
switch (expression)
{
case value1: statement1; [break;]
case value2: statement2; [break;]
...
[default: def_statement; [break]]
[case valueafter1: statementafter1; [break;] ]
[case valueafter2: statementafter2; [break;] ]
...
}
The switch statement evaluates the value of the expression and tries matching it against one of the specified values. If a match is found, the corresponding statement is executed otherwise the statement for the default label is executed (if the default label is missing then switch statement execution is interrupted). If a matching case is found, execution of the case statements continues from top to bottom until a break statement or end of switch statement is encountered.
The include statement has the following syntax:
include file-name;
The include statement temporarily suspends execution of the current script file, locates the specified file, loads its content and executes it. After execution of the included file is finished execution returns to the current script file and continues from the statement following the include statement. Global variables and functions declared in the included script file are visible to the current script (and indistinguishable from variables and functions declared in the current script).
The include statement is typically used for writing common functions in a separate include file and then including it from several script files.
The try/catch statements have the following syntax:
try try_statement; catch (e) catch_statement;
The try/catch statement will attempt to execute the try_statement. If an exception occurs during execution it will be caught and the catch_statement will be executed. Variable e will contain exception information. An exception can be thrown when an error occurs during execution of built-in functions or you can throw it manually using a throw statement:
throw expression;
The throw statement will generate an exception. It will be caught by the most nested catch statement that surrounds the throw statement. If there is no such catch statement the exception will terminate execution of the current script.
The try/finally statements have the following syntax:
try try_statement; finally finally_statement;
The try/finally statement will attempt to execute the try_statement. After the try_statement is executed or if an exception occurs during execution the exception will be caught and the finally_statement will be executed in either case.