This topic deals with T-Plan
Robot Enterprise features and it is not applicable to the legacy VNCRobot Version 1.3 or 2.0 projects.
As the scripting language is fully supported by the GUI
but doesn't have the flexibility of the Java programming language, it
often makes sense to use ordinary script for simpler tasks or high
level actions and employ Java only where the ordinary language doesn't
suffice or is inefficient. To support this approach T-Plan Robot
Enterprise provides two mechanisms allowing to call Java code:
Both methods support transfer of parameters between the ordinary script
and Java code through named variables stored in the shared context.
This mechanism is demonstrated on the example below. Java test classes
may also declare the parameters and their types which make the Robot's
GUI recognize them. For details see the
DefaultJavaTestScript class documentation and pictures in the
v2.2 change log.
Let's consider a simple example verifying whether a particular file
exists or not. If the file doesn't exist, the script should exit with
the exit code of 1. The following examples show how to implement this
test using both mechanisms. To demonstrate the parameter transfer the
file name will be passed as parameter and the result ("true" or
"false") will be exposed to the ordinary script.
filetest.tpr
(Alternative
#1) | | | | FileTest.java
|
#Alternative
#1
- run the .java source code file. C:\testsuite\data.txt
# If the "exists" variable is
not "true", exit the script. if ("{exists}" !=
"true") {
| import com.tplan.robot.scripting.*; | |||
filetest.tpr
(Alternative
#2) | ||||
# Alternative #2 - instantiate
the class by name. Include C:\testsuite\FileTest.jar Run FileTest file= C:\testsuite\data.txt #
If
the "exists" variable is not "true", exit the script. if ("{exists}" != "true") { |
filetest.tpr |
# The file to test existence
of. Var file=C:\testsuite\data.txt #
The Java code block calls Java code directly. # The block is in fact
internally converted to a Java test
java { #
If the "exists" variable is not "true", exit the script. if ("{exists}" != "true") {
|
12 December 2014 |
Copyright © T-Plan Ltd. |
Version 1.0 |