Run

3.2.14 Run

Run - Execute another script which may be one of:

  1. TPR script in the format described by this specification (typically a .tpr file). T-Plan Robot will process its commands as if they were written in the calling script, which means that all proceduresvariablesscreenshots and report generators defined by the executed script will remain in the execution repository and can be accessed once the Run command finishes. Exit command with the scope set to file can be used to return from a script executed through Run to the main script.
  2. Java source file (must be a .java file; supported from version 2.2). The class must be a valid T-Plan Robot Java script which extends the DefaultJavaTestScript class or at least implements the JavaTestScript interface. The Run command compiles the source code, instantiates the class and executes its test() method. As this call requires access to Java compiler, T-Plan Robot must run on Java Development Kit (JDK) or be configured with a path to the JDK installation supported since 2.3.3). If the tool runs just on Java Runtime Environment (JRE) and no JDK is available the tool will report an error. Refer to chapter 1 of the Release Notes document for instructions.
  3. Java class name (supported from version 2.2). It must be a fully qualified Java class name (package+class name) corresponding to a valid T-Plan Robot Java script which extends the DefaultJavaTestScript class or at least implements the JavaTestScript interface. The class must have the default (parameterless), constructor. The Run command instantiates the class by name and executes its test() method. As this method doesn't involve compilation of Java code, it is very fast with a minimum performance overhead and it is recommended for production scenarios.
    The compiled class code must be placed on the T-Plan Robot classpath in one of the three supported ways:
    • Load the code (JAR, ZIP or classpath) through the Include command. This way makes the script load the code dynamically and make it available to the current Java/Robot instance.
    • Add the JAR, ZIP or classpath to the "-classpath" parameter of the Robot's start command described in the Release Notes. This will make the code available to the particular Java/Robot instance.
    • Put the JAR file with the code to <java-home>\lib\ext (Windows) or <java-home>/lib/ext (Linux/Unix) of the Java installation used to execute Robot. This will make the code available to any instance of Java started from this installation (and thus to all Robot instances as well).

Version 2.2 also delivers support of optional parameters in form of <name>=<value> pairs specified on the command line after the mandatory file/class argument. These parameters are exposed to the executed script as local variables which are valid only inside the executed script or Java class. In TPR scripts the parameters may be called by name as standard variables. On the side of Java code, they may be retrieved through the getContext().getVariable() method or through the set of convenience methods getVariableAsXXX() defined in the ScriptingContext interface.

Run commands can be effectively used to implement generic snippets of code (libraries) or to separate test code of individual test cases. The Java support enhancements delivered in version 2.2 allow to implement a library of parametrized Java routines and call them from TPR scripts. This is an efficient way of how to add custom functionality to the scripting language without having to go through the Plugin mechanism.

SYNOPSIS

run

run <file_or_class> [<param1>=<value1> ... <paramN>=<valueN>]
* Red colour indicates obligatory parameters

OPTIONS

file

- The file can be one of:

  1. A TPR script file (.tpr) or a Java script file (.java). The file can be either relative to the current script file (for example sayHello.tpr) or absolute (/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.
  2. A fully qualified Java script class name (for example org.mytests.DoSomething). The specified class must be on the Java classpath. For details see the command description.

<param>=<value>

- An optional list of parameters and their values. They will be made available to the executed file in the form of local variables.

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.

Run /root/scripts/MyTest.java

- Executes the specified Java source code file. It must be a class extending com.tplan.robot.scripting.DefaultJavaTestScript or at least implementing the com.tplan.robot.scripting.JavaTestScript interface. The file is first compiled using the Java Compiler API into the byte code format and then instantiated and executed. This will work only if T-Plan Robot runs on Java from a JDK distribution or is configured with a valid path to a JDK installation (v2.3.3 and newer).

Run com.testsuite.MyDummyTestScript server="rfb://localhost:5901" pass="welcome"

- Instantiates a Java script class and executes it. The class must be on the Java classpath and it must extend com.tplan.robot.scripting.DefaultJavaTestScript or at least implement the com.tplan.robot.scripting.JavaTestScript interface. The two parameters on the command line are made inserted into the context as variables; it is however up to the executed class to use them or not.

Var SCRIPT_TO_EXECUTE=sayHello.tpr
Run "{SCRIPT_TO_EXECUTE}"

- Execute a script specified by a variable.