![]() |
T-Plan Robot Enterprise
2.1 Doc
Collection |
20/04/10 |
This document provides a complete specification of the proprietary
test script language supported by T-Plan Robot Enterprise version 2.1.
Its goal is
to provide a complete syntax and
functionality reference to those who write automated test scripts using
this tool and its testing framework. As the scripting language is
tightly coupled with the Java Test Script API, it is
also intended to provide a complementary functionality reference for
design of Java test scripts.
The document is based on specification of its predecessor VNCRobot
1.3, with which it maintains backward compatibility, and describes test
script requirements, parsing and processing rules, language structure
and syntax of particular elements, such as statements, expressions and
commands.
T-Plan Robot Enterprise supports a proprietary
scripting language allowing to write automated test scripts. It is a
structured procedural language somewhat similar to shell scripting on
Linux/Unix. It supports structures and elements well known from moder
programming languages, such as:
As T-Plan Robot Enterprise is designed to work with
most common remote and local desktop technologies, the scripting
language supports commands fall into roughly four functionality
areas:
# This is a
commentgoto command supported by
other programming languages). See the --fromlabel
and --tolabel T-Plan Robot Enterprise
CLI options for more label info.identificator=value' or 'identificator="value with
spaces"' are considered to be one single token and they are
further parsed into identificator/value pairs. This is a text containing spaces
This',
'is', 'a', 'text', 'containing',
'spaces'.This "is a text" containing
spaces
This',
'is a text', 'containing',
'spaces'.This text contains "double quote (\")"This',
'text', 'contains', 'double quote (")'Variable SAMPLE_VAR_1="value with spaces" SAMPLE_VAR_2=no_spaces
"NO_VAR=not_a_variable"
Variable','SAMPLE_VAR_1="value
with spaces"', 'SAMPLE_VAR_2=no_spaces' and 'NO_VAR=not_a_variable'.The
second and third tokens will be further parsed into identificator/value
pairs. The fourth token will not be parsed as it does not comply with
the required format. wait/timeout/delay
parameters of other commands support the following syntax:"1" is parsed as 1 milisecond,"1s" is 1 second,"1m" is 1 minute,"1h" is 1 hour,"1d" is one day.'3.5h' will be parsed as 3.5 hrs (3 hrs 30 mins).
Time values may contain numeric expressions - check the Numeric Expressions chapter for syntax. Wait
"1.5d"
Press
Ctrl+C wait=5s Var/Eval commands themselves).
T-Plan Robot Enterprise's text preprocessor will replace all occurencies of {<var_name>}
with the <var_name>
variable value before parsing of each command line. A typical example:
Var PATH=/tmp Typeline
"mkdir -p {PATH}; cd {PATH}"
Avoid variable names consisting of plain
numbers, e.g. 'Var
1="test"'. These variables are reserved for procedure parameters and
they will be rewritten by any procedure execution without any warning.
If a variable is not
defined, no replacement is performed. The following example will rather
type 'cd {PATH}' than 'cd /tmp' because the
variable definition is commented out:
# Var PATH=/tmp Typeline
"cd {PATH}"
_SEARCH_X_<number> and it is necessary to generate
the variable
names dynamically in a loop. The following example illustrates such a
usage. Let's suppose that you are to search the remote desktop for an
icon and you click onto each of the occurencies:
Compareto
"search.png" method="search" for
(i=1; {i}<{_SEARCH_MATCH_COUNT}+1; i={i}+1) { #
Nested variables compose the variable name from a suffix and an index Mouse
click to=x:{_SEARCH_X_{i}},y:{_SEARCH_Y_{i}} } procedure,
if/else
and for statements) are considered to be local and they are available only
within the block of code (including any nested blocks it may contain). Var or Eval command in a block of
code and the variable name matches an
already existing global variable, you'll rather modify the global
variable than define a local one with the same name. The following
example demonstrates the principles. # Create a global variable
Var
GLOBAL=global
if (1 == 1) {
#
Create a local variable and change the value of GLOBAL to 'modified'
Var
LOCAL=local GLOBAL=modified
if (1 > 0) {
Var
LOCAL2=local2
#
Here GLOBAL, LOCAL and LOCAL2 are available.
#
The command will type "GLOBAL=modified, LOCAL=local, LOCAL2=local2"
Type
"GLOBAL={GLOBAL},
LOCAL={LOCAL}, LOCAL2={LOCAL2}"
}
#
Here GLOBAL and LOCAL are available and LOCAL2 doesn't exist any more.
#
The command will type "GLOBAL=modified, LOCAL=local, LOCAL2={LOCAL2}"
Type
"GLOBAL={GLOBAL},
LOCAL={LOCAL}, LOCAL2={LOCAL2}"
}
# Here
GLOBAL is available and LOCAL and LOCAL2 don't exist any more.
# The
command will type "GLOBAL=modified, LOCAL={LOCAL}, LOCAL2={LOCAL2}"
Type
"GLOBAL={GLOBAL},
LOCAL={LOCAL}, LOCAL2={LOCAL2}"
-v/--variable parameter specified in the T-Plan Robot Enterprise 2.1 CLI Options
document. This allows to parametrize particular test script executions
and/or avoid exposure of sensitive information (passwords, ...) in the
test script code. Redefinition of a variable from CLI makes
the variable 'read only' and fixes its value for the whole time of
script execution. Any Var/Eval commands modifying this
variable executed in the
script will be ignored and they will have no impact on the variable
value. This applies to any variable including the explicit (predefined)
ones. procedure
<procedure_name> {
command1command2...commandN }'{' must be on the same line as the
procedure header. The terminating right curly brace '}'
must be alone on a single line. Procedure names are not case sensitive
and they must not conflict with any other command or language element
name. A procedure definition overrides any eventual already defined
procedure of the same name.
Procedure can be called anywhere in the script AFTER its definition.
Procedures defined in another test script (file) may be imported
through the Include command.<procedure_name>
parameter1
"parameter2 with spaces" .... parameterN
# Procedure definition.
Expected parameters are:
# {1} ...
file name without extension
# {2} ...
image extension (either jpg, jpeg or png). Defaults to "png" when
omitted.
procedure take_screenshot {
Var
extension={2}
if ({_PROCEDURE_ARG_COUNT} == 1) {
Var
extension=png
}
Screenshot
{1}.{extension} desc="This
screenshot was
created by procedure called {0}"
}
take_screenshot image1 jpg
take_screenshot image2 scope
parameter set to procedure. An example follows:
# Procedure definition procedure
exit2 {
Exit
2 scope=procedure } # Procedure call exit2 if
({_EXIT_CODE} == 2) { #
Any code here will be executed because exit2 returns 2 }
take_screenshot image3 tiff'1.25'.'5s' (five seconds) are not
accepted except the cases where the time modifier is at the very end of
the expression. Examples: Wait
5+5s
Wait 5s+5s '(' and ')''+''-''-' (negative numbers)'*''/' # Wait 1 hour -
in miliseconds
Wait
"1*60*60*1000"
# Search
for an image and then click onto it 10 points from its left upper corner
Compareto
"pattern.png" method="search"
Mouse
click to="x:{_SEARCH_X}+10,y:{_SEARCH_Y}+10"
'Eval
HOUR_IN_MS=1*60*60*1000'.if/else
and for. The following operators are supported:
'(' and ')''>' and lower than '<'.
These two operators require numeric arguments.'==' and not equal to '!='.
Arguments are first converted to numbers and compared. If at least one
of the argument is not a number, a plain string comparison is
performed.
Examples:'yes == no' will be false'yes != no' will be true'1.0 == 1' will be true because both
arguments can be converted to a number and the numeric values are equal.'&&' and '||' -
logical "and" and "or". These operators require boolean arguments, i.e.
other expressions. Example:'1 > 0 || yes != no' will be true
because one of the two expressions is true'1 > 0 && yes != no' will
be
false because one expression is falseif/else
and for constructions, for example
# 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
} if/else statements with a
similar
functionality and syntax used by Java. The format
is:if (<boolean
expression>) { <commands> } else if (<boolean
expression>)
{ <commands> } else { <commands> }'else if' and 'else' branches are
optional. While the number of 'else if' branches is not
limited, there can be just one 'else' construction.
Note that the enclosing curly braces '{' and '}'
must be on the same line as their associated if/else/else if
keyword exactly as is displayed above. The right curly brace '}'
terminating the whole structured block is the only exception and it
must be alone on a single line. # 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
# If the image was found more
times, take a screenshot and add a warning to the HTML report } else if
({_SEARCH_MATCH_COUNT} > 1) { Screenshot
unexpected.png
Warning
"Unexpected behavior -
the template image was found
{_SEARCH_MATCH_COUNT} times!" image=unexpected.png }
If/else statements can be nested and combined with other
constructions like the for statement as is usual in any
other structured programming language.for statements which allows to
iterate over a range of values or loop until a particular condition is
satisfied. There are two general forms of the for
statement. for statement allows to execute
until
a boolean expression results true:for
(<statement1>;
<boolean expression>; <statement2>) { <commands> }statement1 and statement2 are
evaluated using the Eval command and should have a
syntax like '<variable>=<numeric expression>'.
They can be also empty. The following examples are equivalent and loop
for values of variable 'index' ranging from 0 to 5. Both
code snippets will type '012345':for (index=0;
{index}<6; index={index}+1) { Type
{index}
} Eval index=0 for ( ; {index} < 6; ) { Type
{index}
Eval
index={index}+1 }
2.
For
Statement Iterating over a Predefined Set of Valuesfor
<variable name> in
<list of space separated values> { <commands> } Type
"I speak "
for language in English Spanish "Brazilian Portuguese" {
if ("{language}" == "Brazilian
Portuguese") {
Type
"{language}."
} else {
Type
"{language}, "
}
}for statement can be interrupted by a break
command. If there are nested loops, the break command
will
always interrupt the innermost for statement. The
following
example illustrates how to use a combination of for and Waitfor to hold on execution until
the
remote desktop stops to update. # Infinite loop
for (; 0 == 0; ) {
#
Wait for at least 20% update of the remote screen.
#
If it doesn't update for 10 seconds, break the loop.
Waitfor
update extent=20%
timeout="10s"
ontimeout="break"
}
_EXIT_CODE. Value of 0 (zero)
usually means
success
while any other number indicates a failure. See documentation of
particular commands for defined exit code values and their meanings.Compareto command e.g. returns 0
when image
comparison passes and non-zero value otherwise. The Waitfor
command
returns 0 when the expected event is received and non-zero value when
timeout is reached. The following example illustrates how to use these
return values. # Alt+F2 opens the Run Program
window on Gnome
Press
Alt+F2 wait=3s
# Start
the Gnome Text Editor
Typeline
gnome-text-editor
# Wait for
the remote desktop update
Waitfor
update extent=30%
timeout="10s"
# If
Waitfor returns non-zero value, the timeout was reached
# and the
text editor probably failed to open
if ({_EXIT_CODE} > 0) {
#
Take a screenshot
Screenshot
failure.png
#
Send the screenshot via E-mail to the tester
Sendmail
to="tester@dummyserver.com" from="robot@dummyserver.com"
server="mail.dummyserver.com" subject="Gnome
editor failed to open!" attach="{_REPORT_DIR}/failure.png"
#
Pause the execution and wait for the tester to fix it
Pause
"Paused because Gnome
Text Editor failed to start"
}
if/else, for and break
calls do not return any value. If you access the _EXIT_CODE
variable after one of these commands, it will rather contain exit code
of the last previously executed command."java -classpath <libs>
com.tplan.robot.ApplicationSupport" command rather than the "java
-jar robot.jar" one. The latter syntax fails to populate the
class path for the Java compiler on some environments which results in
failures to compile and execute Java source code. See the Startup chapter of the
Release Notes document for more information. java {
<Java code>
} endjava| Java Code Block |
Resulting Java Test
Script Class |
|
java { |
|
import com.tplan.robot.scripting.*; |
Var _TEMPLATE_DIR="C:\templates"
# This line declares
dummy values of variables populated by the Java code.
# It
prevents the compiler from reporting error in the for() loop and
CompareTo command.
Var
FILECNT=0 FILE1=dummy.png
java {
File
files[] = getContext().getTemplateDir().listFiles();
int i = 0;
for
(File file : files) {
if
(file.isFile() && file.getName().endsWith(".png")) {
i++;
getContext().setVariable("FILE"+i,
file.getName());
}
}
getContext().setVariable("FILECNT",
Integer.toString(i));
} endjava
for (i=1; {i}<{FILECNT}+1; i={i}+1) {
Compareto
"{FILE{i}}" method=search
}
OPTIONS
URL
- The argument must
be a valid URL in form of <protocol>://<host_or_IP>[:<port>]
except the legacy format described below. The protocol must be equal to
one of the supported protocol codes. T-Plan Robot by default
supports RFB v3.3 (better known as VNC, code "rfb"). The Enterprise
version also supports a Java native client ("java") allowing to access
either a local display directly or a remote one over RMI. As T-Plan
Robot provides an interface allowing to plug in other clients, there
might be more protocols supported by additional plugins.
If port is not
explicitly specified, it defaults to the protocol-specific well known port.
For example, RFB/VNC server runs by default on port 5900, Java RMI
starts by on port 1099 and RDP (Windows Terminal Services)
default to 3389. If you want to connect to a VNC running on Linux/Unix,
you typically have to specify the port of 5901 or higher because the
default RFB port is occupied by the X-Windows server.
Be aware that URL
interpretation may be client specific.
For example, "java://localhost" makes the Java native
client to attach directly to the local system screen buffer and there's
no TCP/IP communication involved. Any other "java" URL will however
connect over TCP/IP to an RMI registry running on the specified host
and port in order to attach to screen buffer of the host machine. Refer
to documentation of particular clients for more information.
If protocol is omitted in the URL, the
host defaults to the RFB (VNC) protocol to provide backward compatibility with VNCRobot 1.x.
Port number is in this case considered to be a display number rather
than real port. To get the port number add the display number to 5900.
Direct port can be in this mode specified through double colon, for
example both "localhost:1" and "localhost::5901"
refer to the same local VNC server running on port 5901. To specify the
same address in the standard URL form one has to list the real port
specifically and the equivalent URL is "rfb://localhost:5901".
The connect method supports by default
just servers with either none or a plain user/password authentication.
Clients requiring custom authentication schemes may take advantage of
the params and paramseparator options to
pass the necessary logon data. Parameters and their expected values
must be specified by the client.
user=<username>
password=<password>
params=<param_name_and_value_pairs>
paramseparator argument. For example, to specify two
parameters PARAM_A=value_A and PARAM_B=value_B
the argument should look like "PARAM_A,value_A,PARAM_B,value_B".
paramseparator=<delimeter>
params
argument. If it is not specified, it defaults to comma (",").
force=<false|true>
onpass=<command>
onfail=<command>
RETURNS
The command returns 0 (zero) on success or 1 when it fails to
connect for unspecified reason. The command returns a value of 10 when
connection fails on an unsupported authentication method.
EXAMPLES
Connect
rfb://localhost:5901 password=test
Connect
localhost:1 password=test
Connect
localhost::5901 password=test
- All three
examples are equal and connect to a VNC
server running on display number 1 (port 5901) of the local machine.
Password authentication is expected. This is typical for Linux/Unix
systems
where port 5900 is usually occupied by X-Windows server and VNC servers
usually runs on ports 5901 and higher.
Connect
rfb://mywindows.companyxy.com:5902 password=mypassword
force=true onfail="exit 2"
- Connect to an RFB
(VNC)
server running on server called mywindows.companyxy.com.
If the tool is already connected to this server, terminate the session
and reconnect. If connection fails, terminate execution of the script
with an exit code of 2.
Connect
java://localhost
- Connect to the local system display buffer directly using Java native client (Enterprise version only). This is just an illustrative example because Java client support has not yet been released.
Connect
java://testmachine:1099
- Connect to
display buffer of host called testmachine over RMI using
Java native client (Enterprise version only). The machine must run the
Java RMI registry on port 1099 as is specified in the Java client
documentation. This is just an illustrative example because Java client
support has
not yet been released.
Connect rdp://winhost
- Connect to host winhost
using RDP. This is just an illustrative example because RDP support is
not yet implemented.
RETURNS
The command returns 0 (zero) on success or 1 when it fails to
disconnect.
EXAMPLES
Disconnect
- Disconnect from
the currently connected desktop.
SYNOPSIS
press [<modifier_1>+...+<modifier_N>+]<key | modifier> [location=<standard|numpad|left|right>]
[count=<number>]
[wait=<time>]
OPTIONS
modifier
key
Key names are internally derived from the VK_ key code
constants declared in the java.awt.event.KeyEvent class
where the identifier itself is the string after the VK_
prefix. For example, as there is a VK_ENTER constant, the
key name may be "ENTER", "Enter" or "enter". As the names are in fact
extracted from the KeyEvent class at runtime using Java
Reflection API, the range of supported keys may differ depending on the
version of Java used to execute T-Plan Robot. A complete map of the
supported key names may be obtained through the Supported Keys Window.
Be aware that the names map rather to particular physical keys and
not to the characters they represent. For example, pressing of the
standard '-' minus key generates a different internal key code than the
one on numpad. These two cases may be also represented by two Press
commands, "Press -"
(standard) and "Press SUBTRACT
location=numpad" (numpad). In most cases the target system
interprets them in the same way but there may be situations when it
fails. For example, control plus ("Press
Ctrl++") is generated as a sequence of [press Ctrl, press '+',
release '+', release Ctrl]. As such a key combination is impossible to
create on a US keyboard where one needs to press Shift as well to get
the standard '+' ASCII character (0x2b), this sequence may or may not
be interpreted correctly by the desktop. If the key is not recognized
try using the numpad one instead ("Press
Ctrl+ADD location=numpad"). To get the key name for your
particular numpad key open the Supported
Keys Window and press it while the focus is on the "Press a key.." text field. It is
recommended to specify the location=numpad
parameter though it may also work without it.
The command accepts besides key names also most plain ASCII
characters since 2.0.3. It is possible to use commands like "Press * " or "Press @". In addition it supports
mapping of these characters onto the numeric keyboard through the localion="numpad" parameter. For
example, pressing of the "0" key on the numeric keypad required to call
"Press NUMPAD0" while the new
version also supports more intuitive "Press
0 location=numpad". This also applies to other numpad keys such
as ADD (mapped to plus, '+'), SUBTRACT (minus, '-'), MULTIPLY
(asterisk, '*' ), DIVIDE (slash, '/'), DECIMAL (period, '.') and
SEPARATOR (comma ',' ).
location=<standard|numpad|left|right>
- Key location.
This option makes sense only with keys which are present on a typical
keyboard more than once. Examples of such keys are the digit keys
'0'-'9' (standard location and num pad) or modifier keys (Ctrl and Alt
on the keyboard left and right). Supported location values are standard
(default), numpad, left and right.
Note that the
command doesn't verify whether the [key,location] pair makes sense. For
example, alphabet characters are present on most keyboard just once and
the only logically valid location is the default standard
one. Most clients however use the location only as a hint and ignore it
by keys where it is not applicable.
count=<number>
- How many times the key should be sent. Default value is 1. Delays among multiple press actions are defined by a value in the Press Command user preferences.
wait=<time>
- Time to wait
after the events are sent. It has the same effect as if the following
command was 'Wait <time_in_ms>'. This parameter is
useful if the server needs some time to react on the pressed key/keys.
A
plain number is by default parsed as miliseconds. See the syntax of time values paragraph for more time
formats.
RETURNS
The command returns 0 (zero) on success or 1 when it fails.
EXAMPLES
Press
Ctrl+Alt+Del
- Press the Ctrl+Alt+Del key on the desktop.
Press
Tab count=5 wait=2s
- Simulate pressing of the Tab key five times and then wait for two seconds before proceeding to the next command.
Press
Ctrl location=right
- Press the right Ctrl key.
Var KEY_TO_PRESS=Alt+F4
<...>
Waitfor
update area=x:340,y:220,w:240,h:160 extent=80%
timeout=10s ontimeout="Var KEY_TO_PRESS=Right"
Press
{KEY_TO_PRESS} wait=2s
- This example illustrates how to solve
the unwanted popup windows. If a window pops up at the given
coordinates, the 'Press {KEY_TO_PRESS}' command ensures
that it gets closed using Alt+F4. If the window doesn't show up, the
Alt
key gets pressed which usually doesn't cause any harm to the window.
Type <text>'
and 'Press Enter'. SYNOPSIS
type <text>
[wait=<time>] [count=<number>]
typeline <text>
[wait=<time>] [count=<number>]
* Red color indicates obligatory
parameters
OPTIONS
text
- Text to type. If
the text contains spaces or equal signs '=', it must be enclosed in
double quotes, e.g. "This is a text containing spaces". If you need to
include the double quote character into your text, place a leading
backslash before it, e.g. "This is double quote - \"". If you need to
display a backslash followed by a double quote, use '\\"', e.g. "This
is
a backslash followed by a double quote - \\"".
Supported text characters are subject to
limitations applied by the desktop client (protocol). For example the
RFB (VNC) protocol cannot transfer characters outside of the Latin-1
(ISO 8859-1) character set. On contrary the native Java client can
transfer only characters which can be generated on the local keyboard
regardless of the character set they belong to. Read the particular
client documentation for more information.
wait=<time>
- Time to wait
after the text gets typed. It has the same effect as if the following
command was 'Wait <time_in_ms>'. This parameter is
useful if the server needs some time to react on the pressed key/keys.
A
plain number is by default parsed as miliseconds. See the syntax of time values paragraph for
more time formats.
location=<standard|numpad|left|right>
- Key location.
When specified the command makes an attempt to map the typed characters
onto the specififed keyboard location.
Though supported location values are standard
(default), numpad, left and right,
this
option makes sense only with the numeric pad which is the only keyboard
part containing characters accepted by the command.
Support of this parameter is intended to make testing of mobile devices easier. Numeric keys on mobile devices (especially mobile phones) are often mapped to numpad keys and it is inconvenient to handle each key press through the Press command. For example, to type and call a phone number +0123456789 on the mobile one can simply use "Typeline +0123456789 location=numpad" .
count=<number>
- How many times the command should be repeated. Default value is 1.
RETURNS
The command returns 0 (zero) on success or 1 when it fails.
EXAMPLES
Type
hello
- Type 'hello'.
Typeline
"mkdir /tmp/mydir" wait=2s
- If you run this
in an active Linux/Unix terminal window, it will invoke the 'mkdir
/tmp/mydir' OS command and wait for
two seconds before
proceeding to the next command.
Type "100*4" location=numpad
- Type the formula on the numeric keyboard.
Typeline
"+111222333444" location=numpad
- Type the formula
on the numeric keyboard and press Enter. When the system under test is
a mobile device with keyboard mapped onto the num pad such as a Nokia
phone with Symbian OS, it will place a call to the specified number.
SYNOPSIS
mouse [<modifier_1>+...+<modifier_N>+]<event_id> [btn=<button_name>]
[modifiers=<modifier_1>+...+<modifier_N>]
[to=[x:<x>][,y:<y>]] [from=[x:<x>][,y:<y>]]
[count=<number>] [wait=<time>]
* Red color indicates obligatory
parameters
OPTIONS
modifier
event_id
- Supported event IDs
are:
move",
a mouse pointer move from the optional destination to the target point,"click", one or more clicks at the target point
using the specified mouse button,"press", a mouse button press (without release),"release", a mouse button release (logically
requires a preceding press event),"drag", mouse drag from the optional destination
to the target point using the specified mouse button,"wheelup", one or more mouse wheel rotation steps
upwards (wheel rotating away from user), "wheeldown", one or more mouse wheel rotation
steps downwards (wheel rotating towards user). btn
- This parameter is used to identify
the mouse button to click, press, release or drag with. Allowed values
are "left", "middle" and "right".
modifiers
to=[x:<x>][,y:<y>]
- Destination coordinates.
If the event is "move",
they define where to move the mouse pointer (target point).
If the event is "click",
"press", "release", "wheelup"
or "wheeldown", the mouse pointer
will be first moved to this location and then the associated click is
performed.
If the action is "drag", the mouse pointer will be
dragged from its actual position (or from the position specified by the
from
option) to this target location.
The coordinates
have format of 'x:<x>,y:<y>', where each
coordinate can be specified in pixels (e.g. 'x:225') or as
a percentage (e.g. 'x:23%'). If x or y is omitted, the
current mouse pointer location will be used to determine the missing
coordinate.
from=[x:<x>][,y:<y>]
- Start coordinates.
If the action is 'drag',
the mouse pointer will be dragged from this position to the coordinates
specified by the to option.
If the event is "click", "press", "release", "wheelup"
or "wheeldown", this parameter will be ignored.
The coordinates
have format of 'x:<x>,y:<y>', where each
coordinate can be specified in pixels (e.g. 'x:225') or
relatively as a percentage (e.g. 'x:23.5%'). Relative
coordinates are rounded if they are not integer. If x or y is omitted,
the current mouse pointer location will be used to determine the
missing
coordinate.
count=<number>
- How many times the mouse event should be sent. Default value is 1. This value makes sense only with the click event.
wait=<time>
- Time to wait after the events are
sent. It has the same effect as if the following command was 'Wait
<time>'. A plain number is by default parsed as
miliseconds. See the syntax of time
values paragraph for more time formats.
RETURNS
The command returns 0 (zero) on success or 1 when it fails.
EXAMPLES
Mouse
click count=2
- Perform a mouse double click at the current mouse pointer coordinates.
Mouse
move to=x:25,y:122
- Move the mouse pointer to the given coordinates
Mouse
move to=x:{_MOUSE_X}+50
- Move the mouse
pointer 50 pixels to the right from its current position.
Mouse
drag from=x:10%,y:450 to=x:22.5%,y:450
wait=2s
x
coordinate is given in the relative form. If your display resolution is
e.g. 800x600 pixels, the 'x:10%' will be equal to 'x:60'
and 'x:22.5%' will be 'x:135'.
Compareto
"icon.png" method=search onfail="Exit
1"
Mouse
move to=x:{_SEARCH_X}+10,y:{_SEARCH_Y}+10
Mouse
press
Mouse
move to=x:{_SEARCH_X}+110 wait=500
Mouse
release
- Example of a
"composed drag" applied to an object located through image comparison.
The snippet first searches the desktop for an object represented by the
icon.png template. If it is found, the mouse pointer is moved to the
area (plus ten pixels in each direction) and the object is dragged 100
pixels to the right using a sequence of press, move and release events.
Variables starting with underscore ('_')
are predefined variables. They are typically provided by T-Plan Robot
or by
its commands and contain useful values providing information about the
execution context. They are not processed in any special way so you are
free to use them and modify them as you wish. A table of the most
important ones follows.
| Who Creates and When | Variable Name | Description |
| T-Plan Robot when a the client receives a clipboard change from desktop server |
_SERVER_CLIPBOARD_CONTENT=<text> |
Content of the remote desktop
clipboard. Note that ability to transfer text to the clipboard is subject to client capabilities. This variable is typically used together with the Waitfor clipboard command. |
| T-Plan
Robot when a script execution is started or when a script is compiled. |
_DATE=<yyyyMMdd> | Date of the execution start in the
"yyyyMMdd" format. For example, May 8, 2005 will be defined as "20050508". The format may be customized in the Language panel of user preferences. To get the current date see the _CURDATE variable below. |
| _TIME=<HHmmss> | Time of the execution start in the "HHmmss"
24-hrs. format. For example, 3:10:33 pm will be defined as "151033". The format may be customized in the Language panel of user preferences. To get the current time in miliseconds see the _CURTIME variable below. Should you need formatted version of current time use _CURDATE with a custom format. |
|
| _FILE=<file> | Absolute path
of the executed script, e.g. "/root/test.txt". |
|
| _FILENAME=<filename> |
Script file
name, e.g. "test.txt". |
|
| _REPORT_DIR=<path> |
Target
directory for screenshots and reports. The default value is the user home folder and it is configurable in user preferences (Language panel). All screenshots and reports will be saved to this directory unless they are specified via absolute path. |
|
| _TEMPLATE_DIR=<path> |
Source directory containing
template images for image comparison. The default value is the user home folder and it is configurable in user preferences (Language panel). Commands employing image comparison will search this directory for all templates specified by relative path. |
|
| _SCRIPT_DIR=<path> |
Directory where the currently
executed script is located (absolute path). |
|
| _WARNING_COUNT=<number> |
Number of warnings which have
been generated by the Warning command during the script execution. |
|
| _CURDATE_FORMAT=<format> |
Date/time format for the _CURDATE dynamic variable. It must be a
string complying with the java.text.SimpleDateFormat specification. For example, setting the variable to "yyyy" will cause any later use of _CURDATE to produce "2010" (the current year in 4-digit format). Setting of this variable to empty string will revert the format to the default value. |
|
| _RANDOM_MIN=<integer_number> _RANDOM_MAX=<integer_number> |
Minimum and maximum values for
the random value generator used for the dynamic variable _RANDOM. Default values are 1 and 100000. |
|
| _RGB_X=<x_coordinate> _RGB_Y=<y_coordinate> |
Coordinates used to retrieve RGB
from the desktop image. See the _RGB dynamic variable below. |
|
| T-Plan
Robot whenever the variable is used. As values of these variables are created at the time of the variable call, they are called "dynamic variables". |
_CURTIME=<time_in_miliseconds> |
Whenever this variable is used,
it is dynamically replaced by the current system time in miliseconds since midnight of January 1, 1970 UTC. You may use this variable to calculate how long a command or a block of commands took to execute or to measure performance of the remote system. |
| _CURDATE=<formatted_time_and_date> |
Produces a readable current time
and/or date. The format may be specified in script through the _CURDATE_FORMAT variable. If the variable is not set the format defaults to the value in user configuration (see the Language panel of user preferences). If neither the preference is set the format defaults to the default Java one produced by java.util.Date().toString(). |
|
| _MOUSE_X=<X_coordinate> _MOUSE_Y=<Y_coordinate> |
Return current mouse pointer X,
Y coordinates. If the tool is not connected to a desktop or no mouse event has been registered yet since the connection, the coordinates return [0, 0]. |
|
| _RANDOM=<random_integer> |
Whenever used the variable
produces a random integer number. The range is by default set to [1, 100000] and may be changed through the _RANDOM_MIN and _RANDOM_MAX variables (see above). |
|
| _RGB=<RGB_color> | Whenever used the variable
retrieves current color of the desktop image pixel pointed to by coordinates specified by the _RGB_X and _RGB_Y variables. The pixel value is returned in HTML-style format string, 6 characters long, with R, G, B components specified in this order as lower case hexadecimal values (2 characters per component). For example the white color of RGB(255, 255, 255) is presented as "ffffff" while the green color of RGB (0, 255, 0) produces "00ff00". |
|
| T-Plan
Robot when a script execution is started. Also updated by Connect and Disconnect commands. |
_MACHINE=<servername> | Desktop server machine name to
which T-Plan Robot is connected. The variable is empty if there is no connection. |
| _PORT=<portnumber> | Desktop server port number. If
the connected desktop doesn't use a TCP/IP connection (such as drivers attached directly to local displays), the variable is empty. |
|
| _PROTOCOL=<protocolname> |
Name of protocol used for
desktop connection, for example "rfb" or "java". |
|
| _URL=<desktop_url> |
Desktop URL containing protocol,
machine (host) name and optionally port number. |
|
| _DESKTOP_WIDTH=<width_in_pixels> | Width of the currently connected
remote desktop (in pixels). |
|
| _DESKTOP_HEIGHT=<width_in_pixels> | Height of the currently connected remote desktop (in pixels). | |
| RFB (VNC) Client when connected or disconnected |
_DISPLAY=<servername>:[<display#>] | Display variable which is useful
for display redirection on Unix/Linux systems. It is in the "server:port" format, e.g. "mymachine:2" defines a machine called 'mymachine' running a VNC server on port 5902. The variable is empty if there is no VNC connection. |
| Waitfor command when an update event complying with the given criteria occurs |
_X=<number_in_pixels> |
The 'x'
coordinate of the last update event that met the criteria. |
| _Y=<number_in_pixels> | The 'y' coordinate of the last update event that met the criteria. | |
| _W=<number_in_pixels> | The 'width' coordinate of the last update event that met the criteria. | |
| _H=<number_in_pixels> | The 'height' coordinate of the last update event that met the criteria. | |
| Waitfor
command after every execution |
_TIMEOUT=<true|false> | If timeout is defined and
reached, the Waitfor command will set this variable to 'true', otherwise to 'false'. |
| Report command whenever a report gets generated |
_REPORT_FILE=<file> | Report file (absolute
path), e.g. '/root/report.html'. |
| _REPORT_FILENAME=<filename> | Report file name, e.g.
'report.html'. |
|
| Compareto command, Screenshot comparisons and 'Waifor match' calls |
_COMPARETO_TEMPLATE=<file> |
Image file (absolute path) used
for last image comparison. |
| _COMPARETO_RESULT=<number> |
Comparison result percentage. It
is always a number between 0 and 100. It indicates how much the images matched. |
|
| _COMPARETO_PASS_RATE=<number> |
Pass rate percentage used for
the last image comparsion. It is always a number between 0 and 100. |
|
| _COMPARETO_TIME_IN_MS=<milliseconds> |
Time in miliseconds spent by the
image comparison. If there's a list of templates, the value represents a summary time of all performed comparisons. |
|
| _COMPARETO_TEMPLATE_INDEX=<number> |
Index of the template in the
template list which produced the pass result. Indexing starts from zero. |
|
| _COMPARETO_TEMPLATE_WIDTH=<number> _COMPARETO_TEMPLATE_HEIGHT=<number> |
Width and height of the last
compared template image (in pixels). If the comparison passed, the variables contain dimensions of the matching template image. Supported since 2.0.2. |
|
| Compareto command, Screenshot comparisons and 'Waifor match' calls when "search" comparison method is used |
_SEARCH_MATCH_COUNT=<number> |
Number of matches found. It is
always an integer greater than or equal to zero. |
| _SEARCH_X=<number> | The 'x' coordinate of the first
match. If the template image was not found, the value is -1. |
|
| _SEARCH_Y=<number> | The 'y' coordinate of the first
match. If the template image was not found, the value is -1. |
|
| _SEARCH_X_<n>=<number> _SEARCH_Y_<n>=<number> |
The 'x' and 'y' coordinates of
the n-th match where n is between 1 and value of _SEARCH_MATCH_COUNT. |
|
| Exec command after every execution |
_EXEC_OUTPUT=<text> |
Standard output of the executed
command, i.e. messages which are printed into the console. |
| _EXEC_ERROR=<text> | Error output of the executed
command, i.e. error messages which are printed into the console. |
|
| _EXEC_COMMAND=<command> | Last executed OS command, i.e. the Exec argument. | |
| _EXEC_VALUE=<number> |
Integer exit code of the
executed OS
command. |
You may use the Variable Browser window to view the list of variables which are present in the current execution repository.
SYNOPSIS
var <var_name_1>=<value_1>
[<var_name_2>=<value_2> ...
<var_name_N>=<value_N>]
* Red color indicates obligatory
parameters
OPTIONS
var_name
- A name for the variable. The name is case sensitive and must not contain spaces.
value
- Variable value. If the value contains spaces, it must be enclosed in double quotes, e.g. "This is a text containing spaces". If you need to include the double quote character into your variable value, place a leading backslash before it, e.g. "This is a double quote \"". If you need to include a backslash followed by a double quote, use '\\"', e.g. "This is a backslash followed by a double quote - \\"".
RETURNS
The Var command always returns 0 (zero).
EXAMPLES
Var PATH=/tmp
path=/tmp DESCRIPTION="Path to change to"
EMPTY=
- Create four
variables PATH, path, DESCRIPTION and EMPTY with the given values.
Compareto
"search.png" method="search"
for (i=1; {i}<{_SEARCH_MATCH_COUNT}+1;
i={i}+1) {
# Nested
variables compose the variable names of a suffix and an index
Mouse
click to=x:{_SEARCH_X_{i}},y:{_SEARCH_Y_{i}}
}
search.png and
clicking onto
each of the occurencies. SYNOPSIS
eval
<var_name_1>=<numeric_expression_1>
[<var_name_2>=<numeric_expression_2> ...
<var_name_N>=<numeric_expression_N>]
* Red color indicates obligatory
parameters
OPTIONS
var_name
- A name for the variable. The name is case sensitive and must not contain spaces.
numeric_expression
- A numeric expression. If the expression contains spaces, it must be enclosed in double quotes, e.g. "1 + 1". See the Numeric Expressions chapter of this manual for more info on expression syntax and supported numeric operators.
RETURNS
The Eval command always returns 0 (zero).
EXAMPLES
Eval POSITION=2*(10+1)
- Create a variable POSITION with a value of 22.
'-v'
CLI command.OPTIONS
file
- A file to be
included. File name can be either relative (e.g. sayHello.tpr)
or absolute (e.g. /root/scripts/sayHello.tpr). T-Plan
Robot
will check if the file exists and is readable during every script compilation and report
an error if not. The file can be also specified via a variable (see
examples).
RETURNS
The command always returns 0 (zero). If the specified file is not
found, T-Plan Robot reports a syntax error rather than returning a
non-zero
return value.
EXAMPLES
Include
sayHello.tpr
- Load all
variables and procedures from a script called sayHello.tpr
which is located in the same directory as the script calling this
command.
Include
/root/scripts/sayHello.tpr
- Load all
variables and procedures from a script called sayHello.tpr
which is located in the /root/scripts/ directory.
Var
PROFILE=profile1.tpr
Include
{PROFILE} '-v
PROFILE=profile2.tpr'.
Run command finishes.Run commands can be effectively used to implement generic
snippets of code (libraries) or to separate test code of individual
test cases. Exit command with scope
set to file can be used to return from a script executed
through Run to the main script.OPTIONS
file
- A file to be
executed. File name can be either relative (e.g. sayHello.tpr)
or absolute (e.g. /root/scripts/sayHello.tpr). T-Plan
Robot
will check if the file exists and is readable during every script
validation and report an error if not. The file can be also specified
via a variable (see examples).
RETURNS
Run always returns the code returned by the last
executed command. If the specified file is not
found, T-Plan Robot reports a syntax error rather than returning a
non-zero
return value.
EXAMPLES
Run
sayHello.tpr
- Execute a script
called sayHello.tpr which is located in the same
directory
as the script calling this command.
Run
/root/scripts/sayHello.tpr
- Execute a script
called sayHello.tpr which is located in the /root/scripts/
directory.
Var
SCRIPT_TO_EXECUTE=sayHello.tpr
Run
{SCRIPT_TO_EXECUTE}
- Execute a script specified by a variable.
'Exit 1'), some test suites may
prefer to send an
E-mail to the responsible person, pause the execution and wait for
human
help.OPTIONS
description
- Optional description of the reason why the script was paused. This description will be displayed in the report (if defined) and printed out to the console in case of CLI mode execution.
RETURNS
The command always returns 0 (zero).
EXAMPLES
Compareto
"application.png"
if ({_EXIT_CODE} > 0) {
#
Cry for help - send a screenshot via E-mail and pause
Screenshot
runaway.png
Sendmail to="tester@dummyserver.com"
from="robot@dummyserver.com" server="mail.dummyserver.com"
subject="Runaway behavior detected - see attached picture.
Please help!" attach="{_REPORT_DIR}/runaway.png"
Pause
"Runaway behavior
detected"
}
- When image
comparison fails, send a screenshot by E-mail to the tester and pause
the execution.
SYNOPSIS
exit <exit_code_number>
[scope=<process|file|procedure|block>]
OPTIONS
exit_code_number
- Exit code. It must be an integer. A
value of zero is usually used to indicate success while non-zero values
indicate an error or unexpected result or behavior. If the command is
used to terminate T-Plan Robot, the exit code is passed to the
underlying
operating system and can be used to identify the reason of the script
termination.
process which terminates
the
script execution. If the execution is an automated one and there are no
more running automated processes, the command also terminates the JVM
(Java Virtual Machine) and returns the specified exit code to the
underlying operating system. file value terminates the currently executed file. If
a script is being executed from another script using the Run
command, only the called script is terminated and control is
returned to the master script.procedure value exits from the innermost procedure.
If
no procedure is executed, the Exit command is ignored.block value exits from the innermost structured block
of code, i.e. one of the if/else of for
statements. If the command gets called out of any such a statement, it
is ignored. RETURNS
The command returns the exit code which is specified as its
argument.
EXAMPLES
Exit
10
- Terminate the executed script and return 10 as the exit code.
Typeline
myapplication
Waitfor
update extent=40% timeout=20s
ontimeout="Exit 2" cumulative=true
- This is a typical
usage of the Exit command. It shows a situation when you
start a GUI
application called myapplication from a terminal window.
Let's suppose that the myapplication window has a fixed
size equal to at least 40% of the screen size. If the GUI starts
properly, the script will continue. The Waitfor command
will otherwise
wait for 20 seconds and then terminate the test script with an exit
code of 2.
SYNOPSIS
wait <time>
* Red color indicates obligatory
parameters
OPTIONS
time
- Time to wait before proceeding to the next command. It must be a number greater than zero. A plain number is by default interpreted as miliseconds. See syntax of time values for specification of time formats.
RETURNS
The command always returns 0 (zero).
EXAMPLES
Wait
30000
Wait
30s
Wait 0.5m
- All three
commands are equivalent and make the script wait for 30 seconds
(aka 30,000 miliseconds or half a minute) before proceeding to the next
command.
Note that this command inserts specific variables into the execution context. 'Waitfor match/mismatch' in addition performs image comparison which modifies image comparison specific variables.
SYNOPSIS
Waitfor <event_id>
[<event specific options>] [timeout=<time>]
[ontimeout=<command>] [onpass=<command>] [count=<number>]
[wait=<time>]
* Red color indicates obligatory
parameters
event_id
- Supported event
IDs are 'bell', 'update', 'match'
,'mismatch' and 'clipboard'.
_SERVER_CLIPBOARD_CONTENT
variable (see also the Var command).timeout=<time>
- Timeout specifying how long to wait at a maximum. A plain number is by default parsed as miliseconds. See the syntax of time values paragraph for more information on time formats. Note that the Waitfor command typically offers a menu item 'Continue' in the T-Plan Robot editor context menu which enables user to interrupt execution of the Waitfor command and resumes execution of the script. Such a user action is considered as if the required event happened successfuly. This affects execution of the commands defined by parameter onfail (will not be executed) and onpass (will be executed).
ontimeout=<command>
- A command to be executed when the timeout is reached. It must be one single command. If you need to define a sequence of command to be executed, use a procedure. See the example section below.
onpass=<command>
- A command to be executed when the the condition is met (i.e. expected update or bell is received). It must be one single command. If you need to define a sequence of command to be executed, use a procedure.
count=<number>
- How many events
to wait for. Default value is 1. This parameter is ignored if used with
'Waitfor
match'.
wait=<time>
- Time to wait
after the Waitfor condition is met. It has the same effect as if the
following command was 'Wait <time_in_ms>'. This
parameter is ignored if the timeout defined by the timeout
parameter is reached. A plain number is by default parsed as
miliseconds. See the syntax of time
values paragraph for more time formats.
Waitfor bell [<common
options>]
SPECIFIC
OPTIONS - BELL
None.
Waitfor update [area=[x:<x>][,y:<y>][,w:<width>][,h:<height>]]
[extent=<number>[%]] [cumulative=<false|true>]
[<common
options>]
SPECIFIC OPTIONS - UPDATE
area=[x:<x>][,y:<y>][,w:<width>][,h:<height>]
- Screen area of
interest. This parameter is applicable only to the update event
and enables user to define a custom area and watch it for updates. The
area coordinates have format of 'x:<x>,y:<y>,w:<width>,h:<height>',
where each coordinate can be specified in pixels (e.g. 'x:225')
or as a percentage (e.g. 'x:23%'). If any of x, y, width
or height is omitted, T-Plan Robot will use the full screen values to
determine the missing parameters, i.e. 'x:0, y:0,
w:<screen_width>, h:<screen_height>'. You may also
define the update area using the status bar Update Coordinates
feature.
extent=<number>[%]
- Extent of the screen update. This
parameter is applicable only to the update event and
defines how large the screen update must be. The value can be either a
number of updated pixels (e.g. 'extent=400') or percentage
(e.g. 'extent=22%'). If a custom area is defined by the area
parameter, the percentage/pixel value will be computed against this
area.
cumulative=<false|true>
- Switches on/off cumulative updates. If your desktop server prefers gradual screen updates and sends many small image fragments instead of a larger expected one, switch this feature on and T-Plan Robot will sumarize all partial updates falling into the defined area. The default value is false.
Waitfor match | mismatch [template=<template_image_file_list>]
[passrate=<pass_rate>%] [interval=<comparison_interval>]
[method=<comparison_method>] [methodparams=<custom_params>]
[cmparea=[x:<x>][,y:<y>][,w:<width>][,h:<height>]]
[<common
options>] [<image_search_options>]
* Template file list is obligatory
only
if it is required by the selected image comparison algorithm. Both two
algorithms provided by T-Plan Robot v2.0 do require a template file.
SPECIFIC
OPTIONS - MATCH AND MISMATCH
template=<template_image_file_list>
- One or more image
file names separated by semicolon (';') to be
compared to the remote desktop image. On Linux/Unix make sure the file
name doesn't contain semicolon because the list would be incorrectly
parsed.File
names can be either relative (e.g. img.png) or absolute
(e.g. /root/report/img.png). If you use relative path,
the
image will be searched in the directory defined by the _TEMPLATE_DIR variable. Supported image
formats are subject to the Java version. Java 1.6 supports at least
PNG, JPG, GIF and BMP.
Template images
will be compared with the remote desktop image in the specified list
order. If a template comparison produces a positive result (either
match or mismatch depending on the specified event), the condition is
considered to be met and the command finishes with an exit code of 0.
Predefined variable _COMPARETO_TEMPLATE_INDEX may be used
to determine index of the matching template in the list. See image comparison specific variables
for more.
Image comparison should not be performed against images with lossy compression such as JPEG. Use PNG or BMP instead. They preserve 100% of the image information and guarantee reliable and stable comparison results. Image comparison is discussed in the Compareto command specification.
passrate=<pass_rate>%
- Pass rate for
image comparison. This parameter is applicable only to the match
and mismatch events. It must be a number followed by the
percentage character (e.g. 'passrate=95%'). If this
parameter is omitted, default value defined in user preferences is
applied. This default value can be configured in the Compareto
preferences panel of the Preferences
window.
interval=<time>
- This parameter
defines time interval for image comparisons. This parameter is
applicable only to the match event. If you set it e.g. to
2
seconds, the desktop image will be compared against the given template
image every 2 seconds. A plain number is by default parsed as
miliseconds. See the syntax of time
values paragraph for more time formats. If this parameter is
omitted, default value defined in user preferences is applied. This
default value can be configured in the Compareto preferences panel of
the Preferences window.
method=<comparison_method>
methodparams=<custom_params>
cmparea=[x:<x>][,y:<y>][,w:<width>][,h:<height>]
x:<x>,y:<y>,w:<width>,h:<height>',
where each coordinate can be specified in pixels (e.g. 'x:225')
or as a percentage (e.g. 'x:23%'). If any of x, y, width
or height is omitted, T-Plan Robot will use the full screen values to
determine the missing parameters, i.e. 'x:0, y:0,
w:<screen_width>, h:<screen_height>'. You may also
define the comparison area using the Waitfor
window.removebg=<true|false>
bgcolor=<color>
minalpha=<0-255>
Waitfor
clipboard [<common options>]
SPECIFIC
OPTIONS - CLIPBOARD
None.
RETURNS
The command generally returns 0 (zero) when the condition (event)
is met. Non-zero value (usually 1) is returned when the timeout is
reached. 'Waitfor match' and 'Waitfor mismatch'
mimick behavior of the Compareto
command and return 0 (zero) when the comparison passes, 1 when it
fails and 2 when the template image is not found or cannot be read.
EXAMPLES
Typeline
"export MYDOC=`find / -name
mydoc.txt`; sleep 1; echo -e '\007\007'"
Waitfor
bell count=2
Typeline
"gnome-text-editor $MYDOC"
- This is a typical
example on how to use the bell event on a Unix/Linux
system. Let's suppose that you need to find a file on your hard drive
and edit it. The first command will run the search in a terminal window
and proceed to the Waitfor command. Once the search finishes, two bell
characters are printed using the echo OS command and your
machine beeps twice. This will cause the Waitfor command to proceed and
run the third command which will open the document in a Gnome text
editor.
Please note the 'sleep 1' command in the first line. If
your desktop server is very fast and your machine running T-Plan Robot
is
somewhat slower, it may happen that the document search finishes before
T-Plan Robot manages to proceed to the Waitfor command. The 'sleep
1'
prevents this problem because the server will wait 1 second before
printing the two bell characters.
procedure terminate {
Screenshot
error.jpg
Report
report.html
Exit
{1}
}
Typeline
myapplication
Waitfor
update extent=40% timeout=20s
ontimeout="terminate 2"
- This is a typical usage of the 'Waitfor
update' command. It shows a situation when you are starting a
GUI application called myapplication from a terminal
window. Let's suppose that the application window has a fixed size
equal
to at least 40% of the screen size. If the GUI starts properly, the
script will continue. The Waitfor command will otherwise wait for 20
seconds and then will run the exit procedure with the given exit code.
Waitfor
match template=application.png;application2.png
passrate=95% interval=5s timeout=5m
ontimeout="exit 1"
- Compare the
remote desktop image to images application.png and application2.png
every 5
seconds until there's at least 95% match with one of them. If this
condition is not met
within 5 minutes, terminate the script execution using the Exit
command and return exit code 1.
Press
Ctrl+C
Waitfor
clipboard timeout=5s
if ({_EXIT_CODE} == 0) {
Screenshot
copied_text.jpg desc="Received
text copied
on the remote desktop: {_SERVER_CLIPBOARD_CONTENT}"
}
- Pressing of
Ctrl+C on the remote desktop typically copies selected text to the
remote system clipboard. Some desktop servers are capable of sending
this
text to the clients. T-Plan Robot can decode such a message and provide
the
text into the script in form of the _SERVER_CLIPBOARD_CONTENT
variable.
The example above shows how to verify reception of the copied text
through Waitfor clipboard and how to use it e.g. in
description of a screenshot.
default
and search. You may also take advantage of the Plugin API
to write your own
image comparison module and plug it into T-Plan Robot. Concepts of
image comparison with T-Plan Robot are also discussed in a
separate document called How To Use
Image Comparison._SEARCH_MATCH_COUNT, _SEARCH_X and _SEARCH_Y.
See the table of predefined variables in
the Var
command
chapter.template_pixel_count * (1 - passrate)) and the
remote desktop image is searched for all instances having a number of
different pixels lower than or equal to this number. If your template
image size is e.g. 100x100 pixels and you specify 99% pass rate, T-Plan
Robot will find all areas of remote server desktop having up to 100
different pixels. Note that the lower pass rate you specify, the lower
the performance will be and the longer the search will take.Compareto
command
preferences which can be customized in the T-Plan Robot Preferences
window.OPTIONS
image_list
- One or more image
file names separated by semicolon (';') to be compared to the remote
desktop image. On Linux/Unix make sure the file name doesn't contain
semicolon because the list would be incorrectly parsed. File
names can be either relative (e.g. img.png) or absolute
(e.g. /root/report/img.png). If you use relative path,
the
image will be searched in the directory defined by the _TEMPLATE_DIR variable.
Supported image formats are subject to the Java version. Java 1.6
supports at least PNG, JPG, GIF and BMP.
Template images
will be compared with the remote desktop image in
the specified list order. If a template comparison produces a positive
result (either match or mismatch depending on the specified event), the
condition is considered to be met and the command finishes with an exit
code of 0 and skips any remaining templates in the list. Predefined
variable _COMPARETO_TEMPLATE_INDEX may be then used to
determine index of the matching template image. See image comparison specific variables
for a complete list of supported variables.
passrate=<pass_rate>%
- Pass rate for
image comparison. It must be a number followed by the percentage
character (e.g. 'passrate=95%'). If this parameter is
omitted, default pass rate defined in the T-Plan Robot preferences will
be
used (default values are 95% for the 'default' and 100% for the
'search' methods). You may customize these default values in the T-Plan
Robot Preferences window.
onpass=<command>
if/else
statement.onfail=<command>
method=<comparison_method>
methodparams=<custom_params>
cmparea=[x:<x>][,y:<y>][,w:<width>][,h:<height>]
x:<x>,y:<y>,w:<width>,h:<height>',
where each coordinate can be specified in pixels (e.g. 'x:225')
or as a percentage (e.g. 'x:23%'). If any of x, y, width
or height is omitted, T-Plan Robot will use the full screen values to
determine the missing parameters, i.e. 'x:0, y:0,
w:<screen_width>, h:<screen_height>'. You may also
define the comparison area using the Compareto window.removebg=<true|false>
bgcolor=<color>
minalpha=<0-255>
RETURNS
The command returns 0 (zero) when the comparison passes, 1 when it
fails and 2 when the template image is not found or cannot be read.
EXAMPLES
Compareto
netscape.png passrate=95%
onfail="exit
1"
- Compare the image
of the current remote desktop to image netscape.png. If
there is not at least 95% match, terminate the script execution using
the Exit command and return exit code 1.
Compareto
button1.png;button2.png method=search
if ({_EXIT_CODE} == 0) {
Mouse
click to="x:{_SEARCH_X}+5,y:{_SEARCH_Y}+5"
}
- Search the remote
desktop image for a button matching either button1.png or
button2.png. If it is found,
click on it. The command adds 5 pixels to the x and y coordinates to
make sure you click in the middle of the button.
Compareto
"search.png" method="search"
for (i=1; {i}<{_SEARCH_MATCH_COUNT}+1; i={i}+1) {
# Nested
variables compose the variable names of a suffix and an index
Mouse
click to=x:{_SEARCH_X_{i}},y:{_SEARCH_Y_{i}}
}
'ls
-l' on Unix/Linux. Pipes and redirection of the output are not
allowed. If you need to save the output to a file, use the outfile
parameter.Exec command. This applies to commands like dir,
cd, copy, md, mkdir,
rd, rmdir, del, erase
etc. A complete list of commands depends on the Windows system and is
available at the Microsoft site. Another good source is the COMMAND.COM page
at
Twikipedia. An example of running 'dir' on Windows would
then look like: Exec
"command.com /C dir"
_EXEC_COMMAND (last executed OS command), _EXEC_ERROR
(error output),
_EXEC_OUTPUT (standard output) and _EXEC_VALUE
(OS command exit code).
See the table of predefined variables in the Var
command chapter.OPTIONS
command
- OS command to be executed on the local system.
count=<number>
onpass=<command>
if/else construction
based
on the Exec command return value. onfail=<command>
if/else construction
based
on the Exec command return value.outfile=<file_name>
wait=<time>
RETURNS
The command returns 0 (zero) if the command is successfuly executed
or the exit code of the OS command otherwise.
EXAMPLES
Exec
"ls -l"
- List the contents
of the current directory (Unix/Linux). The listing will be available
under the _EXEC_OUTPUT variable.
Exec
"date"
Screenshot
image.png desc="This screenshot was taken on
{_EXEC_OUTPUT}."
- Use the date
OS command to insert a time stamp into a screenshot description
(Unix/Linux).
Exec
"C:\Program Files\Internet Explorer\iexplore.exe
http://www.google.com"
Exec
"rundll32 url.dll,FileProtocolHandler http://www.google.com"
- Both commands should start Internet Explorer on Windows and open the Google site.
Report
index.html
Exec
"mozilla file://{_REPORT_FILE}"
- Create an HTML
report and open it in a Mozilla browser on the local machine. The
_REPORT_FILE variable is populated by the Report
command and contains full report file path.
for
loop and proceed to the first command after the loop's enclosing right
curly brace '}'. If the command is used outside of a for
loop, it is reported as syntax error.RETURNS
The command doesn't modify the exit code and leaves its value on
the one returned by the previously executed command.
EXAMPLES
# Infinite loop
for (; 0 == 0; ) {
#
Wait for at least 20% update of the remote screen.
#
If it doesn't update for 10 seconds, break the loop.
Waitfor
update extent=20%
timeout="10s"
ontimeout="break"
}- Use a combination
of for, Waitfor
and break to hold on execution until
the
remote desktop stops to update.
'template', 'passrate','onpass','onfail'.'template'
parameter, the command will search the template directory for a
template
with matching name and extension PNG, GIF, BMP and JPG (in this order).
You can switch this feature off in the Screenshot preferences to force
the command to search for templates with exactly the same file name as
the screenshot images.OPTIONS
file
- File name to save
the image to. It MUST have a supported extension, for example "png" or
"jpg". Supported image formats are subject to the Java version. Java
1.6 supports at least PNG, JPG, GIF and BMP. T-Plan Robot will check
during every script validation
if the
path/file can be created and report an error if not. File name can be
either relative (e.g. img.jpg) or absolute (e.g. /root/report/img.jpg).
If the path doesn't exist, it is created. If you use relative path or
just a file name, the image will be saved to a directory defined by the
_REPORT_DIR variable.
desc=<description>
area=[x:<x>][,y:<y>][,w:<width>][,h:<height>]
x:<x>,y:<y>,w:<width>,h:<height>',
where each coordinate can be specified in pixels (e.g. 'x:225')
or as a percentage (e.g. 'x:23%'). If any of x, y, width
or height is omitted, T-Plan Robot will use the full screen values to
determine the missing parameters, i.e. 'x:0, y:0,
w:<screen_width>, h:<screen_height>'. You may also
define the comparison area using the Screenshot
window.attach=<list_of_files>
template=<image_list>
- One or more image
file names separated by semicolon (';') to be
compared to the remote desktop image. On Linux/Unix make sure the file
name doesn't contain semicolon because the list would be incorrectly
parsed. This
parameter originates from the Compareto
command. File
names can be either relative (e.g. img.png) or absolute
(e.g. /root/report/img.png). If you use relative path,
the
image will be searched in the directory defined by the _TEMPLATE_DIR variable.
Supported image formats are subject to the Java version. Java 1.6
supports at least PNG, JPG, GIF and BMP.
Template images will
be compared with the remote desktop image in
the specified list order. If a template comparison produces a positive
result (either match or mismatch depending on the specified event), the
condition is considered to be met and the command finishes with an exit
code of 0 and skips any remaining templates in the list. Predefined
variable _COMPARETO_TEMPLATE_INDEX may be then used to
determine index of the matching template image. See image comparison specific variables
for a complete list of supported variables.
passrate=<pass_rate>%
- Pass rate for
image comparison. It must be a number followed by the percentage
character (e.g. 'passrate=95%'). This parameter
originates
from the Compareto command. If
you
omit this value, the default pass rate of the Compareto command will be
used.
onpass=<command>
onfail=<command>
method=<comparison_method>
methodparams=<custom_params>
cmparea=[x:<x>][,y:<y>][,w:<width>][,h:<height>]
x:<x>,y:<y>,w:<width>,h:<height>',
where each coordinate can be specified in pixels (e.g. 'x:225')
or as a percentage (e.g. 'x:23%'). If any of x, y, width
or height is omitted, T-Plan Robot Enterprise will use the full screen values to
determine the missing parameters, i.e. 'x:0, y:0,
w:<screen_width>, h:<screen_height>'. You may also
define the comparison area using the Screenshot
window.removebg=<true|false>
bgcolor=<color>
minalpha=<0-255>
drawresults=<true|false>
RETURNS
The command returns 0 (zero) if the screenshot is successfully
saved and eventual image comparison passes. If image comparison takes
place and fails, a value of 1 is returned. If the screenshot cannot be
saved (e.g. not enough space), the command returns 2.
EXAMPLES
Screenshot
image.jpg
- Take a screenshot
of the current remote desktop and
save
it as a JPEG image into a file called image.jpg in a
directory defined by value of the _REPORT_DIR variable.
Screenshot
/root/images/image2.png
desc="This image
shows what happened after I had clicked the Start button."
- Take a screenshot
of the current remote desktop and
save
it as a PNG image into a file called image.png to the /root/images/
directory. If the executed script generates a report, the provided
description will be displayed there.
Report preferences
and defaults to 'default' in the open source version and
to 'enterprise' in the Enterprise one. You should always
reset this setting if you migrate among these two product versions.default". It has the
following
lifecycle:Report
command
at
the very end of your script, the HTML report will list all screenshots
and warnings including those that were taken before the Report
command
was executed. The list of images can be currently restricted only
depending on the image origin (see the scope parameter
below).Screenshot
commands. Note that image comparisons performed through the Compareto
and Waitfor match/mismatch commands are never listed. The
rationale is that you have to create a screenshot anyway to provide a
functional link in the table. See the sample report at the link listed
above for an example.
<!-- version=1.3-20061210 -->
|
Indicates which T-Plan Robot Enterprise
version
and build was used to generate this report. |
<!-- running=false -->
|
Indicates whether execution of the script is running or has already finished. |
<!-- stopped=false -->
|
A value of 'true' indicates that execution of the script has been manually stopped by user via Stop button in GUI mode or by Ctrl+C in CLI. |
<!-- paused=false -->
|
A value of 'true' indicates that
execution of the script has been either manually or programatically
(via
the Pause command) paused. |
<!-- exitCode=0 -->
|
Exit code. Zero indicates
success while any other positive number is interpreted as failure. See
the Exit command. |
<!-- imageCount=3 -->
|
Number of images in the report. |
<!-- failedComparisons=0 -->
|
Number of failed image comparisons. |
<!-- warningCount=0 -->
|
Number of warnings added by the Warning command. |
<!-- executionTimeInSec=44 -->
|
Time of script execution in seconds. |
"enterprise". It copies exactly behavior of the
default provider and it even reuses all of its configuration
parameters. The difference is however in the way how the test output is
processed to generate the resulting report file. Unlike the default
provider, this one also supports the Script and Step test results and allows to structure the
resulting test report..xml file is
specified in the command argument), the provider generates a simple XML
file with all test outputs. It's format is specified in the provider's Java
API documentation. As XML reports are linked with an XML style
sheet (XSL), they may be displayed by web browsers and they provide
exactly the same view of the report as the HTML files generated by the
default provider. As interpretation of the XML data into an HTML view
is on the web browser side, the XML output is fast and efficient. The
XML file may be in addition reused for export of test results to third
party applications.OPTIONS
file
- File name to save
the report to. T-Plan Robot Enterprise will then check whether the path and file
can
be
created and report an error if not. File extension is validated against
the list of supported formats declared by the provider and a syntax
error is raised on mismatch. The "default" provider
supports .htm
and .html extensions, the "enterprise" one
supports .xml, .htm and .html.
File name can be
either relative (e.g. report.xml) or absolute (e.g. /root/report/report.xml).
If
the path doesn't exist, it is usually created (default provider) but
this behavior may be provider specific. If you use a relative path, the
report file and all associated outputs should be saved to a directory
defined by the _REPORT_DIR
variable.
provider=<provider_name>
desc=<description>
scope=<scope_id>
scope parameter
provides a way to define which images should be included in the report
based on the screenshot creator. There are two acceptable values:all - This value is the default one. All images
taken
during the script execution will be included in the report.file - Include only those images that were taken
within the current script and in procedures called by this script.
Other
screenshots created by the master script (i.e. a super script calling
this script) and by the scripts executed using the Run
command will be excluded. This approach is suitable when you
execute
a number of smaller scripts using one superscript and you prefer to
have
a couple of shorter reports instead of a large one.RETURNS
The Report command returns 0 (zero) if the report provider is
started and the first report is created and saved successfuly. If any
error occurs, i.e. the report file cannot be created, the command
returns 1.
EXAMPLES
Report
index.html desc="This is my report."
- Create a report
generator and start to generate a report. As relative file is provided,
the report will be saved to a directory defined by value
of the
_REPORT_DIR variable. The provided description will be
displayed in the
report header.
Report
index.xml provider=enterprise desc="This
is my XML report."
- Create a report
generator and start to generate an XML report. As relative file is
provided,
the report will be saved to a directory defined by value
of the
_REPORT_DIR variable. The provided description will be
displayed in the
report header.
Var
_REPORT_DIR=/var/apache/htdocs/robot
Report
index.html scope=file
Screenshot
start_state.jpg desc="Initial state of the
{_MACHINE} desktop. Starting execution of the {_FILE} script..."
- This is a typical example on how to use the report command. The first command defines the output path for the report file and screenshots which actually resides inside the Apache document root. This is very convenient because users can watch the report online through a web browser. As both report and screenshot commands use relative path for the outputs, everything will be saved to the output directory.
Report
command), an
execution of a Warning command will trigger refresh of
the report. If
there's no active report provider, a warning is created in the
internal
tables but it is not reported in any way.OPTIONS
description
- Text of the warning to be displayed in the report.
image=<screenshot_name>
Screenshot command.RETURNS
The Warning command always returns 0 (zero).
EXAMPLES
Report
index.html
Exec
"mozilla file://{_REPORT_FILE}"
if ({_EXIT_CODE} > 0) {
Warning
"Mozilla failed to
start. Error output: {_EXEC_ERROR}"
}
-
Try to open the
HTML report in a Mozilla browser using the Exec command and add a
warning if it fails.
Screenshot
image.jpg template=template1.png
onfail="Warning
\"The image image.jpg doesn't seem to display what is expected.\"
image=image.jpg"
- Take a screenshot
and compare it to a template called template1.png. If the
comparison fails, add a warning to the image description.
'from','to',
'server' and 'user' are provided in the
Sendmail preferences, they may be omitted in the command.OPTIONS
from=<sender_address>
to=<recipient_address>
server=<server[:port]>
subject=<subject>
text=<mail_body>
attach=<attachments>
user=<username>
'passwd'
parameter.passwd=<password>
'user'
parameter. debug=<true|false>
debug=true
to switch on the JavaMail debugging console output. This is useful if
you need
to find out why the E-mail feature doesn't work. RETURNS
The command returns 0 (zero) on success or 1 if the E-mail cannot
be sent.
EXAMPLES
Screenshot
scr.png
Sendmail
to="tester@dummyserver.com" from="robot@dummyserver.com"
server="mail.dummyserver.com" subject="Screenshot
of the remote desktop" text="Please check the attached
screenshot." attach="{_REPORT_DIR}/scr.png"
- Take a screenshot
of the current remote desktop and send it by E-mail to user tester@dummyserver.com.
Sendmail
subject="Hello" text="This is a multiline
E-mail.\nSecond line.\nThird line."
- Example of a
multiline E-mail. This command will only work if you have set correct
default values of the 'from','to' and 'server'
parameters in the Sendmail command preferences.
OPTIONS
id
- A unique script ID.
It may be a number or text. If the test results are to be exported to a
third party test management application, the ID must be an
understandable value. Export to T-Plan database (and T-Plan
Professional)
requires the ID to be a valid script entity number as is described in
the Entity Mapping
chapter of the T-Plan Robot Enterprise 2.1 Integration Reference.
start|end
name
RETURNS
The Script command always returns 0 (zero).
EXAMPLES
Script
1 start name="Display
http://www.t-plan.com"
Press
Windows+R wait=3s
Typeline
"http://www.t-plan.com"
Waitfor
match template="tplanlogo.png" method=search
timeout=20s
if ({_EXIT_CODE} == 0) {
Step
"Open http://www.t-plan.com in web browser" pass
} else {
Step
"Open http://www.t-plan.com in web browser" fail
Exit
1
}
Script
1 end
- An example of
script number 1 which opens the T-Plan web site in the default web
browser on Windows. The script uses image search to verify that the
page was displayed successfully. If the T-Plan logo is detected
on the desktop, the script records a passed step result. Otherwise a
failed step is recorded and the script exits with code of 1 to indicate
failure.
OPTIONS
name
- Displayable step name, for example "Logon", "Open Browser" etc. It doesn't have to be unique.
pass|fail|nt|na
instruct=<instructions>
expected=<expected_result_desc>
actual=<actual_result_desc>
notes=<notes>
RETURNS
The Step command always returns 0 (zero).
EXAMPLES
Compareto
template=
"application.png"
if ({_EXIT_CODE} == 0) {
Step
"Start application"
pass expected="The
application GUI opens."
} else {
Step
"Start application"
fail expected="The
application GUI opens." actual="The application failed
to start."
Exit
1
}
- A typical example
of Step usage. The snippet employs image comparison to test whether the
desktop matches the application.png template or not and produces a Step
pass or fail result accordingly.
| Exit Code | Pseudo code |
Description |
| 0 |
SUCCESS |
Successful completion. |
| 1 |
FAILED_TO_OPEN |
Failed to open the input file.
Returned just by "File open". |
| 2 |
FAILED_TO_SAVE |
Failed to save to the file.
Returned just by "File close". |
| 3 | FAILED_TO_FIND |
Failed to find a value. Returned just by "File find" to indicate failed text search. |
| 4 |
INVALID_POSITION |
The line and/or column
parameters do
not point to an existing position in the file. Returned by all commands
supporting "line" and "column". |
OPTIONS
file=<ile>
outfile=<output_file>
id=<identifier>
RETURNS
The open command returns either 0 (SUCCESS) or 1 (FAILED_TO_OPEN).
The create command always returns
0 because it creates the file just in memory. If the command
exits with 0 it populates variables from the File and Counter variable groups.
EXAMPLES
File
open file="data.csv"
- Open a CSV file
located in the same directory as the script in read/write mode.
File
open file="C:\Data\data.csv" outfile="newdata.csv"
- Open a CSV file
located in the specified directory in the read only mode. When the file
is closed, save the
content and eventually all changes into the specified output
file in the script directory. If the output file exists it will be
overwritten.
File
create file="C:\Data\log.txt"
- Create a new file
content buffer in the memory and associate it with the specified file
for output.
File append [text=<text>] [id=<identifier>]
* Red
color indicates obligatory
parameters
OPTIONS
text=<text>
id=<identifier>
RETURNS
The command always returns
0 (success). As it changes file size and eventually number of lines,
the command updates variables from the Counter
group.
EXAMPLES
File
append text="This is one line\nwhile this is
another one"
- Append two lines
of text , "This is one line" and "while this is another one" to the end
of the file.
File
append text="screws\\nails"
- Append one line
of text, "screws\nails". The back slash character must be in this case
doubled because it would be otherwise interpreted as new line character.
File insert [text=<text>]
[line=<line_number>] [column=<column_number>]
[id=<identifier>]
* Red
color indicates obligatory
parameters
OPTIONS
text=<text>
line=<line_number>
column=<column_number>
id=<identifier>
RETURNS
The command returns
0 (SUCCESS) or 4 (INVALID_POSITION) if the line and column parameters
do not point to an existing position in the file. As it changes file
size and eventually number of lines,
the command updates variables from the Counter
group. The command also updates the Line
variable group to provide information about the line pointed to by the
[line,column] coordinates.
EXAMPLES
File
read line=2
File
insert text=" and potatoes" line=2
column={_FILE_LINE_LENGTH}+1
- Append " and
potatoes" to the end of the second line. The "File read" command is
called to get the line length (the _FILE_LINE_LENGTH variable).
File
find text="bananas"
File
insert text=" and potatoes" line={_FILE_LINE_NUMBER}
column={_FILE_LINE_COLUMN}+7
- Search for
"bananas" and insert the text to create "bananas and potatoes".
Note that the example doesn't test whether the find command succeeds.
File find [text=<text>]
[line=<line_number>] [column=<column_number>]
[direction=<forward|backward>]
[scope=<line|file>] [id=<identifier>]
* Red
color indicates obligatory
parameters
OPTIONS
text=<text>
line=<line_number>
column=<column_number>
direction=<forward|backward>
scope=<file|line>
id=<identifier>
RETURNS
The command returns
0 (SUCCESS) if the text is found, 3 (NOT_FOUND) if the text is not
found or 4 (INVALID_POSITION) if the line and column parameters do not
point to a valid position in the file. If the search succeeds, the Line variable group is updated
to provide the target [line,column] coordinates.
EXAMPLES
File
find text="bananas"
if ({_EXIT_CODE} == 3) {
Exit
3
}
File
insert text=" and potatoes" line={_FILE_LINE_NUMBER}
column={_FILE_LINE_COLUMN}+7
- Search the file
forwards for
"bananas" and insert the text to create "bananas and potatoes".
If the word is not found the script will be terminated with the exit
code of 3.
File read [line=<line_number>]
[column=<column_number>] [length=<length_in_chars>]
[id=<identifier>]
* Red
color indicates obligatory
parameters
OPTIONS
line=<line_number>
column=<column_number>
length=<length_in_chars>
id=<identifier>
RETURNS
The command returns
0 (SUCCESS) if the text is located and read successfully or 4
(INVALID_POSITION) if the line and column parameters do not
point to a valid position in the file. If successful the extracted text
is stored into the _FILE_READ variable. The command also updates the Line variable group to provide
information about the line pointed to by the [line,column] coordinates.
EXAMPLES
File
find text="bananas" line=2
scope=line
File
read line=2 length={_FILE_LINE_COLUMN}
Type
"{_FILE_READ}"
- Find the
"bananas" word on the second line, read the text before the word and
type it.
File parse [line=<line_number>]
[delimeter=<delimeter_char>] [separator=<separator_char>]
[trim=<true|false>]
[id=<identifier>]
File parse [line=<line_number>]
[pattern=<regular_expression>]
[trim=<true|false>]
[id=<identifier>]
* Red
color indicates obligatory
parameters
The command by default reads values from
the specified line according to the Comma Separated Values (CSV)
specification. The command is compatible with rules specified in the
Comma-Separated Values article at Wikipedia
and supports multi line values. The parsing mechanism may be in
addition customized with optional custom text delimeter, value
separator. and trimming mode.
When the "pattern" parameter is
specified, the command parses the line based on the provided
Java-compatible regular expression. This approach takes advantage of
the java.lang.String.split()
method and it is fundamentally different from the CSV mechanism. For
example, to parse individual words separated by a space use regular
expression "\s". This mode may not be mixed with CVS parsing and
"pattern" can not be specified at the same time as "delimeter" and/or
"separator".
The parsed values are made available through a set of numbered variables (_FILE_PARSE_VALUE1, _FILE_PARSE_VALUE2, ...) and a counter (_FILE_PARSE_COUNT) and may be retrieved in the script through a "for" loop with nested variable names (see the examples section). The command also modifies the line variables and sets the line number to the last processed line. This is an important feature allowing to iterate correctly over lines which may contain multiline values.
OPTIONS
line=<line_number>
delimeter=<delimeter_char>
separator=<separator_char>
pattern=<regular_expression>
trim=<true|false>
id=<identifier>
RETURNS
The command returns
0 (SUCCESS) if the text is located and read successfully or 4
(INVALID_POSITION) if the line and column parameters do not
point to a valid position in the file. On
success the command populates the Parse
variable group and also updates the Line
one with information about the processed line.
EXAMPLES
Let's have a set of data listed as
example on Wikipedia:
| 1997 | Ford |
E350 |
ac, abs, moon | 3000.00 |
| 1999 |
Chevy |
Venture "Extended Edition" | 4900.00 | |
| 1999 |
Chevy | Venture "Extended Edition, Very Large" | 5000.00 | |
| 1996 |
Jeep |
Grand Cherokee | MUST SELL! air, moon roof, loaded |
4799.00 |
The corresponding CSV file looks as
follows:
1997,Ford,E350,"ac,
abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""","",5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!
air, moon roof, loaded",4799.00
The following script parses the lines
one by one and prints out the individual CSV values (to see the results
open a text editor on the connected remote desktop).
It also calculates and prints out a sum of all prices located usually
in the fifth value on the line. Note that we can not simply iterate
over the number of lines in the file because the second last line
contains a multiline value.
File
open file="data.csv" # We declare the fifth
variable just to supress compiler error in the Eval cmd below Var sum=0
_FILE_PARSE_VALUE5=0 for (i=1;
{i}<{_FILE_LINE_COUNT}; i={i}+1) { File
parse line={i} Typeline
"Line #{i}:"
for (j=1; {j}<{_FILE_PARSE_COUNT}+1;
j={j}+1) { Typeline
" Value #{j}:
{_FILE_PARSE_VALUE{j}}"
} # Add the car
price from column 5 to the sum Eval sum={sum}+{_FILE_PARSE_VALUE5} # As the parse
command updates the Line var group with number of the last # processed line,
this will alow us to skip lines with multiline values Var i={_FILE_LINE_NUMBER} } Typeline
"Summary value: ${sum}"
Line
#1: Value #1: 1997 Value #2: Ford Value #3: E350 Value #4: ac, abs, moon Value #5: 3000.00Line #2: Value #1: 1999 Value #2: Chevy Value #3: Venture "Extended
Edition" Value #4: Value #5: 4900.00Line #3: Value #1: 1999 Value #2: Chevy Value #3: Venture "Extended
Edition, Very Large" Value #4: Value #5: 5000.00Line #4: Value #1: 1996 Value #2: Jeep Value #3: Grand Cherokee Value #4: MUST SELL!air, moon roof, loaded Value #5: 4799.00
Summary value: $17699
Another
example: Let's have a text file with numbers separated by one or
more spaces or tabulators:
1 14 23
9 100
117 5 7
To calculate the sum of all numbers into
a variable called "count" one would typically use the following script.
Note that as the data file is not CSV, it is necessary to use a Java
regular expression "\s".
File
open file="C:\numbers.txt"
Eval count=0
Var _FILE_PARSE_COUNT=0
_FILE_PARSE_VALUE1=0
for (i=1; {i}<{_FILE_LINE_COUNT}+1; i={i}+1) {
File
parse line={i} pattern="\s"
for (j=1; {j}<{_FILE_PARSE_COUNT}+1; j={j}+1) {
Eval
count={count}+{_FILE_PARSE_VALUE{j}}
}
}
File delete
[line=<line_number>] [column=<column_number>]
[length=<length_in_chars>] [id=<identifier>]
* Red color indicates obligatory
parameters
OPTIONS
line=<line_number>
column=<column_number>
length=<length_in_chars>
id=<identifier>
RETURNS
The command returns
0 (SUCCESS) if the text is located and deleted successfully or 4
(INVALID_POSITION) if the line and column parameters do not
point to a valid position in the file. The command saves the deleted
text to the _FILE_DELETED variable. As the delete operation changes
file size and eventually number of lines, it updates variables from the
Counter
group as well as the Line
one.
EXAMPLES
File
delete line="1"
- Delete the first
line (including the new line character).
File
delete line="2" length={_FILE_LENGTH}
- Delete everything
from the second line to the end of file and leave just the first line.
for (i=1; {i}<{_FILE_LINE_COUNT}; i={i}+1) {
File
delete line={i} length=10
}
- Delete first 10
characters on each line.
File
read line=1
File
delete line="1" column={_FILE_LINE_LENGTH}+1
length=1
- Remove the new
line character located at the end of the first line and
join the first and second line.
OPTIONS
id=<identifier>
save=<true|false>
RETURNS
The open command returns either 0 (SUCCESS) or 2 (FAILED_TO_SAVE)
on an I/O error. It also clears up all File specific variables from the
context.
EXAMPLES
File
open file=test.txt
...
File
close - Close the file.
If the content has been modified, save the changes to the test.txt file.
File
open file=test.txt outfile=test2.txt
...
File
close - Close the file.
The content loaded from test.txt will be written to test2.txt
regardless of whether it has been modified or not.
File
open file=test.txt id="testfile"
...
File
close id="testfile" save=false- Close the file
and discard any eventual changes. As the "testfile" ID was assigned to
the file in "File open", it must be specified in the "File close" one
as well as in any other File call between these two commands.
| Exit Code | Pseudo code |
Description |
| 0 |
SUCCESS |
Successful completion. |
| 1 |
FAILED_TO_OPEN |
Failed to open the input file.
Returned just by "Excel open". |
| 2 |
FAILED_TO_SAVE |
Failed to save to the file.
Returned just by "Excel close". |
| 3 | FAILED_TO_CREATE | Failed to create a new document or sheet. Returned just by "Excel create". |
| 4 |
SHEET_NOT_FOUND |
The row and/or column
parameters do
not point to an existing cell. Returned by all cell-reading commands
supporting "row" and "column". |
| 5 |
CELL_NOT_FOUND | Failed to find a cell with the given coordinates or with the specified value ("Excel find"). |
OPTIONS
file=<Excel_file>
id=<identifier>
sheet=<sheet_name_or_index>
RETURNS
The open command returns either 0 (SUCCESS) or 1 (FAILED_TO_OPEN).
On success it populates variables from the File and Sheet variable group.
EXAMPLES
Excel
open file="data.xls"
- Open a MS Excel
document located in the same directory as the script in read/write
mode.
Excel
open file="C:\Data\data.xls" outfile="newdata.xls"
- Open a MS Excel
document located in the specified directory in the read only mode. When
the document is closed, save the
content and eventually all changes into the specified output
file in the script directory. If the output file exists it will be
overwritten.
OPTIONS
file=<Excel_file>
id=<identifier>
sheet=<sheet_name>
RETURNS
The open command returns either 0 (SUCCESS) or 3 (FAILED_TO_CREATE)
on failure, for example when a sheet of the specified name already
exists. The command populates variables from the File and Sheet variable groups.
EXAMPLES
Excel
create file="C:\Data\log.xls"
Excel
create file="C:\Data\log.xls" sheet="Data"
Excel
create sheet="Data"
- Create a new sheet with named "Data" in the currently opened document.
Excel select [sheet=<sheet_name_or_index>]
[id=<identifier>]
Excel select [row=<row_number>]
[column=<column_number_or_id>] [sheet=<sheet_name_or_index>]
[id=<identifier>]
Excel select [ref=<cell_id>] [sheet=<sheet_name_or_index>]
[id=<identifier>]
* Red color indicates obligatory
parameters
OPTIONS
row=<row_number>
column=<column_number_or_id>
ref=<cell_id>
sheet=<sheet_name_or_index>
evaluate=<true|false>
id=<identifier_or_name>
RETURNS
The open command returns either 0 (SUCCESS), 4 (SHEET_NOT_FOUND) or
5 (CELL_NOT_FOUND).
The command populates variables from the Sheet and Cell variable groups.
EXAMPLES
Excel
select sheet=2
Excel
select sheet="Data"
Excel
select row=2 column=4
Excel
select sheet="Results" ref=A5
Excel find [value=<value>]
[type=<type>] [sheet=<sheet_name_or_index>]
[evaluate=<true|false>] [id=<identifier>]
Excel
find
[pattern=<regular_expression>]
[type=<type>] [sheet=<sheet_name_or_index>]
[evaluate=<true|false>] [id=<identifier>]
* Red
color indicates obligatory
parameters
OPTIONS
value=<value>
pattern=<sheet_name_or_index>
type=<type>
sheet=<sheet_name_or_index>
evaluate=<true|false>
id=<identifier_or_name>
- An identifier or name of the open document. This parameter doesn't have to be specified if the script opens/creates just one Excel document at a time. If multiple documents are being opened, the identifier identifies the document in other Excel commands.RETURNS
The open command returns either 0 (SUCCESS), 4 (SHEET_NOT_FOUND) or
5 (CELL_NOT_FOUND). If the cell is located successfully the command
populates variables from the Sheet
and Cell variable groups.
EXAMPLES
Excel
find value="Test data"
if ({_EXIT_CODE} > 0) {
Warning
"The \"Test data\" cell was not
found."
Exit
1
}
Excel
select row={_EXCEL_CELL_ROW}+1 column={_EXCEL_CELL_COLUMN}
Type
"{_EXCEL_CELL_VALUE}"
Excel
find value="2" evaluate=true
Excel
find sheet="Data" pattern="boo.*"
Excel
find type=FORMULA pattern="SUM\(.*\)"
Excel
find type=FORMULA pattern="SUM\(.*\)"
evaluate=true
Excel set [row=<row_number>]
[column=<column_number_or_id>] [sheet=<sheet_name_or_index>]
[id=<identifier>] [type=<type>]
[value=<value>]
Excel set [ref=<cell_id>] [sheet=<sheet_name_or_index>]
[id=<identifier>] [type=<type>]
[value=<value>]
* Red
color indicates obligatory
parameters
OPTIONS
row=<row_number>
column=<column_number_or_id>
ref=<cell_id>
sheet=<sheet_name_or_index>
id=<identifier_or_name>
type=<type>
value=<value>
RETURNS
The open command returns either 0 (SUCCESS), 4 (SHEET_NOT_FOUND) or
5 (CELL_NOT_FOUND). If the cell is located successfully the command
sets the value and/or cell type and populates variables from the Sheet and Cell variable groups.
EXAMPLES
Excel
set ref=A5 value="Test data"
Excel
set row=1 column=A value="2"
sheet="Results"
#
Declare the variable as numeric to supress compiler error
Var
_EXCEL_CELL_VALUE=1
Excel
set row=1 column=A value="2"
Excel
set value={_EXCEL_CELL_VALUE}+1 type=NUMERIC
Excel
set row=5 column=1 type=FORMULA
value="SUM(A1:A4)"
Excel
select evaluate=true
Excel close [id=<identifier>]
[save=<true|false>]
* Red color indicates obligatory
parameters
OPTIONS
id=<identifier_or_name>
save=<true|false>
RETURNS
The open command returns either 0 (SUCCESS) or 2 (FAILED_TO_SAVE)
on an I/O error. It also clears up all Excel specific variables from
the
context.
EXAMPLES
Excel
open file=test.xls
...
Excel
close - Close the file.
If the content has been modified, save the changes to the test.xls file.
Excel
open file=test.xls outfile=test2.xls
...
Excel
close
- Close the file.
The content loaded from test.xls will be written to test2.xls
regardless of whether it has been modified or not.
Excel
open file=test.xls id="testfile"
...
Excel
close id="testfile" save=false- Close the file
and discard any eventual changes. As the "testfile" ID was assigned to
the file in "Excel open", it must be specified in the "Excel close" one
as well as in any other Excel call between these two commands.