T-Plan Robot Enterprise 5.0.1
Build No. 5.0.1-20190308.1

com.tplan.robot
Interface AutomatedRunnable

All Superinterfaces:
java.lang.Runnable

public interface AutomatedRunnable
extends java.lang.Runnable

Declaration of automated runnable methods.

An automated runnable typically performs one automated task usually defined by a test script or a Java class. Life cycle of such a runnable is:

The tool is designed as a multithreaded application and it can run multiple automated testing threads. Each such a thread contains its own desktop client (RemoteDesktopClient instance) and a script manager (ScriptManager instance). Each thread is typically able to handle an independent automated task, e.g. running of a script on one server instance. This class implements such a functionality and it can be executed as a thread through the Runnable interface.

Each runnable can be initiated with different CLI options. See the ApplicationSupport.APPLICATION_CLI_OPTIONS array. Thread behavior strongly depends on whether it runs in CLI (invoked with the -n option) or GUI mode. See the Runnable.run() method for more info. While there's no limitation on threads running on CLI mode, there can be just one thread running in GUI mode within one Java Virtual Machine (JVM) because the current GUI design is not capable to handle multiple frames.

The application is by default started in a single thread mode. It means that only one thread is created regardless of the CLI/GUI mode flag. The ability of running multiple threads in CLI mode can be exploited only through custom Java programs where the application JAR file and it's APIs serve as a library.

To execute an automated process instantiate the ApplicationSupport class and call one of its createAutomatedRunnable() methods. Then execute the run() method of the returned runnable. To run multiple threads encapsulate the runnable with a Thread and start it instead.

IMPORTANT: Implementations of the runnable are in general stateful and not thread safe. Do not use a single instance repeatedly or in multiple threads. Always create a new instance for each execution process.

The following example starts two automated threads. The first one connects to VNC server at localhost:1 and executes script /root/thread1.txt. The other one connects to VNC server localhost:2 and executes another script /root/thread2.txt. Note that both the threads will be executed simultaneously and the program exits when the last thread finishes.

 import com.tplan.robot.ApplicationSupport;
 import com.tplan.robot.AutomatedRunnable;

 public class TwoTasks {

    public static void main(String[] argv) {
       ApplicationSupport robot = new ApplicationSupport();
       String args1[] = { "-c", "localhost:1", "-p", "welcome", "-n", "-r", "/root/thread1.txt" };
       AutomatedRunnable runnable1 = robot.createAutomatedRunnable("cli-1", args1, System.out, false);
       Thread t1 = new Thread(runnable1);
       t1.start();

       String args2[] = { "-c", "localhost:2", "-p", "welcome", "-n", "-r", "/root/thread2.txt" };
       AutomatedRunnable runnable2 = robot.createAutomatedRunnable("cli-2", args2, System.out, false);
       Thread t2 = new Thread(runnable2);
       t2.start();
    }
 }
 
IMPORTANT: This is version has one major limitation:


T-Plan Robot Enterprise, (C) 2009-2019 T-Plan Limited. All rights reserved.


Method Summary
 int getExitCode()
          Get the thread exit code which should reflect result of the script execution.
 java.lang.String getId()
          Get the thread ID assigned during the thread creation.
 TestScriptInterpret getInterpret()
          Get the test script interpret associated with this runnable.
 ScriptManager getScriptManager()
          Get the script manager associated with the runnable.
 boolean isConnected()
          Returns true if the thread is connected to a server/desktop.
 boolean isConsoleMode()
          Returns true if the thread is running in console/CLI mode (i.e.
 void stop()
          Set the stop flag to true to indicate that the script should be stopped.
 
Methods inherited from interface java.lang.Runnable
run
 

Method Detail

isConsoleMode

boolean isConsoleMode()
Returns true if the thread is running in console/CLI mode (i.e. either "-n" or "--nodisplay" was passed among the thread parameters).

Returns:
true if the thread is running in the console/CLI mode, false if in the GUI one.

isConnected

boolean isConnected()
Returns true if the thread is connected to a server/desktop.

Returns:
true if the thread is connected to a desktop, false if not.

stop

void stop()

Set the stop flag to true to indicate that the script should be stopped. This will initiate the shutdown phase. If a test script is being executed, the execution will be finished without the shutdown timeout sequence. If the runnable owns a connection to the desktop, it is either disconnected or returned to the connection pool (see the RemoteDesktopClientFactory class for details). If the test script is configured to generate an HTML or XML report, it will show as "Manually Stopped By User".

Be aware that this method only calls the TestScriptInterpret.setStop(java.lang.Object, boolean, boolean, java.lang.String) method of the test script interpret it owns to set on the stop flag and the method has nothing to do with the obfuscated Thread.stop() one. As all standard test script methods defined in the DefaultJavaTestScript class observe the stop flag, the script is stopped promptly if such a method is being executed. Third party functionality called from test scripts should often test the flag through DefaultJavaTestScript.getContext().getInterpret().isStop() and implement a safe return when it is true.


getExitCode

int getExitCode()

Get the thread exit code which should reflect result of the script execution. Value of zero usually indicates successful execution, non-zero values mean failures. See the Exit command in the Scripting Language Specification document for more info on exit codes.

Threads stopped by the stop() method always return zero unless an internal error occurs.

Returns:
thread exit code.

getId

java.lang.String getId()
Get the thread ID assigned during the thread creation.

Returns:
thread ID (name).

getInterpret

TestScriptInterpret getInterpret()

Get the test script interpret associated with this runnable. As the interpret instance is typically created inside the Runnable.run() method of this class, it is available only after the runnable has been started. Otherwise the method returns null.

This method is intended to provide access to runtime objects created during script execution, usually through the context (TestScriptInterpret.getExecutionContext()) which links to other important objects such as the remote desktop client (ScriptingContext.getClient()) or the script variable table (ScriptingContext.getVariables()). This mechanism allows to check or even influence the script execution from the top layer of automated testing runnables and threads.

Returns:
test interpret created by the runnable to execute the test script. If the runnable is not running, the method returns null.

getScriptManager

ScriptManager getScriptManager()
Get the script manager associated with the runnable. It must be available right after the runnable gets created. This allows external script listeners to register for script events before the script gets started.

Returns:
the script manager. It never returns null.
Since:
4.0

T-Plan Robot Enterprise 5.0.1
Build No. 5.0.1-20190308.1