com.vncrobot.api
Interface VNCRobotThread

All Superinterfaces:
java.lang.Runnable

public interface VNCRobotThread
extends java.lang.Runnable

This interface allows to use the VNCRobot automated tasks in multi-threaded third party applications.

A VNCRobot thread typically performs one automated task. If you run VNCRobot as an application in the CLI mode to execute a test script, it actually creates a single thread and executes it. The thread life cycle is:

To create a VNCRobot thread, instantiate the com.vncrobot.VNCRobot class and call the method createVNCRobotThread(String threadId, String params[], PrintStream logStream, boolean exitOnFinish) where:

If you need to modify behavior of an individual thread, you may take advantage of the -o or --option. For the list of available options review the DefaultConfiguration.properties default configuration file.

The following example starts two VNCRobot 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.vncrobot.VNCRobot;
 import com.vncrobot.api.VNCRobotThread;

 public class TwoTasks {

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

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

Since: VNCRobot 1.3

(C) 2006 Robert Pes. All rights reserved. Date: Dec 9, 2006, 11:02:41 AM


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.
 boolean isConnected()
          Returns true if the thread is connected to a VNC server.
 boolean isConsoleMode()
          Returns true if the thread is running in console/CLI mode (i.e.
 boolean isRunning()
          Returns true if the thread is executing a script, false if not.
 void stop()
          Stop the thread.
 
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.

isRunning

boolean isRunning()
Returns true if the thread is executing a script, false if not. The value of false may indicate that the thread is not started, it failed or finished, or it is in the initial or shutdown countdown phase.

Note that if you need to find out whether the thread is started or has finished, you should rather use the Thread.isAlive() method.

Returns:
true if the thread is executing a script, false if not.

isConnected

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

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

stop

void stop()
Stop the thread. This will initiate the shutdown phase. If a test script is being executed, the execution is finished without the shutdown timeout sequence, connection to the VNC server is closed and the thread exits. If your test script is configured to generate an HTML report, it will show as "Manually Stopped By User".


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 VNCRobot 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).