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

Re: updated notepad.pl example

Expand Messages
  • Dennis K. Paulsen
    Hello, I believe WaitWindow was recently implemented, so it is possible that several of the samples haven t been updated as of yet. Here is a slight
    Message 1 of 2 , Jun 3 7:38 PM
    • 0 Attachment
      Hello,

      I believe WaitWindow was recently implemented, so it is possible
      that several of the samples haven't been updated as of yet.

      Here is a slight modification to your script:

      #!/usr/bin/perl

      ## Perl Pragmas/Includes ##
      use strict;
      use warnings;

      # Uses Win32::GuiTest v1.49.2 available from the Files
      # section of this Yahoo group.
      use Win32::GuiTest qw/
      PushButton
      WaitWindow
      SendKeys
      /;


      ## Script Core ##

      # Start Application
      system('start notepad.exe');

      # Wait for application window to appear
      if (!WaitWindow('^Untitled - Notepad$')) {
      die "Can't find Notepad window!";
      }

      # Send input to application
      SendKeys("If you're reading this inside notepad,\n");
      SendKeys("we might consider this test succesful.\n");
      SendKeys("Now I'll send notepad an ALT{+}F4 to close\n");
      SendKeys("it. Please wait.......");

      # Use sleep statements to make the process more exciting
      for (my $i = 0; $i < 10; $i++) {
      # Could use sleep, but select allows for shorter wait
      # periods.
      select(undef, undef, undef, 0.50);
      SendKeys('.');
      }

      # Close Application
      SendKeys("%{F4}");

      # Wait for Save Dialog to come up.
      if (!WaitWindow('^Notepad$')) {
      die "Can't find Notepad dialog!";
      }
      # Press No as we don't want to save what we've written.
      PushButton('&No');


      Regards,
      Dennis K. Paulsen

      --- In perlguitest@yahoogroups.com, Danny Faught <faught@t...> wrote:
      > I'm learning Win32::GuiTest to use as an example in my perl
      scripting
      > tutorial at the Software Test Automation Conference. My first
      project
      > was modifying eg/notepad.pl so it uses WaitWindow for
      synchronization
      > instead of sleep.
      >
      > Was it the intention for this example to show simple sleep
      > synchronization? If so, we could add some comments explaining
      that
      > there's a better way to be learned elsewhere. If not, feel free
      to
      > adopt the code below. Who knows, it might even work. :-)
      >
      > --------------------------------------------------
      > system("start notepad.exe");
      >
      > if (Win32::GuiTest::WaitWindow(qr/^Untitled - Notepad$/, 10) == 0)
      {
      > die "Can't find Notepad window";
      > }
      > Win32::GuiTest::SendKeys("If you're reading this inside
      notepad,\n");
      > Win32::GuiTest::SendKeys("we might consider this test
      succesful.\n");
      > Win32::GuiTest::SendKeys("Now I'll send notepad an ALT{+}F4 to
      close\n");
      > Win32::GuiTest::SendKeys("it. Please wait.......");
      > sleep 1;
      > Win32::GuiTest::SendKeys(".");
      > sleep 1;
      > Win32::GuiTest::SendKeys(".");
      > sleep 1;
      > Win32::GuiTest::SendKeys(".");
      > Win32::GuiTest::SendKeys("%{F4}");
      > if (Win32::GuiTest::WaitWindow(qr/^Notepad$/, 10) == 0) {
      > die "Can't find Notepad dialog";
      > }
      > Win32::GuiTest::SendKeys("{TAB}{ENTER}");
      > --------------------------------------------------
      >
      > --
      > Danny R. Faught
      > Tejas Software Consulting
      > -> subscribe to Open Testware Reviews -
      > http://tejasconsulting.com/open-testware/
    Your message has been successfully submitted and would be delivered to recipients shortly.