win_gui 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +43 -0
  5. data/Rakefile +58 -0
  6. data/VERSION +1 -0
  7. data/book_code/early_success/bundle.rb +34 -0
  8. data/book_code/early_success/english.txt +1 -0
  9. data/book_code/early_success/jruby_basics.rb +47 -0
  10. data/book_code/early_success/windows_basics.rb +97 -0
  11. data/book_code/guessing/locknote.rb +379 -0
  12. data/book_code/guessing/monkeyshines.rb +14 -0
  13. data/book_code/guessing/note.rb +120 -0
  14. data/book_code/guessing/note_spec.rb +175 -0
  15. data/book_code/guessing/replay.rb +21 -0
  16. data/book_code/guessing/seed.rb +9 -0
  17. data/book_code/guessing/spec_helper.rb +69 -0
  18. data/book_code/guessing/windows_gui.rb +247 -0
  19. data/book_code/home_stretch/junquenote.rb +151 -0
  20. data/book_code/home_stretch/locknote.rb +180 -0
  21. data/book_code/home_stretch/note.rb +144 -0
  22. data/book_code/home_stretch/note_spec.rb +191 -0
  23. data/book_code/home_stretch/spec_helper.rb +55 -0
  24. data/book_code/home_stretch/swing_gui.rb +50 -0
  25. data/book_code/home_stretch/windows_gui.rb +232 -0
  26. data/book_code/junquenote/exports.sh +10 -0
  27. data/book_code/junquenote/jruby_mac.sh +10 -0
  28. data/book_code/junquenote/junquenote_app.rb +262 -0
  29. data/book_code/novite/Rakefile +10 -0
  30. data/book_code/novite/app/controllers/application.rb +18 -0
  31. data/book_code/novite/app/controllers/guests_controller.rb +28 -0
  32. data/book_code/novite/app/controllers/parties_controller.rb +77 -0
  33. data/book_code/novite/app/helpers/application_helper.rb +11 -0
  34. data/book_code/novite/app/helpers/guests_helper.rb +10 -0
  35. data/book_code/novite/app/helpers/parties_helper.rb +10 -0
  36. data/book_code/novite/app/models/guest.rb +11 -0
  37. data/book_code/novite/app/models/party.rb +32 -0
  38. data/book_code/novite/app/models/party_mailer.rb +19 -0
  39. data/book_code/novite/app/views/layouts/application.rhtml +44 -0
  40. data/book_code/novite/app/views/parties/new.html.erb +42 -0
  41. data/book_code/novite/app/views/parties/show.html.erb +43 -0
  42. data/book_code/novite/app/views/party_mailer/invite.erb +17 -0
  43. data/book_code/novite/config/boot.rb +117 -0
  44. data/book_code/novite/config/database.yml +19 -0
  45. data/book_code/novite/config/environment.rb +67 -0
  46. data/book_code/novite/config/environments/development.rb +29 -0
  47. data/book_code/novite/config/environments/production.rb +27 -0
  48. data/book_code/novite/config/environments/test.rb +30 -0
  49. data/book_code/novite/config/initializers/inflections.rb +18 -0
  50. data/book_code/novite/config/initializers/mime_types.rb +13 -0
  51. data/book_code/novite/config/routes.rb +47 -0
  52. data/book_code/novite/db/migrate/001_create_parties.rb +26 -0
  53. data/book_code/novite/db/migrate/002_create_guests.rb +23 -0
  54. data/book_code/novite/db/schema.rb +41 -0
  55. data/book_code/novite/log/empty.txt +0 -0
  56. data/book_code/novite/public/.htaccess +40 -0
  57. data/book_code/novite/public/404.html +38 -0
  58. data/book_code/novite/public/422.html +38 -0
  59. data/book_code/novite/public/500.html +38 -0
  60. data/book_code/novite/public/dispatch.cgi +10 -0
  61. data/book_code/novite/public/dispatch.fcgi +24 -0
  62. data/book_code/novite/public/dispatch.rb +18 -0
  63. data/book_code/novite/public/favicon.ico +0 -0
  64. data/book_code/novite/public/images/rails.png +0 -0
  65. data/book_code/novite/public/index.html +285 -0
  66. data/book_code/novite/public/javascripts/application.js +10 -0
  67. data/book_code/novite/public/javascripts/controls.js +971 -0
  68. data/book_code/novite/public/javascripts/dragdrop.js +980 -0
  69. data/book_code/novite/public/javascripts/effects.js +1128 -0
  70. data/book_code/novite/public/javascripts/prototype.js +4233 -0
  71. data/book_code/novite/public/robots.txt +5 -0
  72. data/book_code/novite/script/about +3 -0
  73. data/book_code/novite/script/console +3 -0
  74. data/book_code/novite/script/destroy +3 -0
  75. data/book_code/novite/script/generate +3 -0
  76. data/book_code/novite/script/performance/benchmarker +3 -0
  77. data/book_code/novite/script/performance/profiler +3 -0
  78. data/book_code/novite/script/performance/request +3 -0
  79. data/book_code/novite/script/plugin +3 -0
  80. data/book_code/novite/script/process/inspector +3 -0
  81. data/book_code/novite/script/process/reaper +3 -0
  82. data/book_code/novite/script/process/spawner +3 -0
  83. data/book_code/novite/script/runner +3 -0
  84. data/book_code/novite/script/server +3 -0
  85. data/book_code/novite/test/test_helper.rb +46 -0
  86. data/book_code/one_more_thing/applescript.rb +68 -0
  87. data/book_code/one_more_thing/note_spec.rb +50 -0
  88. data/book_code/one_more_thing/spec_helper.rb +17 -0
  89. data/book_code/one_more_thing/textedit-pure.rb +28 -0
  90. data/book_code/one_more_thing/textedit.applescript +26 -0
  91. data/book_code/one_more_thing/textedit.rb +32 -0
  92. data/book_code/one_more_thing/textnote.rb +87 -0
  93. data/book_code/simplify/junquenote.rb +48 -0
  94. data/book_code/simplify/locknote.rb +46 -0
  95. data/book_code/simplify/note.rb +35 -0
  96. data/book_code/simplify/note_spec.rb +28 -0
  97. data/book_code/simplify/swing_gui.rb +45 -0
  98. data/book_code/simplify/windows_gui.rb +232 -0
  99. data/book_code/simplify/windows_gui_spec.rb +35 -0
  100. data/book_code/story/invite.story +19 -0
  101. data/book_code/story/journal.txt +29 -0
  102. data/book_code/story/novite_stories.rb +156 -0
  103. data/book_code/story/party.rb +149 -0
  104. data/book_code/story/password.rb +61 -0
  105. data/book_code/story/password.story +26 -0
  106. data/book_code/story/rsvp.story +29 -0
  107. data/book_code/tables/TestTime.html +93 -0
  108. data/book_code/tables/TestTimeSample.html +63 -0
  109. data/book_code/tables/calculate_time.rb +39 -0
  110. data/book_code/tables/calculator.rb +108 -0
  111. data/book_code/tables/calculator_actions.rb +27 -0
  112. data/book_code/tables/calculator_spec.rb +47 -0
  113. data/book_code/tables/fit.rb +32 -0
  114. data/book_code/tables/matrix.rb +109 -0
  115. data/book_code/tables/pseudocode.rb +17 -0
  116. data/book_code/tubes/book_selenium.rb +67 -0
  117. data/book_code/tubes/book_watir.rb +60 -0
  118. data/book_code/tubes/dragdrop.html +81 -0
  119. data/book_code/tubes/html_capture.rb +33 -0
  120. data/book_code/tubes/joke_list.rb +67 -0
  121. data/book_code/tubes/list_spec.rb +41 -0
  122. data/book_code/tubes/search_spec.rb +32 -0
  123. data/book_code/tubes/selenium_example.rb +66 -0
  124. data/book_code/tubes/selenium_link.rb +23 -0
  125. data/book_code/tubes/web_server.rb +14 -0
  126. data/book_code/windows/wgui.rb +29 -0
  127. data/book_code/windows/wobj.rb +25 -0
  128. data/book_code/windows/wsh.rb +25 -0
  129. data/book_code/with_rspec/empty_spec.rb +13 -0
  130. data/book_code/with_rspec/junquenote.rb +60 -0
  131. data/book_code/with_rspec/locknote.rb +129 -0
  132. data/book_code/with_rspec/note_spec.rb +32 -0
  133. data/book_code/with_rspec/should_examples.rb +18 -0
  134. data/exp/exp.rb +6 -0
  135. data/exp/exp_encodings.rb +40 -0
  136. data/exp/exp_enum_windows.rb +60 -0
  137. data/exp/exp_quik.rb +38 -0
  138. data/exp/exp_wsh.rb +115 -0
  139. data/exp/old/windows_basics.rb +80 -0
  140. data/exp/old/wnote.rb +80 -0
  141. data/exp/old/wnote_spec.rb +20 -0
  142. data/features/step_definitions/win_gui_steps.rb +0 -0
  143. data/features/support/env.rb +4 -0
  144. data/features/win_gui.feature +9 -0
  145. data/lib/note/java/jemmy.jar +0 -0
  146. data/lib/note/java/jnote.rb +48 -0
  147. data/lib/note/java/jruby_basics.rb +37 -0
  148. data/lib/note/java/junquenote_app.rb +262 -0
  149. data/lib/note/java/note_spec.rb +20 -0
  150. data/lib/note/win/locknote.rb +19 -0
  151. data/lib/note.rb +15 -0
  152. data/lib/win_gui/constants.rb +66 -0
  153. data/lib/win_gui/string_extensions.rb +24 -0
  154. data/lib/win_gui/win_gui.rb +274 -0
  155. data/lib/win_gui/window.rb +70 -0
  156. data/lib/win_gui.rb +3 -0
  157. data/spec/note/win/locknote_spec.rb +7 -0
  158. data/spec/spec.opts +2 -0
  159. data/spec/spec_helper.rb +100 -0
  160. data/spec/test_apps/locknote/LockNote.exe +0 -0
  161. data/spec/win_gui/string_extensions_spec.rb +61 -0
  162. data/spec/win_gui/win_gui_spec.rb +733 -0
  163. data/spec/win_gui/window_spec.rb +124 -0
  164. metadata +251 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/request'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/inspector'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/reaper'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/spawner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/server'
@@ -0,0 +1,46 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ ENV["RAILS_ENV"] = "test"
10
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
11
+ require 'test_help'
12
+
13
+ class Test::Unit::TestCase
14
+ # Transactional fixtures accelerate your tests by wrapping each test method
15
+ # in a transaction that's rolled back on completion. This ensures that the
16
+ # test database remains unchanged so your fixtures don't have to be reloaded
17
+ # between every test method. Fewer database queries means faster tests.
18
+ #
19
+ # Read Mike Clark's excellent walkthrough at
20
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
21
+ #
22
+ # Every Active Record database supports transactions except MyISAM tables
23
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
24
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
25
+ # is recommended.
26
+ #
27
+ # The only drawback to using transactional fixtures is when you actually
28
+ # need to test transactions. Since your test is bracketed by a transaction,
29
+ # any transactions started in your code will be automatically rolled back.
30
+ self.use_transactional_fixtures = true
31
+
32
+ # Instantiated fixtures are slow, but give you @david where otherwise you
33
+ # would need people(:david). If you don't want to migrate your existing
34
+ # test cases which use the @david style and don't mind the speed hit (each
35
+ # instantiated fixtures translates to a database query per test method),
36
+ # then set this back to true.
37
+ self.use_instantiated_fixtures = false
38
+
39
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
40
+ #
41
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
42
+ # -- they do not yet inherit this setting
43
+ fixtures :all
44
+
45
+ # Add more helper methods to be used by all tests here...
46
+ end
@@ -0,0 +1,68 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+
10
+ module AppleScript
11
+ class Command
12
+ def initialize #(1)
13
+ @lines = []
14
+ @tells = 0
15
+ end
16
+
17
+ def method_missing(name, *args, &block)
18
+ immediate = name.to_s.include? '!' #(2)
19
+ param = args.shift
20
+ script = name.to_s.chomp('!').gsub('_', ' ')
21
+ script += %Q( #{param.inspect}) if param
22
+
23
+ unless immediate #(3)
24
+ script = 'tell ' + script
25
+ @tells += 1
26
+ end
27
+
28
+ @lines << script
29
+
30
+ if block_given? #(4)
31
+ @has_block = true
32
+ instance_eval &block
33
+ go!
34
+ elsif immediate && !@has_block
35
+ go!
36
+ else
37
+ self
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+
45
+
46
+ module AppleScript
47
+ class Command
48
+ def go!
49
+ clauses = @lines.map do |line|
50
+ '-e "' + line.gsub('"', '\"') + '"'
51
+ end.join(' ') + ' '
52
+
53
+ clauses += '-e "end tell" ' * @tells
54
+
55
+ `osascript #{clauses}`.chomp("\n")
56
+ end
57
+ end
58
+ end
59
+
60
+
61
+
62
+
63
+ module AppleScript
64
+ def tell
65
+ Command.new
66
+ end
67
+ end
68
+
@@ -0,0 +1,50 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'spec_helper'
10
+
11
+ describe 'The editor' do
12
+ it_should_behave_like 'a new document'
13
+
14
+ it 'supports multiple levels of undo' do
15
+
16
+ @note.text = 'abc'
17
+ @note.text = 'def'
18
+
19
+ @note.undo
20
+ @note.text.should == 'abc'
21
+
22
+ @note.undo
23
+ @note.text.should be_empty
24
+
25
+ end
26
+
27
+ it 'supports copying and pasting text' do
28
+ @note.text = 'itchy'
29
+ @note.select_all
30
+ @note.copy
31
+ @note.text.should == 'itchy'
32
+
33
+ @note.text = 'scratchy'
34
+ @note.select_all
35
+ @note.paste
36
+ @note.text.should == 'itchy'
37
+ end
38
+
39
+ it 'supports cutting and pasting text' do
40
+ @note.text = 'pineapple'
41
+ @note.select_all
42
+ @note.cut
43
+ @note.text.should be_empty
44
+
45
+ @note.text = 'mango'
46
+ @note.select_all
47
+ @note.paste
48
+ @note.text.should == 'pineapple'
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ describe 'a new document', :shared => true do
10
+ before do
11
+ @note = Note.open
12
+ end
13
+
14
+ after do
15
+ @note.exit! if @note.running?
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'applescript'
10
+
11
+ include AppleScript
12
+
13
+ RightArrow = 124
14
+
15
+ tell.application("TextEdit").activate! #(1)
16
+
17
+ tell.application("System Events").
18
+ process("TextEdit").
19
+ menu_bar(1).
20
+ menu_bar_item("Edit"). #(2)
21
+ menu("Edit") do #(3)
22
+ keystroke! "H"
23
+ keystroke! "i"
24
+ click_menu_item! "Select All"
25
+ click_menu_item! "Copy"
26
+ key_code! RightArrow
27
+ click_menu_item! "Paste"
28
+ end
@@ -0,0 +1,26 @@
1
+ tell application "TextEdit"
2
+ activate
3
+ end tell
4
+
5
+ tell application "System Events"
6
+ tell process "TextEdit"
7
+ keystroke "H"
8
+ keystroke "i"
9
+ end tell
10
+ end tell
11
+
12
+ tell application "System Events"
13
+ tell process "TextEdit"
14
+ tell menu bar 1
15
+ tell menu bar item "Edit"
16
+ tell menu "Edit"
17
+ click menu item "Select All"
18
+ click menu item "Copy"
19
+ set rightArrow to 124
20
+ key code rightArrow
21
+ click menu item "Paste"
22
+ end tell
23
+ end tell
24
+ end tell
25
+ end tell
26
+ end tell
@@ -0,0 +1,32 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'rubygems'
10
+ require 'appscript'
11
+
12
+ include Appscript
13
+
14
+ app("TextEdit").activate
15
+
16
+ events = app("System Events")
17
+ events.keystroke "H"
18
+ events.keystroke "i"
19
+
20
+ edit = app('System Events').
21
+ processes['TextEdit'].
22
+ menu_bars[1].
23
+ menu_bar_items['Edit'].
24
+ menus['Edit']
25
+
26
+ edit.menu_items['Select All'].click
27
+ edit.menu_items['Copy'].click
28
+
29
+ RightArrow = 124
30
+ events.key_code RightArrow
31
+
32
+ edit.menu_items['Paste'].click
@@ -0,0 +1,87 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+
10
+ require 'applescript'
11
+ require 'note'
12
+
13
+ class TextNote < Note
14
+ include AppleScript
15
+
16
+ @@app = TextNote
17
+
18
+ def initialize(name = 'Untitled', with_options = {})
19
+ tell.application('TextEdit').activate!
20
+ end
21
+
22
+ DontSave = 2
23
+
24
+ def exit!
25
+ menu 'TextEdit', 'Quit TextEdit'
26
+
27
+ tell.
28
+ application('System Events').
29
+ process('TextEdit').
30
+ window('Untitled').
31
+ sheet(1).
32
+ click_button!(DontSave) #(1)
33
+ end
34
+
35
+ def running?
36
+ tell.
37
+ application('System Events').
38
+ process!('TextEdit') == 'TextEdit' #(2)
39
+ end
40
+ end
41
+
42
+
43
+
44
+
45
+ class TextNote
46
+ def text
47
+ tell.
48
+ application('System Events').
49
+ process('TextEdit').
50
+ window('Untitled').
51
+ scroll_area(1).
52
+ text_area(1).
53
+ get_value!
54
+ end
55
+
56
+ def text=(new_text)
57
+ select_all
58
+
59
+ tell.application('System Events').
60
+ process('TextEdit').
61
+ window('Untitled') do
62
+ new_text.split(//).each {|k| keystroke! k}
63
+ end
64
+ end
65
+ end
66
+
67
+
68
+
69
+
70
+ class TextNote
71
+ def menu(name, item, wait = false)
72
+ tell.application('System Events').
73
+ process('TextEdit').
74
+ menu_bar(1).
75
+ menu_bar_item(name).
76
+ menu(name).
77
+ click_menu_item! item
78
+ end
79
+
80
+ def undo; menu('Edit', 1) end #(3)
81
+
82
+ def select_all; menu('Edit', 'Select All') end
83
+ def cut; menu('Edit', 'Cut') end
84
+ def copy; menu('Edit', 'Copy') end
85
+ def paste; menu('Edit', 'Paste') end
86
+ end
87
+
@@ -0,0 +1,48 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+
10
+ require 'swing_gui' #(1)
11
+ require 'junquenote_app'
12
+ require 'note'
13
+
14
+ class JunqueNote < Note
15
+ include SwingGui
16
+
17
+
18
+ @@app = JunqueNote
19
+ @@titles[:save] = "Quittin' time"
20
+
21
+
22
+ def initialize
23
+ JunqueNoteApp.new
24
+
25
+ @main_window = JFrameOperator.new 'JunqueNote'
26
+ @edit_window = JTextAreaOperator.new @main_window #(2)
27
+ end
28
+ end
29
+
30
+
31
+
32
+
33
+ class JunqueNote
34
+ def text
35
+ @edit_window.text
36
+ end
37
+
38
+ def text=(message)
39
+ @edit_window.clear_text
40
+ @edit_window.type_text message
41
+ end
42
+
43
+ def close
44
+ menu_bar = JMenuBarOperator.new @main_window
45
+ menu_bar.push_menu_no_block 'File|Exit', '|'
46
+ end
47
+ end
48
+
@@ -0,0 +1,46 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+
10
+ require 'windows_gui'
11
+ require 'note'
12
+
13
+ class LockNote < Note
14
+ include WindowsGui
15
+
16
+
17
+ @@app = LockNote
18
+ @@titles[:save] = 'Steganos LockNote'
19
+
20
+
21
+ def initialize
22
+ system 'start "" "C:/LockNote/LockNote.exe"'
23
+
24
+ @main_window = Window.top_level 'LockNote - Steganos LockNote'
25
+ @edit_window = @main_window.child 'ATL:00434310'
26
+ end
27
+ end
28
+
29
+
30
+
31
+ class LockNote
32
+ def text
33
+ @edit_window.text
34
+ end
35
+
36
+ def text=(message)
37
+ keystroke VK_CONTROL, ?A
38
+ keystroke VK_BACK
39
+ type_in(message)
40
+ end
41
+
42
+ def close
43
+ @main_window.close
44
+ end
45
+ end
46
+
@@ -0,0 +1,35 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+
10
+ class Note
11
+ @@app = nil #(1)
12
+ @@titles = {} #(2)
13
+
14
+ def self.open
15
+ @@app.new
16
+ end
17
+ end
18
+
19
+
20
+
21
+
22
+ class Note
23
+ def exit!
24
+ close
25
+
26
+ @prompted = dialog(@@titles[:save]) do |d| #(3)
27
+ d.click '_No'
28
+ end
29
+ end
30
+
31
+ def has_prompted?
32
+ @prompted
33
+ end
34
+ end
35
+
@@ -0,0 +1,28 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ describe 'The main window' do
10
+ it 'launches with a welcome message' do
11
+ note = Note.open
12
+ note.text.should include('Welcome')
13
+ note.exit!
14
+ end
15
+
16
+ it 'exits without a prompt if nothing has changed' do
17
+ note = Note.open
18
+ note.exit!
19
+ note.should_not have_prompted
20
+ end
21
+
22
+ it 'prompts before exiting if the document has changed' do
23
+ note = Note.open
24
+ note.text = 'changed'
25
+ note.exit!
26
+ note.should have_prompted
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'java'
10
+ require 'jemmy.jar'
11
+
12
+ include_class 'org.netbeans.jemmy.JemmyProperties'
13
+ include_class 'org.netbeans.jemmy.TestOut'
14
+
15
+ JemmyProperties.set_current_output TestOut.get_null_output
16
+
17
+ %w(Frame TextArea MenuBar Dialog Button).each do |o|
18
+ include_class "org.netbeans.jemmy.operators.J#{o}Operator"
19
+ end
20
+
21
+
22
+ class JDialogOperator
23
+ def click(title)
24
+ b = JButtonOperator.new self, title.gsub('_', '') #(1)
25
+ b.push
26
+ end
27
+ end
28
+
29
+
30
+
31
+ module SwingGui
32
+ def dialog(title, seconds=3)
33
+ JemmyProperties.set_current_timeout \
34
+ 'DialogWaiter.WaitDialogTimeout', seconds * 1000
35
+
36
+ begin
37
+ d = JDialogOperator.new title
38
+ yield d #(2)
39
+ d.wait_closed
40
+
41
+ true
42
+ rescue NativeException
43
+ end
44
+ end
45
+ end