Loading ...
Sorry, an error occurred while loading the content.

testing calc.exe

Expand Messages
  • gabor529
    I have written a small script to test calc.exe I d be glad to hear your comments on my script. How would you do it differently ? I included the sleep() calls
    Message 1 of 1 , Feb 27, 2004
    • 0 Attachment
      I have written a small script to test calc.exe
      I'd be glad to hear your comments on my script. How would you do
      it differently ?
      I included the sleep() calls to make it easier on the eyes to follow
      what it does.

      If this seems like a helpful example you are welcome to include it in
      the distribution.
      Gabor

      use strict;
      use warnings;

      use Win32::GuiTest qw(:ALL);

      if (not @ARGV or
      not grep {$ARGV[0] eq $_} qw(keyboard mouse)) {
      die "Usage: $0 [keyboard|mouse]\n"
      }

      $Win32::GuiTest::debug = 0;

      system "start calc.exe";
      sleep(1);
      my @windows = FindWindowLike(undef, "Calculator");

      if ($ARGV[0] eq "keyboard") {
      PushButton '7';
      sleep(1);
      PushButton '\*';
      sleep(1);
      PushButton '5';
      sleep(1);
      PushButton '=';
      sleep(2);

      # Catch the content of the first child,
      # At this point we can only hope that this
      # is the child that holds the result
      # as it does not have a title, maybe it
      # has a type that we can check ?
      my @children = GetChildWindows($windows[0]);
      printf "Result: %s\n", WMGetText($children[0]);

      SendKeys("%{F4}"); # Alt-F4 to exit
      }
      if ($ARGV[0] eq "mouse") {
      my ($left, $top, $right, $bottom) = GetWindowRect($windows[0]);

      # find the appropriate child window
      # click in the center of it
      my @children = GetChildWindows($windows[0]);
      foreach my $title (qw(7 * 5 =)) {
      my ($c) = grep {$title eq GetWindowText($_)} @children;
      my ($left, $top, $right, $bottom) = GetWindowRect($c);
      MouseMoveAbsPix(($right+$left)/2,($top+$bottom)/2);
      SendMouse("{LeftClick}");
      sleep(1);
      }
      printf "Result: %s\n", WMGetText($children[0]);

      MouseMoveAbsPix($right-10,$top+10);
      # this probably depends on the resolution

      sleep(2);
      SendMouse("{LeftClick}");
      }
    Your message has been successfully submitted and would be delivered to recipients shortly.