TechChase
Skip to content


Perl automation : Win32::GuiTest

In manual testing,for some applications always have to click and enter value for input text boxes.It is very boaring and frustrated on working the repetitive work in long run  and then tester think that work to be done by some one else . Yes, Perl can do this type of work .This article gives some idea about Perl automation testing of GUI application.

Why Perl  Automation ?
Perl is an open source software and there are all required nuts and bolts to automate software applications.Perl build in modules can be used  to find out  the controls of an application.

What need to do before testing.

We have to  setup a basic environment before proceeding for automation .

  • Perl installations(ActivePerl)
  • Win32::GuiTest module( PPM from CPAN)

A basic idea about GUI application

All GUI application have more than just one window.Windows have common elements that we have to consider before writing a program that interacts with a GUI.

  • Each window belongs to a window class,through this class we can identify the window.
  • Every GUI application has at least one root window, and every window may have child windows.
  • Windows form a tree hierarchy. This makes them searchable (by class or not) in depth: start from a root window and search among its siblings.
  • Some windows have text attached to them. This is useful to identify windows.
  • Windows have an numeric ID that uniquely identifies them.

Please note that we can identify windows by their ID,text,class,and parent window attributes.

How to find windows handle ?

When testing GUI application,make sure the application we have to test has started.To find out the window,use the Win32::GuiTest exported function named FindWindowLike()

Syntax for FindWindowLike is:

  • FindWindowLike($window,$titleregex,$classregex,$childid, $maxlevel)

A small details about the arguments of the above functions as follows.

$window – This is the (numeric) handle of the parent window to be search.
$titleregex – This is the most often used parameter. It is a regular expression for FindWindowLike to match against window titles to find the appropriate window(s).
$classregex-This matches against a window class.

For example ,if we want to find all buttons in an application. Use the function like this:

my @windows = FindWindowLike(undef,”",”Button”);

$childid – If you pass this argument, then the function will match all windows with this ID.
$maxlevel – Maximum depth level to match windows.

How to check that a particular window is exists and not ?

Suppose @H_windows  is the windows handle we are talking for.Following code checks the window is exists or not

unless ( @H_windows ) {
print “* The program hasn’t started!n”;
exit 1;
}

Bring a window foreground

After finding a window, the window should be in the foreground for some action on it.
Following is the appropriate functions for bringing window foreground

  • SetActiveWindow(Window handle)
  • SetForegroundWindow(Window handle)

Send some input to window

SendKeys() function sends value to a input box in is in focused of a active window.

SendKeys(“value”, delay);

Finding text from an application

Following two functions are  useful for grabbing text from an GUI application
GetWindowText()
WMGetText()

Both take as a parameter as window ID:
For example
$text = GetWindowText($window);
$text = WMGetText($window);

More examples of perl GUI functions

Push buttons

PushButton() function is used to click on the button.
Systax :  PushButton($button[,$delay])

Moving around with the Mouse

MouseMoveAbsPix() is used for mouse movement over a window.

Finding co-ordinates of a window

GetWindowRect() is used to find out the coordinates of a window.

A simple Perl script for mouse click on middle of a button

Perl Win32 Mouse Click

Digg This
Reddit This
Buzz This
Vote on DZone
Share on a Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Posted in Automation Solutions.

Tagged with , , , , , .

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Gourisankar says

    This really looks good and nice post as well. Could you please provide perl tutorial(basics of perl) to make me more understanding.

    Thanks a lot…

Continuing the Discussion

  1. Perl Windows GUI Automation | AutomationDioxide linked to this post on September 5, 2009

    [...] For more information about Perl Win32::GuiTest methods  my earlier post of Perl automation [...]



Some HTML is OK

or, reply to this post via trackback.