The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

X11::GUITest - Provides GUI testing/interaction facilities

Developed by Dennis K. Paulsen

SYNOPSIS

  use X11::GUITest qw/
    StartApp
    WaitWindowViewable
    SetInputFocus
    SendKeys
  /;

  # Start gedit application
  StartApp('gedit');

  # Wait for application window to come up and become viewable. 
  my ($GEditWinId) = WaitWindowViewable('gedit');
  if (!$GEditWinId) {
    die("Couldn't find gedit window in time!");
  }

  # Ensure input focus is set to the window
  SetInputFocus($GEditWinId);

  # Send text to it
  SendKeys("Hello, how are you?\n");

  # Close Application (Alt-f, q).
  SendKeys("%(f)q");

  # Handle gedit's Question window if it comes up when closing.  Wait
  # at most 5 seconds for it.
  if (WaitWindowViewable('Question', undef, 5)) {
    # DoN't Save (Alt-n)
    SendKeys("%(n)");
  }

INSTALLATION

  perl Makefile.PL
  make
  make test
  make install

DEPENDENCIES

An X server with the XTest extensions enabled. This seems to be the norm. If it is not enabled, it usually can be by modifying the X server configuration (i.e., XF86Config).

DESCRIPTION

This Perl package is intended to facilitate the testing of GUI applications by means of user emulation. It can be used to test/interact with GUI applications; which have been built upon the X toolkit or other toolkits (i.e., GTK) that "wrap" X toolkit's functionality.

VERSION

0.10

CHANGES

0.10 Tue Mar 05 2003 18:00:00 - Initial Release.

FUNCTIONS

Parameters enclosed within [] are optional.

If there are multiple optional parameters available for a function and you would like to specify the last one, for example, you can utilize undef for those parameters you don't specify.

REGEX in the documentation below denotes an item that is treated as a regular expression. For example, the regex "^OK$" would look for an exact match for the word OK.

FindWindowLike TITLEREGEX [, WINDOWIDSTARTUNDER]

Finds the window Ids of the windows matching the specified title regex. Optionally one can specify the window to start under; which would allow one to constrain the search to child windows of that window.

An array of window Ids is returned for the matches found. An empty array is returned if no matches were found.

  my @WindowIds = FindWindowLike('gedit');
  # Only worry about first window found
  my ($WindowId) = FindWindowLike('gedit');
WaitWindowLike TITLEREGEX [, WINDOWIDSTARTUNDER] [, MAXWAITINSECONDS]

Waits for a window to come up that matches the specified title regex. Optionally one can specify the window to start under; which would allow one to constrain the search to child windows of that window.

One can optionally specify an alternative wait amount in seconds. A window will keep being looked for that matches the specified title regex until this amount of time has been reached. The default amount is defined in the DEF_WAIT constant available through the :CONST export tag.

If a window is going to be manipulated by input, WaitWindowViewable is the more robust solution to utilize.

An array of window Ids is returned for the matches found. An empty array is returned if no matches were found.

  my @WindowIds = WaitWindowLike('gedit');
  # Only worry about first window found
  my ($WindowId) = WaitWindowLike('gedit');

  WaitWindowLike('gedit') or die("gedit window not found!");
WaitWindowViewable TITLEREGEX [, WINDOWIDSTARTUNDER] [, MAXWAITINSECONDS]

Similar to WaitWindow, but only recognizes windows that are viewable. When GUI applications are started, their window isn't necessarily viewable yet, let alone available for input, so this function is very useful.

Likewise, this function will only return an array of the matching window Ids for those windows that are viewable. An empty array is returned if no matches were found.

ClickWindow WINDOWID [, X Offset] [, Y Offset] [, Button]

Clicks on the specified window with the mouse.

Optionally one can specify the X offset and Y offset. By default, the top left corner of the window is clicked on, with these two parameters one can specify a different position to be clicked on.

One can also specify an alternative button. The default button is M_LEFT, but M_MIDDLE and M_RIGHT are also available through the :CONST export tag.

zero is returned on failure, non-zero for success

  ClickWindow('gedit');
StartApp COMMANDLINE

Uses the shell to execute a program. A primative method is used to detach from the shell, so this function returns as soon as the program is called. Useful for starting GUI applications and then going on to work with them.

zero is returned on failure, non-zero for success

  StartApp('gedit');
RunApp COMMANDLINE

Uses the shell to execute a program until its completion.

Return value will be application specific, however -1 is returned to indicate a failure in starting the program.

  RunApp('/work/myapp');