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

Re: best wishes!

Expand Messages
  • Danny R. Faught
    I have a script that does some kludging around with GetForegroundWindow and GetWindowText to detect modal error dialogs. It does a fairly reliable job of
    Message 1 of 5 , Dec 1, 2005
    • 0 Attachment
      I have a script that does some kludging around with GetForegroundWindow and GetWindowText to detect modal error dialogs. It does a fairly reliable job of getting past them.

      I haven't tried to detect non-modal dialogs.
      --
      Danny R. Faught
      Tejas Software Consulting
      http://tejasconsulting.com/
    • Piotr Kaluski
      Could you please send us those scripts? --Piotr ... GetForegroundWindow and GetWindowText to detect modal error dialogs. It does a fairly reliable job of
      Message 2 of 5 , Dec 1, 2005
      • 0 Attachment
        Could you please send us those scripts?
        --Piotr

        --- In perlguitest@yahoogroups.com, "Danny R. Faught" <faught@t...>
        wrote:
        >
        > I have a script that does some kludging around with
        GetForegroundWindow and GetWindowText to detect modal error dialogs.
        It does a fairly reliable job of getting past them.
        >
        > I haven't tried to detect non-modal dialogs.
        > --
        > Danny R. Faught
        > Tejas Software Consulting
        > http://tejasconsulting.com/
        >
      • Danny R. Faught
        ... The script is proprietary to one of my client, but here s a sanitized snippet. I call the checkFocus sub right before every mouse click. Hopefully it
        Message 3 of 5 , Dec 2, 2005
        • 0 Attachment
          > Could you please send us those scripts?

          The script is proprietary to one of my client, but here's a sanitized snippet. I call the checkFocus sub right before every mouse click. Hopefully it makes sense out of context. This took a lot of tweaking to get right, and it's still not as reliable as I'd like. The order of each action is very sensitive.

          There are tons of race conditions when trying to automate a GUI. I found this out the hard way when I tried sending Alt-F4 and the window went away on its own, causing the parent to shut down.


          sub checkFocus {
          my $tries = 0;
          my $f4Sent = 0;
          while (1) {
          SetFocus($parentWindow);
          my $foreground = &GetForegroundWindow();
          if ($foreground == $parentWindow) {
          return 1;
          }
          my $foregroundText = GetWindowText($foreground);
          printLog("foreground is #$foreground '$foregroundText'");
          if (++$tries > 20) {
          die "can't set focus";
          }
          if ($foregroundText eq "Myapp") {
          if ($splash) {
          logPrint("Switching from splash screen to main window\n");
          $splash = 0;
          $parentWindow = $foreground;
          }
          else {
          printLog("found dialog, groping for buttons");
          if (! PushChildButton($foreground, "Cancel") &&
          ! PushChildButton($foreground, "No") &&
          ! PushChildButton($foreground, "OK")) {
          printLog("! Can't dismiss dialog with button");
          }
          }
          }
          elsif ($foregroundText eq "Myapp Dialog1" ||
          $foregroundText eq "Myapp Dialog2") {
          if (! $f4Sent) {
          printLog("-> dismissing '$foregroundText'");
          # Alt-F4 doesn't work with L or M button down
          _LButtonUp();
          _MButtonUp();
          _RButtonUp();
          Type("%{F4}");
          $f4Sent = 1;
          }
          else {
          printLog("waiting for window to dismiss");
          }
          }
          # these are transient dialogs, they'll go away if we wait a bit
          elsif ($foregroundText eq "Myapp Transient1" ||
          $foregroundText eq "Myapp Transient2") {
          printLog("Waiting for '$foregroundText'");
          # If action doesn't succeed, must click Continue
          PushChildButton($foreground, "Continue");
          }
          elsif ($foregroundText eq "") {
          # hit this condition once, not sure why
          if (findWindow($winName)) {
          printLog("foreground text is null, retrying");
          }
          else {
          die "Myapp is gone\n";
          }
          }
          SetForegroundWindow($parentWindow);

          uSleep(.5);
          }
          }

          --
          Danny R. Faught
          Tejas Software Consulting
          http://tejasconsulting.com/
        • brentje
          Yes, please send in your script. I ve been working on something to do this for the last couple of days. I ve finally got something to work. But to quote a
          Message 4 of 5 , Dec 2, 2005
          • 0 Attachment
            Yes, please send in your script. I've been working on something to do
            this for the last couple of days. I've finally got something to work.
            But to quote a certain sci-fi movie...this has got to be the ugliest
            hack I've ever done.

            I've made a master script. After checking to see if the foreground
            window is the right window to test on, I create a process. Then I
            start a loop that just checks every half second to make sure the
            foreground window is still the right window. If it's not, it suspends
            the process. Then it checks the window title of the new foreground
            window to see if it matches a known error message that could popup for
            the window. If a match is found, I direct it to handle the error,
            kill the process, then create a new process to start the script again.
            If it's not, for now I just have it dying. With a little work, I
            think this could do what I want it to do. But I would be more then
            appreciative for some suggestions.

            Here's a copy of my code for everyone to improve. Since I'm testing
            .Net, and .Net has strange ways of creating error dialogs appearently,
            I have to search the foreground window to get the title text. And I
            know the hardcoded mouse click is bad, as is the multiple process
            creation code, but this was a quick proof-of-concept test.


            Win32::Process::Create($ProcessObj,
            "C:\\Perl\\bin\\perl.exe",
            "perl Login.pl",
            0,
            NORMAL_PRIORITY_CLASS,
            ".")|| die ErrorReport();

            while (1)
            {
            select(undef, undef, undef, 0.50);
            $fgWindow = GetForegroundWindow();
            if($fgWindow != $myWindow)
            {
            $ProcessObj->Suspend();
            select(undef, undef, undef, 2.00);
            if(FindWindowLike($fgWindow, "Invalid User", undef))
            {
            MouseMoveAbsPix(507,406);
            SendMouse('{LEFTCLICK}');
            $ProcessObj->Kill( 9 );
            Win32::Process::Create($ProcessObj,
            "C:\\Perl\\bin\\perl.exe",
            "perl Login.pl",
            0,
            NORMAL_PRIORITY_CLASS,
            ".")|| die ErrorReport();
            }elsif(FindWindowLike($fgWindow, "Password Error", undef))
            {
            MouseMoveAbsPix(507,406);
            SendMouse('{LEFTCLICK}');
            $ProcessObj->Kill( 9 );
            Win32::Process::Create($ProcessObj,
            "C:\\Perl\\bin\\perl.exe",
            "perl Login.pl",
            0,
            NORMAL_PRIORITY_CLASS,
            ".")|| die ErrorReport();
            }else
            {
            $ProcessObj->Kill( 9 );
            die;
            }
            }
            }


            Thanks
            Brent


            --- In perlguitest@yahoogroups.com, "Piotr Kaluski" <pkaluski@p...> wrote:
            >
            > Could you please send us those scripts?
            > --Piotr
            >
            > --- In perlguitest@yahoogroups.com, "Danny R. Faught" <faught@t...>
            > wrote:
            > >
            > > I have a script that does some kludging around with
            > GetForegroundWindow and GetWindowText to detect modal error dialogs.
            > It does a fairly reliable job of getting past them.
            > >
            > > I haven't tried to detect non-modal dialogs.
            > > --
            > > Danny R. Faught
            > > Tejas Software Consulting
            > > http://tejasconsulting.com/
            > >
            >
          • Philip Zembrod
            ... My approach: I scan for new top level windows 10 times per second and have the rule: Every unexpected new top level window is an error. Thus in my test
            Message 5 of 5 , Dec 5, 2005
            • 0 Attachment
              > Date: Thu, 01 Dec 2005 15:30:46 -0600
              > From: "Danny R. Faught" <faught@...>
              > Subject: Re: best wishes!
              >
              > I have a script that does some kludging around with GetForegroundWindow and GetWindowText to detect modal error dialogs. It does a fairly reliable job of getting past them.
              >
              > I haven't tried to detect non-modal dialogs.

              My approach: I scan for new top level windows 10 times per second and have the rule:
              Every unexpected new top level window is an error. Thus in my test scripts I have to
              announce expected dialogs or message boxes before I click the button or menu item
              that triggers them. This works fine for me.

              Regards
              Philip
            Your message has been successfully submitted and would be delivered to recipients shortly.