Introduction - Functions Overview - Home Page
Online
There are some basic syntax features used in RoutineBot:
- Starting version 2.0 RoutineBot supports Pascal Scripts, Java
Scripts, Basic Scripts
- To change the scripting language use Scrip Language command in
Project menu
- Scripts can contain variables, there are various ways to
declare variables
- Functions and procedures declarations are possible
- External units can be included into the script
The examples below will help to understand how everything
works.
Variables
The declaration of variables in RoutineBot is similar more to
php and basic ideology, e.g. the variable can be declared anywhere
in the script.
- a:=2; // the new variable a was declared
- b:='test'; // the new variable b was declared
There are also some specific ways to declare variables, which
help in test automation:
Functions
The example below will show how to use functions in RoutineBot.
First, we need to create a basic function main. From the
main function we call previously declared function
test.
function test(a1, a2: integer;
a3: string): integer;
begin
MsgBox(a3);
result:=a1+a2;
end;
function main: integer;
begin
r1:=test(3,4, 'test');
MsgBox(r1);
end;
{
the result of script execution is the message
'test' first and then the message '7', which is the sum of passed
variables.
}
Please, note: in the same way you can pass parameters to
screen-related functions. For instance:
cancel_btn:='cancel_button.bmp';
a:=MouseFocuse(cancel_btn,100);
and it is a good place to show how to use if
operator
Using IF operator
There are pascal standard IF... else operators, here is an
example:
cancel_btn:='cancel_button.bmp'; // please, note:
there must be cancel_button.bmp image in the project
a:=MouseFocuse(cancel_btn,100);
if a=1 then MsgBox('Cancel
button image exists')
else MsgBox('The image does not
exist');
Cycles:
operators FOR and UNTIL
The for and until operators
are also available:
a:=0; // this example will count using MsgBox
from 1 to 3
for a:=1 to 3 do begin
a:=a+1;
MsgBox(a);
end;
using until operator is a good idea to wait for
some image to appear.
For instance, when it is necessary to check the list of some
items, script can move mouse to the first element of the list and
then use keyboard to move and MouseFocuse function to check if
necessary item exists in the list. The function below will show how
to manage this with RoutineBot:
function af_category_selection: integer;
begin
MouseFocuse('category_label.bmp',10000); // moving the mouse
to the category label, this might be "The list of possible
categories:"
MouseMoveRel(9,20); // Actually we don't need category label, but
we need the list of available categories, so we move the mouse to
this list
MouseClick; // Click once to focus on the list
EnterKeys('{UP 100}'); // Emulate the big number (100) of UP key
(arrow up on the keyboard) to make sure we are in the beginning of
the list
repeat
EnterKeys('{Down 10}'); // now we are in the drop list and press
DOWN ARROW 10 times to move a little down
// depending on the category we are looking for
we check the necessary image for existance
if article_category='management'
then
cat:=MouseFocuse('business-category.bmp',100);
if article_category='software'
then
cat:=MouseFocuse('software-category.bmp',100);
until cat=1;
// if the category was found we click on it
mouseclick;
ff:=1;
Result := ff;
end;
Uses command to include stand alone
unit
|