Debian Codegraph @

eg/TextEditor_1.pl

raw
1 #!/usr/bin/perl
2 #----------------------------------------------------------------------#
3 # X11::GUITest ($Id: TextEditor_1.pl 249 2026-08-15 18:43:40Z ctrondlp $)
4 # Notes: Example of interaction with gedit (Text Editor). Tested with
5 # version 2.2.0 of the editor application using the English
6 # language.
7 #----------------------------------------------------------------------#
8
9 ## Pragmas/Directives/Diagnostics ##
10 use strict;
11 use warnings;
12
13 ## Imports (use [MODULE] qw/[IMPORTLIST]/;) ##
14 use X11::GUITest qw/
15 StartApp
16 WaitWindowClose
17 WaitWindowViewable
18 SendKeys
19 ClickWindow
20 GetWindowName
21 /;
22
23 ## Constants (sub [CONSTANT]() { [VALUE]; }) ##
24
25 ## Variables (my [SIGIL][VARIABLE] = [INITIALVALUE];) ##
26 my $GEMainWin = 0;
27 #my $GEAboutWin = 0;
28
29
30 ## Core ##
31 print "$0 : Script Start\n";
32
33 # Start the text editor
34 StartApp('GDK_BACKEND=x11 gedit');
35 # Wait for it to appear within 120 seconds. RegEx: .* = zero or more of any character.
36 ($GEMainWin) = WaitWindowViewable('Un.*gedit|Untitled Document 1', undef, 120)
37 or die('Unable to find editor window!');
38
39 # Send some text to the editor (TEXT x NUM TIMES)
40 SendKeys("Hello, how are you today?\n" x 2) or die('Unable to send text to editor!');
41
42 # Ensure the window changes its name to include the
43 # 'modified' word since we sent it text above.
44 (GetWindowName($GEMainWin) =~ /(modified|\*Unsaved|\*Untitled Document 1)/i) or die('Editor did not switch its title as expected!');
45
46 # Using shortcuts (Alt-h, a), open about box and wait for it
47 #SendKeys('%(h)a');
48 #( ($GEAboutWin) = WaitWindowViewable('About gedit') ) or die('Unable to find about box!');
49
50 # Close about box (Alt-o (old) and Alt-c (new)) using shortcut for OK button.
51 #SendKeys('%(o)%(c)');
52
53 # To be safe, ensure about box is closed before we continue
54 #WaitWindowClose($GEAboutWin);
55
56 # Now close the editor using menu short-cuts
57 SendKeys('%(f)q');
58
59 # Wait for confirmation window to appear
60 # New gedit may not have this text. May need to implement screen capture sooner then later.
61 WaitWindowViewable('Question'); # or die('Unable to find confirmation (Question) window!');
62
63 # Select DoN't Save or Close without Saving (new)
64 SendKeys('%(n)%(w)') or die('Unable to select Don\'t Save button!');
65
66 # Ensure main window gets closed
67 WaitWindowClose($GEMainWin) or die('The editor window did not close!');
68
69 print "$0 : Script End (Success)\n";
70
71 ## Subroutines ##