Class PGUICapture

java.lang.Object
  |
  +--java.awt.Component
        |
        +--PGUICapture
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class PGUICapture
extends java.awt.Component

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 Capture Tool

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 in testing the GUI interface of Java programs. It is the utility which captures key and mouse events to file.

Events are recorded to the file named in the runtime parameter supplied at program start. The program itself prompts for the tested process invocation string.

The Standard Output and Standard Error streams of the tested process are redirected to files.

See Also:
Serialized Form

Inner Class Summary
private  class PGUICapture.WriteProcessOutput
          Class to write an output stream of the tested process to a file.
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.AWTTreeLock
 
Field Summary
(package private)  int autodelayint
          Test parameter - auto delay interval
(package private)  byte[] buf
          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) static java.lang.String DM
          Drag Mouse standard message
(package private)  java.net.DatagramPacket dpckt
          Instrumentation Datagram Packet
(package private)  java.net.DatagramSocket ds
          Instrumentation Datagram Socket
(package private)  boolean eatingDrags
          Flag for Mouse Drag in process.
(package private)  int keycode
          Test parameter - Key code
(package private)  java.lang.String lastDragMsg
          Last Drag message read by logPrint()
(package private)  java.lang.String lastLogMsg
          Log message written by logPrint()
protected static java.io.PrintStream log
          Log file
(package private) static java.lang.String MM
          Move Mouse standard message
private static int mouse_x
          Test parameter - mouse x coordinate
private static int mouse_y
          Test parameter - mouse y coordinate
(package private) static int MOUSECLICK
          Test Code
(package private) static int MOUSEDBLCLICK
          Test Code
(package private) static int MOUSEMOVE
          Test Code
(package private)  boolean mouseMoveEaten
          Mouse move eaten flag
(package private)  boolean mouseReleased
          Mouse Released Flag
(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
(package private)  int savedMods
          Saved Button Mask
(package private) static java.lang.String SET
          Set meta key standard message
(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
(package private) static java.lang.Process thisProc
          The tested process
(package private) static int TYPEKEY
          Test Code
(package private) static java.lang.String UNS
          UnSet meta key standard message
(package private) static int UNSETMODEKEY
          Test Code
(package private)  boolean verboseMouse
          Verbose Mouse flag (if true, lots of Mouse moves; otherwise compacted).
(package private) static java.lang.String version
          Version
 
Fields inherited from class java.awt.Component
accessibleContext, actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dbg, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PGUICapture()
          Constructor
 
Method Summary
private  int getClickCount(java.lang.String dmsg)
          Get Click Count from Datagram message
private  void getData()
          Listen for Datagrams from the tested process, and send to the appropriate handler.
private  int getKeyCode(java.lang.String dmsg)
          Get Keycode from Datagram message
private  int getMods(java.lang.String dmsg)
          Get Modifiers from Datagram message
private  java.awt.Point getPoint(java.lang.String dmsg)
          Get Coordinate point from Datagram message
private  void handleKeyEvent(java.lang.String dmsg)
          Handle Datagram message about Key event
private  void handleMouseEvent(java.lang.String dmsg)
          Handle Datagram message about Mouse event
private  void logPrint(java.lang.String s)
          Write an action to the test log file.
static void main(java.lang.String[] args)
          Mainline.
 
Methods inherited from class java.awt.Component
, action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkGD, checkImage, checkImage, checkWindowClosingException, coalesceEvents, constructComponentName, contains, contains, createChildHierarchyEvents, createHierarchyEvents, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, doLayout, enable, enable, enableEvents, enableInputMethods, eventEnabled, firePropertyChange, getAccessibleContext, getAccessibleIndexInParent, getAccessibleStateSet, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, initIDs, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, layout, lightweightPaint, lightweightPrint, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, numListening, paint, paintAll, paintHeavyweightComponents, paramString, postEvent, postsOldMouseEvents, preferredSize, prepareImage, prepareImage, print, printAll, printHeavyweightComponents, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, readObject, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, resetGC, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, 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

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

SET

static java.lang.String SET
Set meta key standard message

UNS

static java.lang.String UNS
UnSet meta key standard message

DM

static java.lang.String DM
Drag Mouse standard message

MM

static java.lang.String MM
Move Mouse standard message

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

mouse_x

private static int mouse_x
Test parameter - mouse x coordinate

mouse_y

private static int mouse_y
Test parameter - mouse y coordinate

shiftlock

boolean shiftlock
Shift lock

log

protected static java.io.PrintStream log
Log file

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

verboseMouse

boolean verboseMouse
Verbose Mouse flag (if true, lots of Mouse moves; otherwise compacted).

mouseMoveEaten

boolean mouseMoveEaten
Mouse move eaten flag

ds

java.net.DatagramSocket ds
Instrumentation Datagram Socket

buf

byte[] buf
Instrumentation Datagram Packet Buffer

dpckt

java.net.DatagramPacket dpckt
Instrumentation Datagram Packet

lastLogMsg

java.lang.String lastLogMsg
Log message written by logPrint()

lastDragMsg

java.lang.String lastDragMsg
Last Drag message read by logPrint()

eatingDrags

boolean eatingDrags
Flag for Mouse Drag in process.

mouseReleased

boolean mouseReleased
Mouse Released Flag

savedMods

int savedMods
Saved Button Mask

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

PGUICapture

public PGUICapture()
Constructor
Method Detail

main

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

logPrint

private void logPrint(java.lang.String s)
Write an action to the test log file.
Parameters:
String - Action to write.

getData

private void getData()
Listen for Datagrams from the tested process, and send to the appropriate handler.

handleKeyEvent

private void handleKeyEvent(java.lang.String dmsg)
Handle Datagram message about Key event
Parameters:
String - Datagram message

getKeyCode

private int getKeyCode(java.lang.String dmsg)
Get Keycode from Datagram message
Parameters:
String - Datagram message
Returns:
int Keycode

handleMouseEvent

private void handleMouseEvent(java.lang.String dmsg)
Handle Datagram message about Mouse event
Parameters:
String - Datagram message

getMods

private int getMods(java.lang.String dmsg)
Get Modifiers from Datagram message
Parameters:
String - Datagram message
Returns:
int Modifiers

getClickCount

private int getClickCount(java.lang.String dmsg)
Get Click Count from Datagram message
Parameters:
String - Datagram message
Returns:
int Number of clicks

getPoint

private java.awt.Point getPoint(java.lang.String dmsg)
Get Coordinate point from Datagram message
Parameters:
String - Datagram message
Returns:
Point Coordinate