Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

GUITest to test GUI

by Anonymous Monk
on May 17, 2004 at 11:30 UTC ( #353924=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

I need your help and guidance please,....

I am using ‘system()’ on WinXP to run list of batch files – that installs software - and using GUITest to check if the execution of those batch files were successful, like so;
$|++; use strict; use Win32; use Win32::GuiTest qw(:ALL :SW); use vars qw /%data/; system (cls); $data{apps_list} = shift @ARGV; $data{host} = Win32::NodeName(); print "\nThis machine is ". $data{host}; print "\n\nPath to apps list => ". $data{apps_list}."\n"; open (LST, "$data{apps_list}") || die "$! : File was not found\n"; chomp (@{$data{Go_scripts}} = <LST>); for my $item (@{$data{Go_scripts}}) { System ($item); Print "Testing => $item\n"; # # some code needs to be here to detect the popup! # Win32::AbortSystemShutdown($data{host}); }
Only if the execution of this batch file was unsuccessful, then a popup window appears indicating the failure, otherwise no popup windows will appear. Also, those popups do not remain on the screen, they have a time out value of few seconds and they disappear soon after.

Basically, I am trying to detect those pop ups using this bit of code which I test and it works fine,
While (1) { my @windows = FindWindowLike(0, 'MYPOPUP'); for my $win (@windows) { print "Found window $win with title '", GetWindowText($win), "'\n"; my @children = GetChildWindows($win); for my $child (@children) { my $text = GetWindowText($child); next if ($text =~ /^\xff/); # you've found the icon + print "Found child $child with text '$text'\n" if ($text =~ /^ +OK$/)}}}
However my problem is this, If I insert the above GUItest code after the System( ) command, then it will only run after System() has completed its excution and by then if there were any popups, then they would have disappeared.

A suggestion was made is to exit system() after starting the batch file and then running the above code. But will not help because there is no telling when these popups will appear – it could happen as soon as the batch file has ran or after few seconds. And importantly one batch file must complete its execution before starting another.

Oh, some of those batch file will attemp to restart the local machine so I need to prevent that.

What I need to do is to have the above GUITestcode running in tandem with the system ($batch) command. i.e. as the system() begins running a batch file from the list then the GUItest should start monitoring for any popup connected to that particular batch file. and Only move on to the next batch file in the list when the running of the current batch file has completed or a popup was detected.

I am not sure how I can achieve this! Do I need to use multi threading? Can I get system() to run to processes concurrently? Alternatively, how can I exit off the while loop once the batch file has completed its run?

Can some one please help me out here....That wil be very highly appreaciated,....Indeed.

Thank you very much in advance.

Replies are listed 'Best First'.
Re: GUITest to test GUI
by Ven'Tatsu (Deacon) on May 17, 2004 at 14:48 UTC
    You could possibly use threads and make the main thread the work thread and a child thread a 'watcher' thread, or vice versa. It would basically go something like this (untested pseudo code):
    use threads; #lets us make threads use threads::shared; #lets us share variables between threads my $job_done : shared = 0; #allow the main thread to notify the child +thread it is done. sub watcher { my $error = 0; until ($job_done) { if (error windows appeared) { $error = 1; } sleep 1; #use Time::HiRes qw(sleep) or select(undef, undef, un +def, 0.5) if you need less than 1 second testing } return $error; } my $watcher = threads->create \&watcher; #start the watcher thread system(call the program); #this will tie up the main thread until it f +inishes $job_done = 1; #this should let the thread exit on the next loop my $error = $watcher->join; #clean up the thread and get it's return.
Re: GUITest to test GUI
by EdwardG (Vicar) on May 17, 2004 at 12:42 UTC
    Why not watch for these popups using a script that runs as a distinct process?


      I will not be able to find out which batch files were successful or have failed! There is only one popup style (a generic one) and it does not tell me with batch file has issued it. I need to find a way to tie up the batch file with its popup.

      I hope I am making it clear!
        Process 1 | Process 2 |------------------------------|---------------------------------| | | | | write "batch 1" to a file F | | | starts "batch 1" | | | | | T | * Notices generic popup | I | * Reads "batch 1" from file F | M | * writes to a log file etc | E | * Ignores popup until F changes | | | * Aborts system shutdown | | | | | batch 1 finishes | | | write "batch 2" to F | | | start "batch 2" | | | | * (no popups detected) | | | * detects and aborts sys shtdn | | batch 2 finishes | | | | | | ...etc | | V


Re: GUITest to test GUI
by bbfu (Curate) on May 17, 2004 at 18:02 UTC

    Two strategies that come to mind: 1) Perhaps the batch files will return a return-code indicating whether they succeeded or failed (which you can check via $?), or 2) You can use Win32::Process::Create to start the batch files instead of system() (which would allow your program to continue running without waiting for the batch files to finish).

    Black flowers blossom
    Fearless on my breath

      I cannot start another batch file until the first one has finished. Thats because what those batch files do is install software.

      I am looking into the Multi-Threading appraoch now.


        You misunderstood. By allowing your program to continue to run, I meant that it would allow your GUITest code to run, and thus detect the popups (or lack thereof).

        Black flowers blossom
        Fearless on my breath

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://353924]
Approved by Corion
[Discipulus]: echo 'a'\'' gives me the prompt and then go with error on ctrl-d
[Discipulus]: uch! worst than windows!
[marto]: It's not worse, just different. Different shells, different tools. Different ways

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-11-24 10:23 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (346 votes). Check out past polls.