Class PGUIRobot

java.lang.Object
  |
  +--PGUIRobot

public class PGUIRobot
extends java.lang.Object

PhOSCo GUI Test Robot


PGUI - PhOSCo GUI Testing
Copyright (C) 2000 Mike Calder-Smith, mike@gmot.demon.co.uk
Guillemot Design Ltd - www.PhOSCo.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


The PhOSCo GUI Test Robot is a very easy to use tool for testing the Graphical User Interface (GUI) behaviour of Java applications. It consists of two programs and one helper class:

For documentation, see the PGUI user documentation .

This is a very initial release with minimal testing, but does work. Please let the author know of any problems. Improvements and adaptations welcomed.

PhOSCo Graphical User Interface Tester Robot

This code requires Java 1.3 to compile, and the availability of the com.sun.image.codec.jpeg extensions from the Sun JDK 1.3 or JRE.

This routine is used to test the GUI interface of Java programs in the PhOSCo suite.


Inner Class Summary
private  class PGUIRobot.WriteProcessOutput
          Class to write an output stream of the tested process to a file.
 
Field Summary
(package private)  int autodelayint
          Test parameter - auto delay interval
(package private)  byte[] bufPGUI
          PGUI Capture/Robot Instrumentation Datagram Packet Buffer
(package private)  int buttonmask
          Test parameter - mouse button mask
(package private) static int COMMENT
          Test Code
(package private) static java.lang.String copyr
          Copyright
(package private) static int DELAY
          Test Code
(package private)  java.net.DatagramPacket dpcktPGUI
          PGUI Capture/Robot Instrumentation Datagram Packet
(package private) static int DRAGMOUSE
          Test Code
(package private)  int dragStartX
          Test parameter - mouse x coordinate at start of drag
(package private)  int dragStartY
          Test parameter - mouse y coordinate at start of drag
(package private)  java.net.DatagramSocket dsPGUI
          PGUI Capture/Robot Instrumentation Datagram Socket
private  int errcode
          Error code
(package private) static int FILECOMPARE
          Test Code
(package private) static int FILECOPY
          Test Code
private  int imageCounter
          Image counter
private  java.lang.String invocationString
          Tested Process Invocation string
(package private) static int INVOKED
          Test Code
(package private)  int keycode
          Test parameter - Key code
protected static java.io.PrintStream log
          Log file
(package private) static int MOUSECLICK
          Test Code
(package private) static int MOUSEDBLCLICK
          Test Code
(package private) static int MOUSEMOVE
          Test Code
private  int numpasses
          Number of passes
(package private) static int PROCESS
          Test Code
(package private)  java.io.BufferedInputStream processErrors
          Error Output Stream produced by the tested process
(package private)  java.io.BufferedInputStream processOutput
          Standard Output Stream produced by the tested process
protected  java.awt.Robot robbie
          The Robot
(package private) static int SCREENCAPTURE
          Test Code
(package private) static int SETAUTODELAY
          Test Code
(package private) static int SETMODEKEY
          Test Code
private  int sheight
          Tested Process Screen Height
(package private)  boolean shiftlock
          Shift lock
(package private)  int sleeptime
          Test parameter - delay interval
private  int sox
          Tested Process Screen X Origin
private  int soy
          Tested Process Screen Y Origin
private  int swidth
          Tested Process Screen Width
private  java.io.BufferedReader tcs
          Test Case suite file
(package private) static int TERMINATE
          Test Code
private  int testcases
          Number of test cases
private  boolean testeeActive
          Tested Process Active Flag
private  boolean testpass
          Pass/Fail Flag
(package private) static java.lang.Process thisProc
          The tested process
(package private) static int TYPEKEY
          Test Code
(package private) static int UNSETMODEKEY
          Test Code
(package private)  boolean verbose
          Verbosity Flag
(package private) static java.lang.String version
          Version
(package private)  int x
          Test parameter - mouse x coordinate
(package private)  int y
          Test parameter - mouse y coordinate
 
Constructor Summary
PGUIRobot()
          Constructor
 
Method Summary
private  void captureScreen(java.lang.String invoc)
          Capture and compare Screen Window
 int cmdParse(java.lang.String cmdstring)
          Parse test command string.
private  void fileCompare(java.lang.String invoc)
          File Compare
private  void fileCopy(java.lang.String invoc)
          File Copy
private  java.lang.String getTestFilename()
          Get next Test Case Filename.
private  void logAction(int cmd, int parm)
          Write action message to log file
private  void logPrint(java.lang.String s)
          Write line in log file
static void main(java.lang.String[] args)
          Mainline
private  int parseKeyCode(java.lang.String s)
          Parse string representation of a key code into the correct KeyEvent value.
private  void runProcess(java.lang.String invoc)
          Run Process
private  void runRobot(java.lang.String invoc)
          Invoke application to be tested and get screen window datagram from it.
private  void runTests(java.lang.String tfn)
          Run GUI Tests from file against current application.
 void sendSlave(java.lang.String msg)
          Send Datagram Packet to PGUIRobotSlave.
private  void writeJPEG(java.awt.image.BufferedImage bi, java.lang.String filename)
          Save an Image to a JPEG file.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

version

static java.lang.String version
Version

copyr

static java.lang.String copyr
Copyright

COMMENT

static final int COMMENT
Test Code

DELAY

static final int DELAY
Test Code

MOUSECLICK

static final int MOUSECLICK
Test Code

MOUSEDBLCLICK

static final int MOUSEDBLCLICK
Test Code

MOUSEMOVE

static final int MOUSEMOVE
Test Code

DRAGMOUSE

static final int DRAGMOUSE
Test Code

SETAUTODELAY

static final int SETAUTODELAY
Test Code

SETMODEKEY

static final int SETMODEKEY
Test Code

TYPEKEY

static final int TYPEKEY
Test Code

UNSETMODEKEY

static final int UNSETMODEKEY
Test Code

INVOKED

static final int INVOKED
Test Code

SCREENCAPTURE

static final int SCREENCAPTURE
Test Code

PROCESS

static final int PROCESS
Test Code

FILECOMPARE

static final int FILECOMPARE
Test Code

FILECOPY

static final int FILECOPY
Test Code

TERMINATE

static final int TERMINATE
Test Code

autodelayint

int autodelayint
Test parameter - auto delay interval

buttonmask

int buttonmask
Test parameter - mouse button mask

keycode

int keycode
Test parameter - Key code

sleeptime

int sleeptime
Test parameter - delay interval

x

int x
Test parameter - mouse x coordinate

y

int y
Test parameter - mouse y coordinate

dragStartX

int dragStartX
Test parameter - mouse x coordinate at start of drag

dragStartY

int dragStartY
Test parameter - mouse y coordinate at start of drag

shiftlock

boolean shiftlock
Shift lock

log

protected static java.io.PrintStream log
Log file

robbie

protected java.awt.Robot robbie
The Robot

dsPGUI

java.net.DatagramSocket dsPGUI
PGUI Capture/Robot Instrumentation Datagram Socket

bufPGUI

byte[] bufPGUI
PGUI Capture/Robot Instrumentation Datagram Packet Buffer

dpcktPGUI

java.net.DatagramPacket dpcktPGUI
PGUI Capture/Robot Instrumentation Datagram Packet

thisProc

static java.lang.Process thisProc
The tested process

sox

private int sox
Tested Process Screen X Origin

soy

private int soy
Tested Process Screen Y Origin

swidth

private int swidth
Tested Process Screen Width

sheight

private int sheight
Tested Process Screen Height

testeeActive

private boolean testeeActive
Tested Process Active Flag

invocationString

private java.lang.String invocationString
Tested Process Invocation string

tcs

private java.io.BufferedReader tcs
Test Case suite file

errcode

private int errcode
Error code

testpass

private boolean testpass
Pass/Fail Flag

testcases

private int testcases
Number of test cases

numpasses

private int numpasses
Number of passes

imageCounter

private int imageCounter
Image counter

verbose

boolean verbose
Verbosity Flag

processErrors

java.io.BufferedInputStream processErrors
Error Output Stream produced by the tested process

processOutput

java.io.BufferedInputStream processOutput
Standard Output Stream produced by the tested process
Constructor Detail

PGUIRobot

public PGUIRobot()
Constructor
Method Detail

main

public static void main(java.lang.String[] args)
Mainline
Parameters:
String[] - Runtime arguments:
  • Test script file name
  • [optional] 'q' for quiet running

runRobot

private void runRobot(java.lang.String invoc)
Invoke application to be tested and get screen window datagram from it.
Parameters:
String - Invocation string.

getTestFilename

private java.lang.String getTestFilename()
Get next Test Case Filename.

The Test Case Suite file must be an ASCII file with no empty lines with a test case file name on each line.

Returns:
String Test Case filename from Test Case Suite file

runTests

private void runTests(java.lang.String tfn)
Run GUI Tests from file against current application.
Parameters:
String - Test File name

cmdParse

public int cmdParse(java.lang.String cmdstring)
Parse test command string.

This routine may also amend the global test parameters.

Parameters:
String - Test command
Returns:
int Test Code

parseKeyCode

private int parseKeyCode(java.lang.String s)
Parse string representation of a key code into the correct KeyEvent value.

The String may be a single character in which case it represents the character which is required (including single digit characters); it may be a numeric string, in which case this is a string representation of the key code itself; or it may be a key name such as "Alt", "Ctrl", and "Shift".

Parameters:
String - String key code
Returns:
int KeyEvent Key Code or CHAR_UNDEFINED

logPrint

private void logPrint(java.lang.String s)
Write line in log file
Parameters:
String - Line to be written

logAction

private void logAction(int cmd,
                       int parm)
Write action message to log file
Parameters:
int - Command code
int - First parameter

captureScreen

private void captureScreen(java.lang.String invoc)
Capture and compare Screen Window
Parameters:
String - Invocation string

fileCompare

private void fileCompare(java.lang.String invoc)
File Compare
Parameters:
String - Invocation string

fileCopy

private void fileCopy(java.lang.String invoc)
File Copy
Parameters:
String - Invocation string

runProcess

private void runProcess(java.lang.String invoc)
Run Process
Parameters:
String - Invocation string

writeJPEG

private void writeJPEG(java.awt.image.BufferedImage bi,
                       java.lang.String filename)
Save an Image to a JPEG file.
Parameters:
BufferedImage - Image to be saved to JPEG file
String - Pathname to save file under

sendSlave

public void sendSlave(java.lang.String msg)
Send Datagram Packet to PGUIRobotSlave.
Parameters:
String - Message to send in packet