| 1 |
#!/usr/bin/perl |
| 2 |
#----------------------------------------------------------------------# |
| 3 |
# X11::GUITest ($Id: WebBrowser_1.pl 206 2011-05-15 13:24:11Z ctrondlp $) |
| 4 |
# Notes: Basic interaction with Mozilla (Web Browser). Tested using |
| 5 |
# v1.2.1 of the application under the English language. |
| 6 |
#----------------------------------------------------------------------# |
| 7 |
|
| 8 |
## Pragmas/Directives/Diagnostics ## |
| 9 |
use strict; |
| 10 |
use warnings; |
| 11 |
|
| 12 |
## Imports (use [MODULE] qw/[IMPORTLIST]/;) ## |
| 13 |
use X11::GUITest qw/ |
| 14 |
StartApp |
| 15 |
FindWindowLike |
| 16 |
WaitWindowClose |
| 17 |
WaitWindowViewable |
| 18 |
SendKeys |
| 19 |
SetEventSendDelay |
| 20 |
/; |
| 21 |
|
| 22 |
## Constants (sub [CONSTANT]() { [VALUE]; }) ## |
| 23 |
|
| 24 |
## Variables (my [SIGIL][VARIABLE] = [INITIALVALUE];) ## |
| 25 |
my $MainWin = 0; |
| 26 |
my $AlertWin = 0; |
| 27 |
my $AboutWin = 0; |
| 28 |
|
| 29 |
## Core ## |
| 30 |
print "$0 : Script Start\n"; |
| 31 |
|
| 32 |
# Slow event sending down a little for when X server |
| 33 |
# is busy with this and other bigger applications |
| 34 |
SetEventSendDelay(20); |
| 35 |
|
| 36 |
# Make sure Mozilla isn't already running |
| 37 |
# even though we could find a way around |
| 38 |
# other instances of it. |
| 39 |
if (FindWindowLike('Mozilla Firefox')) { |
| 40 |
die('Mozilla Firefox window is already open!'); |
| 41 |
} |
| 42 |
|
| 43 |
# Start the application |
| 44 |
StartApp('firefox'); |
| 45 |
# Wait at most 20 seconds for it to come up |
| 46 |
($MainWin) = WaitWindowViewable('Mozilla Firefox', undef, 20) or die('Could not find browser window!'); |
| 47 |
|
| 48 |
# If an alert window presents itself within 5 seconds, close it |
| 49 |
if ( (($AlertWin) = WaitWindowViewable('Alert', undef, 5)) ) { |
| 50 |
SendKeys('{SPC}'); |
| 51 |
WaitWindowClose($AlertWin) or die('Could not close Alert window!'); |
| 52 |
} |
| 53 |
|
| 54 |
# Select web address bar and go to a website |
| 55 |
SendKeys('^(l)'); |
| 56 |
SendKeys("http://sourceforge.net/projects/x11guitest\n"); |
| 57 |
# Wait for website page to start coming up |
| 58 |
WaitWindowViewable('X11::GUITest') or die('Could not find website page!'); |
| 59 |
# Give page time to finish loading, so we can interact with the shortcut keys |
| 60 |
# again. Hopefully we can find a better way in the future rather then hard waits. |
| 61 |
sleep(15); |
| 62 |
|
| 63 |
# Open About Mozilla Window |
| 64 |
SendKeys('%(h)a'); # Alt-h, a |
| 65 |
($AboutWin) = WaitWindowViewable('About.*Mozilla') or die('Could not find About window!'); |
| 66 |
# Now close it |
| 67 |
SendKeys('%(c)'); |
| 68 |
WaitWindowClose($AboutWin) or die('Could not close About window!'); |
| 69 |
|
| 70 |
# Close main Mozilla window |
| 71 |
SendKeys('^(w)'); |
| 72 |
WaitWindowClose($MainWin) or die('Could not close Mozilla window!'); |
| 73 |
|
| 74 |
|
| 75 |
print "$0 : Script End (Success)\n"; |
| 76 |
|
| 77 |
## Subroutines ## |