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 scripts 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:
- Call of a Java test class through the Run command. See the specification.
- Embedded blocks of Java code. See the specification.
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.
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.
1. Example with the Run command:
2. Example with embedded Java code block: