NAME
X11::GUITest - Provides GUI testing/interaction facilities.
Developed by Dennis K. Paulsen
VERSION
0.13
Please consult 'docs/Changes' for the list of changes between module revisions.
SYNOPSIS
For additional examples, please look under the 'eg/' sub-directory.
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.
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.
- WaitWindowClose WINDOWID [, MAXWAITINSECONDS]
-
Waits for the specified window to close.
One can optionally specify an alternative wait amount in seconds. The window will keep being checked to see if it has closed until this amount of time has been reached. The default amount is defined in the DEF_WAIT constant available through the :CONST export tag.
zero is returned if window is not gone, non-zero if it is gone.
- 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 may be specified too. Also, you could use the logical Id for the button: M_BTN1, M_BTN2, M_BTN3, M_BTN4, M_BTN5. These are all available through the :CONST export tag.
zero is returned on failure, non-zero for success
ClickWindow('gedit');
- IsChild PARENTWINDOWID WINDOWID
-
Determines if the specified window is a child of the specified parent.
zero is returned for false, non-zero for true.
- QuoteStringForSendKeys STRING
-
Quotes {} characters in the specified string that would be interpreted as having special meaning if sent to SendKeys directly. This function would be useful if you had a text file in which you wanted to use each line of the file as input to the SendKeys function, but didn't want any special interpretation of the characters in the file.
Returns the quoted string, undef is returned on error.
# Quote ~, %, etc. as {~}, {%}, etc for literal use in SendKeys. SendKeys( QuoteStringForSendKeys('Hello: ~%^(){}+') );
- 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');