JDogRob has asked for the wisdom of the Perl Monks concerning the following question:

Monks -

I have a perl Tk script that generates a MainWindow and two buttons ("Continue", "Exit"). The perl script is called from another program. I am trying to automate the that script for batch script testing - i.e I call that perl script dozens of times across the batch scripts I wrote...so for automation I need the ability to 'press' "Continue" automagically.

So perl script is called -> sleeps for 3 seconds to simulate user -> "Continue" is programatically pressed.

Lot's of Google searching. Uncovered generateEvents and binding. But nothing that has really solved the problem (if solvable). Any help is appreciated. - Jason

Replies are listed 'Best First'.
Re: Perl Tk ButtonPress Automation
by Anonymous Monk on Sep 10, 2015 at 02:54 UTC
    #!/usr/bin/perl # http://perlmonks.org/?node_id=1141496 use Tk; use strict; use warnings; $| = 1; my $mw = MainWindow->new; my $continue = $mw->Button(-text => 'Continue', -command => sub {print "continue was pressed\n" ; $mw->destroy }, )->pack; my $exit = $mw->Button(-text => 'Exit', -command => sub {print "exit was pressed\n" ; $mw->destroy }, )->pack; $mw->after(3_000, sub { $continue->invoke } ); # automation :) MainLoop;

      Anonymous - this is exactly what I was looking for.

      I appreciate the help.

      Thanks,

      Jason
Re: Perl Tk ButtonPress Automation
by Anonymous Monk on Sep 10, 2015 at 02:16 UTC

    I am trying to automate the that script for batch script testing

    Why?

    Instead of a script that only does "GoTk( @ARGV );" expand the script to have a "GoCLI( @ARGV ); " then you won't need to "automate" the GUI

    See guitest as in X11::GUITest or Win32::GuiTest