"Monkey testing" is a technical term often applied to early software test automation systems, which approximated monkeys banging on the keyboard. Although it had a bad reputation at one time, monkey testing is once again gaining in popularity, because it is so cheap to implement.
It is of course hard to resist posting a Perl Monk-ey test script here. =)
This script randomly performs one of five actions every second: left mouse down or up; right mouse down or up; move mouse. Point it at the MS Paint program for a few minutes to get a good idea of what it does.
One note: something about this script plays havoc with anything running under Java. Be sure to save your work before you start the Perl Monkey Test script.
Another note: this script often ignores CTRL-C. And it takes over your cursor. Don't plan on getting any work done while the Perl Monkey Test is running. And be prepared to be quick with Task Manager...
#!/usr/bin/perl
use warnings;
use strict;
use Win32::GuiTest qw(FindWindowLike GetWindowText
SetForegroundWindow SendKeys MouseMoveAbsPix
SendLButtonDown SendLButtonUp SendRButtonDown SendRButtonUp);
$|=1;
$Win32::GuiTest::debug = 0; # Set to "1" to enable verbose mode
#set screen size
my @x = (1 .. 1024);
my @y = (1 .. 768);
my $xcoord;
my $ycoord;
my @commands = ("MouseMoveAbsPix", "SendLButtonDown()", "SendLButtonUp
+()", "SendRButtonDown()", "SendRButtonUp()");
print "Enter the name of the window for monkey testing, i.e untitled -
+ Paint :\n";
my $winName = <STDIN>;
chomp $winName;
print "You have 10 seconds to bring that window to the forefront befor
+e PerlMonkeyTest takes over your machine!\n";
print "Use Task Manager to kill processes if your mouse is out of cont
+rol.\n";
my @windows = FindWindowLike(0, "^$winName" );
#my @windows = FindWindowLike(0, "^untitled - Paint" );
# my @windows = FindWindowLike(0, "^Microsoft Excel", "^XLMAIN\$");
for (@windows) {
print "$_>\t'", GetWindowText($_), "'\n";
SetForegroundWindow($_)
or die "what window?";
sleep 10;
while (1) {
#set random $x, $y, 1024, 768
my $xcoord = $x[rand @x];
my $ycoord = $y[rand @y];
#choose random from @commands
my $command = $commands[rand @commands];
if ($command =~ "Send") {
eval $command;
}
else {
eval "$command($xcoord,$ycoord)";
}
sleep 1;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.