watir-classic 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. data/CHANGES +721 -0
  2. data/LICENSE +34 -0
  3. data/README.rdoc +78 -0
  4. data/VERSION +1 -0
  5. data/bin/watir-console +5 -0
  6. data/lib/watir-classic.rb +14 -0
  7. data/lib/watir-classic/IEDialog/Release/IEDialog.dll +0 -0
  8. data/lib/watir-classic/assertions.rb +44 -0
  9. data/lib/watir-classic/browser.rb +149 -0
  10. data/lib/watir-classic/browsers.rb +7 -0
  11. data/lib/watir-classic/close_all.rb +31 -0
  12. data/lib/watir-classic/container.rb +110 -0
  13. data/lib/watir-classic/contrib/enabled_popup.rb +21 -0
  14. data/lib/watir-classic/contrib/ie-new-process.rb +27 -0
  15. data/lib/watir-classic/contrib/page_checker.rb +29 -0
  16. data/lib/watir-classic/cookies.rb +80 -0
  17. data/lib/watir-classic/core.rb +43 -0
  18. data/lib/watir-classic/dialogs/file_field.rb +34 -0
  19. data/lib/watir-classic/dialogs/javascript.rb +43 -0
  20. data/lib/watir-classic/drag_and_drop_helper.rb +68 -0
  21. data/lib/watir-classic/element.rb +438 -0
  22. data/lib/watir-classic/element_collection.rb +109 -0
  23. data/lib/watir-classic/element_extensions.rb +69 -0
  24. data/lib/watir-classic/exceptions.rb +50 -0
  25. data/lib/watir-classic/form.rb +96 -0
  26. data/lib/watir-classic/frame.rb +47 -0
  27. data/lib/watir-classic/ie-class.rb +767 -0
  28. data/lib/watir-classic/ie-process.rb +47 -0
  29. data/lib/watir-classic/ie.rb +20 -0
  30. data/lib/watir-classic/image.rb +111 -0
  31. data/lib/watir-classic/input_elements.rb +480 -0
  32. data/lib/watir-classic/irb-history.rb +31 -0
  33. data/lib/watir-classic/link.rb +46 -0
  34. data/lib/watir-classic/locator.rb +243 -0
  35. data/lib/watir-classic/logger.rb +19 -0
  36. data/lib/watir-classic/matches.rb +23 -0
  37. data/lib/watir-classic/modal_dialog.rb +72 -0
  38. data/lib/watir-classic/module.rb +12 -0
  39. data/lib/watir-classic/non_control_elements.rb +114 -0
  40. data/lib/watir-classic/options.rb +56 -0
  41. data/lib/watir-classic/page-container.rb +114 -0
  42. data/lib/watir-classic/process.rb +20 -0
  43. data/lib/watir-classic/screen_capture.rb +115 -0
  44. data/lib/watir-classic/supported_elements.rb +172 -0
  45. data/lib/watir-classic/table.rb +224 -0
  46. data/lib/watir-classic/testcase.rb +97 -0
  47. data/lib/watir-classic/util.rb +35 -0
  48. data/lib/watir-classic/version.rb +4 -0
  49. data/lib/watir-classic/wait.rb +41 -0
  50. data/lib/watir-classic/wait_helper.rb +12 -0
  51. data/lib/watir-classic/waiter.rb +98 -0
  52. data/lib/watir-classic/win32.rb +40 -0
  53. data/lib/watir-classic/win32ole.rb +16 -0
  54. data/lib/watir-classic/win32ole/1.8.7/win32ole.so +0 -0
  55. data/lib/watir-classic/win32ole/1.9.3/win32ole.so +0 -0
  56. data/lib/watir-classic/window.rb +68 -0
  57. data/lib/watir-classic/xpath_locator.rb +52 -0
  58. data/rakefile.rb +54 -0
  59. data/unittests/all_tests.rb +10 -0
  60. data/unittests/buttons_xpath_test.rb +68 -0
  61. data/unittests/checkbox_test.rb +163 -0
  62. data/unittests/checkbox_xpath_test.rb +106 -0
  63. data/unittests/click_no_wait_test.rb +23 -0
  64. data/unittests/close_all_test.rb +17 -0
  65. data/unittests/core_tests.rb +17 -0
  66. data/unittests/css_selector_test.rb +44 -0
  67. data/unittests/css_test.rb +38 -0
  68. data/unittests/dialog_test.rb +64 -0
  69. data/unittests/div2_xpath_test.rb +21 -0
  70. data/unittests/div_test.rb +170 -0
  71. data/unittests/div_xpath_test.rb +95 -0
  72. data/unittests/document_standards.rb +63 -0
  73. data/unittests/element_collection_indexes_test.rb +57 -0
  74. data/unittests/element_collections_test.rb +100 -0
  75. data/unittests/element_test.rb +47 -0
  76. data/unittests/errorchecker_test.rb +31 -0
  77. data/unittests/filefield_test.rb +43 -0
  78. data/unittests/filefield_xpath_test.rb +35 -0
  79. data/unittests/form_test.rb +282 -0
  80. data/unittests/form_xpath_test.rb +254 -0
  81. data/unittests/frame_test.rb +165 -0
  82. data/unittests/google_form_test.rb +15 -0
  83. data/unittests/html/JavascriptClick.html +39 -0
  84. data/unittests/html/blankpage.html +11 -0
  85. data/unittests/html/buttons1.html +40 -0
  86. data/unittests/html/checkboxes1.html +89 -0
  87. data/unittests/html/click_no_wait.html +14 -0
  88. data/unittests/html/complex_table.html +35 -0
  89. data/unittests/html/cssTest.html +42 -0
  90. data/unittests/html/depot_store.html +59 -0
  91. data/unittests/html/div.html +92 -0
  92. data/unittests/html/div_xml.html +21 -0
  93. data/unittests/html/fileupload.html +44 -0
  94. data/unittests/html/formTest1.html +38 -0
  95. data/unittests/html/forms2.html +44 -0
  96. data/unittests/html/forms3.html +131 -0
  97. data/unittests/html/forms4.html +26 -0
  98. data/unittests/html/frame_buttons.html +4 -0
  99. data/unittests/html/frame_links.html +4 -0
  100. data/unittests/html/frame_multi.html +5 -0
  101. data/unittests/html/google_india.html +119 -0
  102. data/unittests/html/ie7_document_standards.html +9 -0
  103. data/unittests/html/ie8_document_standards.html +9 -0
  104. data/unittests/html/ie9_document_standards.html +9 -0
  105. data/unittests/html/iframe.html +3 -0
  106. data/unittests/html/iframeTest.html +17 -0
  107. data/unittests/html/iframeTest1.html +7 -0
  108. data/unittests/html/iframeTest2.html +5 -0
  109. data/unittests/html/images/1.gif +0 -0
  110. data/unittests/html/images/2.GIF +0 -0
  111. data/unittests/html/images/3.GIF +0 -0
  112. data/unittests/html/images/button.jpg +0 -0
  113. data/unittests/html/images/circle.jpg +0 -0
  114. data/unittests/html/images/map.GIF +0 -0
  115. data/unittests/html/images/map2.gif +0 -0
  116. data/unittests/html/images/minus.GIF +0 -0
  117. data/unittests/html/images/originaltriangle.jpg +0 -0
  118. data/unittests/html/images/plus.gif +0 -0
  119. data/unittests/html/images/square.jpg +0 -0
  120. data/unittests/html/images/triangle.jpg +0 -0
  121. data/unittests/html/images1.html +65 -0
  122. data/unittests/html/javascriptevents.html +33 -0
  123. data/unittests/html/link_pass.html +11 -0
  124. data/unittests/html/links1.html +37 -0
  125. data/unittests/html/links2.html +11 -0
  126. data/unittests/html/links_multi.html +12 -0
  127. data/unittests/html/list_matters.html +720 -0
  128. data/unittests/html/lists.html +18 -0
  129. data/unittests/html/map_test.html +30 -0
  130. data/unittests/html/modal_dialog.html +10 -0
  131. data/unittests/html/modal_dialog_launcher.html +12 -0
  132. data/unittests/html/multiple_specifiers.html +64 -0
  133. data/unittests/html/nestedFrames.html +6 -0
  134. data/unittests/html/new_browser.html +17 -0
  135. data/unittests/html/pass.html +13 -0
  136. data/unittests/html/popups1.html +59 -0
  137. data/unittests/html/pre.html +29 -0
  138. data/unittests/html/quirks_document_standards.html +8 -0
  139. data/unittests/html/radioButtons1.html +71 -0
  140. data/unittests/html/select_tealeaf.html +54 -0
  141. data/unittests/html/selectboxes1.html +52 -0
  142. data/unittests/html/simple_table.html +25 -0
  143. data/unittests/html/simple_table_buttons.html +104 -0
  144. data/unittests/html/simple_table_columns.html +75 -0
  145. data/unittests/html/table1.html +179 -0
  146. data/unittests/html/tableCell_using_xpath.html +19 -0
  147. data/unittests/html/table_and_tablerow_to_a.html +174 -0
  148. data/unittests/html/textarea.html +30 -0
  149. data/unittests/html/textfields1.html +100 -0
  150. data/unittests/html/textsearch.html +44 -0
  151. data/unittests/html/wallofcheckboxes.html +1003 -0
  152. data/unittests/html/xpath_nbsp.html +11 -0
  153. data/unittests/html/zeroindex.html +11 -0
  154. data/unittests/ie_exists_test.rb +16 -0
  155. data/unittests/ie_mock.rb +94 -0
  156. data/unittests/ie_test.rb +54 -0
  157. data/unittests/images_test.rb +156 -0
  158. data/unittests/images_xpath_test.rb +90 -0
  159. data/unittests/index_specifier_test.rb +31 -0
  160. data/unittests/js_events_test.rb +31 -0
  161. data/unittests/links_multi_test.rb +34 -0
  162. data/unittests/links_test.rb +131 -0
  163. data/unittests/links_xpath_test.rb +38 -0
  164. data/unittests/lists_test.rb +23 -0
  165. data/unittests/map_test.rb +98 -0
  166. data/unittests/minmax_test.rb +37 -0
  167. data/unittests/navigate_test.rb +38 -0
  168. data/unittests/nbsp_xpath_test.rb +16 -0
  169. data/unittests/no_wait_test.rb +28 -0
  170. data/unittests/non_core_tests.rb +12 -0
  171. data/unittests/other/all_tests_concurrent.rb +57 -0
  172. data/unittests/other/navigate_exception_test.rb +24 -0
  173. data/unittests/other/rexml_unit_test.rb +27 -0
  174. data/unittests/other/screen_capture_test.rb +53 -0
  175. data/unittests/other/testcase_method_order_test.rb +36 -0
  176. data/unittests/other/testcase_verify_test.rb +25 -0
  177. data/unittests/other/wait_until_test.rb +102 -0
  178. data/unittests/pagecontainstext_test.rb +69 -0
  179. data/unittests/parent_child_test.rb +27 -0
  180. data/unittests/perf_test.rb +20 -0
  181. data/unittests/pre_test.rb +49 -0
  182. data/unittests/radios_test.rb +181 -0
  183. data/unittests/radios_xpath_test.rb +100 -0
  184. data/unittests/security_setting_test.rb +24 -0
  185. data/unittests/selectbox_test.rb +144 -0
  186. data/unittests/selectbox_xpath_test.rb +102 -0
  187. data/unittests/setup.rb +69 -0
  188. data/unittests/speed_settings_test.rb +67 -0
  189. data/unittests/table_cell_using_xpath_test.rb +34 -0
  190. data/unittests/table_test.rb +296 -0
  191. data/unittests/table_xpath_test.rb +109 -0
  192. data/unittests/test_tests.rb +9 -0
  193. data/unittests/textarea_test.rb +92 -0
  194. data/unittests/textarea_xpath_test.rb +77 -0
  195. data/unittests/textfield_for_ch_char_test.rb +32 -0
  196. data/unittests/textfields_test.rb +184 -0
  197. data/unittests/textfields_xpath_test.rb +110 -0
  198. data/unittests/version_test.rb +15 -0
  199. data/unittests/win32ole_so_test.rb +35 -0
  200. data/unittests/window_tests.rb +10 -0
  201. data/unittests/windows/attach_to_existing_window_test.rb +52 -0
  202. data/unittests/windows/attach_to_new_window_test.rb +74 -0
  203. data/unittests/windows/close_window_test.rb +20 -0
  204. data/unittests/windows/frame_links_test.rb +23 -0
  205. data/unittests/windows/ie-each_test.rb +46 -0
  206. data/unittests/windows/modal_dialog_test.rb +95 -0
  207. data/unittests/windows/new_process_test.rb +24 -0
  208. data/unittests/windows/new_test.rb +58 -0
  209. data/unittests/windows/open_close_test.rb +19 -0
  210. data/unittests/windows/send_keys_test.rb +26 -0
  211. data/unittests/xpath_tests.rb +11 -0
  212. data/watir-rdoc.rb +7 -0
  213. metadata +370 -0
@@ -0,0 +1,114 @@
1
+ module Watir
2
+ class Area < Element
3
+ attr_ole :alt
4
+ attr_ole :type
5
+ attr_ole :href
6
+ end
7
+
8
+ class Audio < Element
9
+ attr_ole :src
10
+ end
11
+
12
+ class Base < Element
13
+ attr_ole :href
14
+ end
15
+
16
+ class Command < Element
17
+ attr_ole :disabled?
18
+ attr_ole :type
19
+ end
20
+
21
+ class Data < Element
22
+ attr_ole :value
23
+ end
24
+
25
+ class Embed < Element
26
+ attr_ole :src
27
+ attr_ole :type
28
+ end
29
+
30
+ class FieldSet < Element
31
+ attr_ole :name
32
+ attr_ole :disabled?
33
+ end
34
+
35
+ class Font < Element
36
+ attr_ole :color
37
+ attr_ole :face
38
+ attr_ole :size
39
+ end
40
+
41
+ class Keygen < Element
42
+ attr_ole :name
43
+ attr_ole :disabled?
44
+ end
45
+
46
+ class Label < Element
47
+ attr_ole :for, :htmlFor
48
+ end
49
+
50
+ class Li < Element
51
+ attr_ole :value
52
+ end
53
+
54
+ class Map < Element
55
+ attr_ole :name
56
+ end
57
+
58
+ class Menu < Element
59
+ attr_ole :type
60
+ end
61
+
62
+ class Meta < Element
63
+ attr_ole :http_equiv, :httpEquiv
64
+ attr_ole :content
65
+ attr_ole :name
66
+ end
67
+
68
+ class Meter < Element
69
+ attr_ole :value
70
+ end
71
+
72
+ class Object < Element
73
+ attr_ole :name
74
+ attr_ole :type
75
+ end
76
+
77
+ class Optgroup < Element
78
+ attr_ole :disabled?
79
+ end
80
+
81
+ class Output < Element
82
+ attr_ole :name
83
+ end
84
+
85
+ class Param < Element
86
+ attr_ole :name
87
+ attr_ole :value
88
+ end
89
+
90
+ class Progress < Element
91
+ attr_ole :value
92
+ end
93
+
94
+ class Script < Element
95
+ attr_ole :src
96
+ attr_ole :type
97
+ end
98
+
99
+ class Source < Element
100
+ attr_ole :type
101
+ end
102
+
103
+ class Style < Element
104
+ attr_ole :type
105
+ end
106
+
107
+ class Track < Element
108
+ attr_ole :src
109
+ end
110
+
111
+ class Video < Element
112
+ attr_ole :src
113
+ end
114
+ end
@@ -0,0 +1,56 @@
1
+ #--
2
+ # watir/options
3
+ require 'rubygems'
4
+
5
+ require 'user-choices'
6
+
7
+ module Watir
8
+ @@options_file = nil
9
+ @@options = nil
10
+ class << self
11
+ # Specify the location of a yaml file containing Watir options. Must be
12
+ # specified before the options are parsed.
13
+ def options_file= file
14
+ @@options_file = file
15
+ end
16
+ def options_file
17
+ @@options_file
18
+ end
19
+ def options= x
20
+ @@options = x
21
+ end
22
+ # Return the Watir options, as a hash. If they haven't been parsed yet,
23
+ # they will be now.
24
+ def options
25
+ @@options ||= Watir::WatirOptions.new.execute
26
+ end
27
+ end
28
+
29
+ class WatirOptions < UserChoices::Command
30
+ include UserChoices
31
+ def add_sources builder
32
+ builder.add_source EnvironmentSource, :with_prefix, 'watir_'
33
+ if Watir.options_file
34
+ builder.add_source YamlConfigFileSource, :from_complete_path,
35
+ Watir.options_file
36
+ end
37
+ end
38
+ def add_choices builder
39
+ builder.add_choice :browser,
40
+ :type => Watir::Browser.browser_names,
41
+ :default => Watir::Browser.default
42
+ builder.add_choice :speed,
43
+ :type => ['slow', 'fast', 'zippy'],
44
+ :default => 'fast'
45
+ builder.add_choice :visible,
46
+ :type => :boolean
47
+ builder.add_choice :zero_based_indexing,
48
+ :type => :boolean,
49
+ :default => true
50
+ end
51
+ def execute
52
+ @user_choices[:speed] = @user_choices[:speed].to_sym
53
+ @user_choices
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,114 @@
1
+ module Watir
2
+ # A PageContainer contains an HTML Document. In other words, it is a
3
+ # what JavaScript calls a Window.
4
+ module PageContainer
5
+ include Watir::Exception
6
+
7
+ # This method checks the currently displayed page for http errors, 404, 500 etc
8
+ # It gets called internally by the wait method, so a user does not need to call it explicitly
9
+
10
+ def check_for_http_error
11
+ # check for IE7
12
+ n = self.document.invoke('parentWindow').navigator.appVersion
13
+ m=/MSIE\s(.*?);/.match( n )
14
+ if m and m[1] =='7.0'
15
+ if m = /HTTP (\d\d\d.*)/.match( self.title )
16
+ raise NavigationException, m[1]
17
+ end
18
+ else
19
+ # assume its IE6
20
+ url = self.document.location.href
21
+ if /shdoclc.dll/.match(url)
22
+ m = /id=IEText.*?>(.*?)</i.match(self.html)
23
+ raise NavigationException, m[1] if m
24
+ end
25
+ end
26
+ false
27
+ end
28
+
29
+ # The HTML Page
30
+ def page
31
+ document.documentelement
32
+ end
33
+
34
+ private :page
35
+
36
+ # Execute the given JavaScript string
37
+ def execute_script(source)
38
+ result = nil
39
+ begin
40
+ source = "(function() {#{source}})()"
41
+ result = document.parentWindow.eval(source)
42
+ rescue WIN32OLERuntimeError, NoMethodError #if eval fails we need to use execScript(source.to_s) which does not return a value, hence the workaround
43
+ escaped_src = source.gsub(/[\r\n']/) {|m| "\\#{m}"}
44
+ wrapper = "_watir_helper_div_#{::Time.now.to_i + ::Time.now.usec}"
45
+ cmd = "var e = document.createElement('DIV'); e.style.display='none'; e.id='#{wrapper}'; e.innerHTML = eval('#{escaped_src}'); document.body.appendChild(e);"
46
+ document.parentWindow.execScript(cmd)
47
+ result = document.getElementById(wrapper).innerHTML
48
+ end
49
+
50
+ result == "undefined" ? nil : result
51
+ end
52
+
53
+ # The HTML of the current page
54
+ def html
55
+ page.outerhtml
56
+ end
57
+
58
+ # The url of the page object.
59
+ def url
60
+ page.document.location.href
61
+ end
62
+
63
+ # The text of the current page
64
+ def text
65
+ page.innertext.strip
66
+ end
67
+
68
+ def set_container container
69
+ @container = container
70
+ @page_container = self
71
+ end
72
+
73
+ # This method is used to display the available html frames that Internet Explorer currently has loaded.
74
+ # This method is usually only used for debugging test scripts.
75
+ def show_frames
76
+ if allFrames = document.frames
77
+ count = allFrames.length
78
+ puts "there are #{count} frames"
79
+ for i in 0..count-1 do
80
+ begin
81
+ fname = allFrames.item(i).name.to_s
82
+ puts "frame index: #{i + 1} name: #{fname}"
83
+ rescue => e
84
+ if e.to_s.match(/Access is denied/)
85
+ puts "frame index: #{i + 1} Access Denied, see http://wiki.openqa.org/display/WTR/FAQ#access-denied"
86
+ end
87
+ end
88
+ end
89
+ else
90
+ puts "no frames"
91
+ end
92
+ end
93
+
94
+ # Search the current page for specified text or regexp.
95
+ # Returns the index if the specified text was found.
96
+ # Returns matchdata object if the specified regexp was found.
97
+ #
98
+ # *Deprecated*
99
+ # Instead use
100
+ # IE#text.include? target
101
+ # or
102
+ # IE#text.match target
103
+ def contains_text(target)
104
+ if target.kind_of? Regexp
105
+ self.text.match(target)
106
+ elsif target.kind_of? String
107
+ self.text.index(target)
108
+ else
109
+ raise ArgumentError, "Argument #{target} should be a string or regexp."
110
+ end
111
+ end
112
+
113
+ end # module
114
+ end
@@ -0,0 +1,20 @@
1
+ module Watir
2
+ module Process
3
+
4
+ # Returns the number of windows processes running with the specified name.
5
+ def self.count name
6
+ mgmt = WIN32OLE.connect('winmgmts:\\\\.')
7
+ processes = mgmt.InstancesOf('win32_process')
8
+ processes.extend Enumerable
9
+ processes.select{|x| x.name == name}.length
10
+ end
11
+
12
+ end
13
+
14
+ class IE
15
+ # Returns the number of IEXPLORE processes currently running.
16
+ def self.process_count
17
+ Watir::Process.count 'iexplore.exe'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,115 @@
1
+
2
+ require 'Win32API'
3
+
4
+ module Watir
5
+ module ScreenCapture
6
+
7
+ KEYEVENTF_KEYUP = 0x2
8
+ SW_HIDE = 0
9
+ SW_SHOW = 5
10
+ SW_SHOWNORMAL = 1
11
+ VK_CONTROL = 0x11
12
+ VK_F4 = 0x73
13
+ VK_MENU = 0x12
14
+ VK_RETURN = 0x0D
15
+ VK_SHIFT = 0x10
16
+ VK_SNAPSHOT = 0x2C
17
+ VK_TAB = 0x09
18
+ GMEM_MOVEABLE = 0x0002
19
+ CF_TEXT = 1
20
+
21
+ # this method saves the current window or whole screen as either a bitmap or a jpeg
22
+ # It uses paint to save the file, so will barf if a duplicate filename is selected, or the path doesnt exist etc
23
+ # * filename - string - the name of the file to save. If its not fully qualified the current directory is used
24
+ # * active_window - boolean - if true, the whole screen is captured, if false, just the active window is captured
25
+ # * save_as_bmp - boolean - if true saves the file as a bitmap, saves it as a jpeg otherwise
26
+ def screen_capture(filename , active_window_only=false, save_as_bmp=false)
27
+
28
+
29
+ keybd_event = Win32API.new("user32", "keybd_event", ['I','I','L','L'], 'V')
30
+ vkKeyScan = Win32API.new("user32", "VkKeyScan", ['I'], 'I')
31
+ winExec = Win32API.new("kernel32", "WinExec", ['P','L'], 'L')
32
+ openClipboard = Win32API.new('user32', 'OpenClipboard', ['L'], 'I')
33
+ setClipboardData = Win32API.new('user32', 'SetClipboardData', ['I', 'I'], 'I')
34
+ closeClipboard = Win32API.new('user32', 'CloseClipboard', [], 'I')
35
+ globalAlloc = Win32API.new('kernel32', 'GlobalAlloc', ['I', 'I'], 'I')
36
+ globalLock = Win32API.new('kernel32', 'GlobalLock', ['I'], 'I')
37
+ globalUnlock = Win32API.new('kernel32', 'GlobalUnlock', ['I'], 'I')
38
+ memcpy = Win32API.new('msvcrt', 'memcpy', ['I', 'P', 'I'], 'I')
39
+
40
+
41
+ filename = Dir.getwd.tr('/','\\') + '\\' + filename unless filename.index('\\')
42
+
43
+ if active_window_only ==false
44
+ keybd_event.Call(VK_SNAPSHOT,0,0,0) # Print Screen
45
+ else
46
+ keybd_event.Call(VK_SNAPSHOT,1,0,0) # Alt+Print Screen
47
+ end
48
+
49
+ winExec.Call('mspaint.exe', SW_SHOW)
50
+ sleep(1)
51
+
52
+ # Ctrl + V : Paste
53
+ keybd_event.Call(VK_CONTROL, 1, 0, 0)
54
+ keybd_event.Call(vkKeyScan.Call(?V), 1, 0, 0)
55
+ keybd_event.Call(vkKeyScan.Call(?V), 1, KEYEVENTF_KEYUP, 0)
56
+ keybd_event.Call(VK_CONTROL, 1, KEYEVENTF_KEYUP, 0)
57
+
58
+
59
+ # Alt F + A : Save As
60
+ keybd_event.Call(VK_MENU, 1, 0, 0)
61
+ keybd_event.Call(vkKeyScan.Call(?F), 1, 0, 0)
62
+ keybd_event.Call(vkKeyScan.Call(?F), 1, KEYEVENTF_KEYUP, 0)
63
+ keybd_event.Call(VK_MENU, 1, KEYEVENTF_KEYUP, 0)
64
+ keybd_event.Call(vkKeyScan.Call(?A), 1, 0, 0)
65
+ keybd_event.Call(vkKeyScan.Call(?A), 1, KEYEVENTF_KEYUP, 0)
66
+ sleep(1)
67
+
68
+ # copy filename to clipboard
69
+ hmem = globalAlloc.Call(GMEM_MOVEABLE, filename.length+1)
70
+ mem = globalLock.Call(hmem)
71
+ memcpy.Call(mem, filename, filename.length+1)
72
+ globalUnlock.Call(hmem)
73
+ openClipboard.Call(0)
74
+ setClipboardData.Call(CF_TEXT, hmem)
75
+ closeClipboard.Call
76
+ sleep(1)
77
+
78
+ # Ctrl + V : Paste
79
+ keybd_event.Call(VK_CONTROL, 1, 0, 0)
80
+ keybd_event.Call(vkKeyScan.Call(?V), 1, 0, 0)
81
+ keybd_event.Call(vkKeyScan.Call(?V), 1, KEYEVENTF_KEYUP, 0)
82
+ keybd_event.Call(VK_CONTROL, 1, KEYEVENTF_KEYUP, 0)
83
+
84
+ if save_as_bmp == false
85
+ # goto the combo box
86
+ keybd_event.Call(VK_TAB, 1, 0, 0)
87
+ keybd_event.Call(VK_TAB, 1, KEYEVENTF_KEYUP, 0)
88
+ sleep(0.5)
89
+
90
+ # select the first entry with J
91
+ keybd_event.Call(vkKeyScan.Call(?J), 1, 0, 0)
92
+ keybd_event.Call(vkKeyScan.Call(?J), 1, KEYEVENTF_KEYUP, 0)
93
+ sleep(0.5)
94
+ end
95
+
96
+ # Enter key
97
+ keybd_event.Call(VK_RETURN, 1, 0, 0)
98
+ keybd_event.Call(VK_RETURN, 1, KEYEVENTF_KEYUP, 0)
99
+ sleep(1)
100
+
101
+ # Alt + F4 : Exit
102
+ keybd_event.Call(VK_MENU, 1, 0, 0)
103
+ keybd_event.Call(VK_F4, 1, 0, 0)
104
+ keybd_event.Call(VK_F4, 1, KEYEVENTF_KEYUP, 0)
105
+ keybd_event.Call(VK_MENU, 1, KEYEVENTF_KEYUP, 0)
106
+ sleep(1)
107
+
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+
114
+ #screenCapture( "f.bmp", false , true)
115
+
@@ -0,0 +1,172 @@
1
+ module Watir
2
+ module Container
3
+
4
+ class << self
5
+ def support_element method_name, args={}
6
+ klass = args[:class] || method_name.to_s.capitalize
7
+ super_class = args[:super_class] || "Element"
8
+
9
+ unless Watir.const_defined? klass
10
+ Watir.class_eval %Q[class #{klass} < #{super_class}; end]
11
+ end
12
+
13
+ unless Watir.const_defined? "#{klass}Collection"
14
+ Watir.class_eval %Q[class #{klass}Collection < #{args[:super_collection] || super_class}Collection; end]
15
+ end
16
+
17
+ tag_name = args[:tag_name] || method_name
18
+
19
+ Watir::Container.module_eval %Q[
20
+ def #{method_name}(how={}, what=nil)
21
+ #{klass}.new(self, format_specifiers(#{tag_name.inspect}, how, what))
22
+ end
23
+
24
+ def #{args.delete(:plural) || method_name.to_s + "s"}(how={}, what=nil)
25
+ specifiers = format_specifiers(#{tag_name.inspect}, how, what)
26
+ #{klass}Collection.new(self, specifiers)
27
+ end
28
+ ]
29
+ end
30
+
31
+ private :support_element
32
+ end
33
+
34
+ def format_specifiers(tag_name, how, what)
35
+ defaults = {:tag_name => [tag_name].flatten.map(&:to_s)}
36
+ formatted_specifiers = defaults.merge(what ? {how => what} : how)
37
+ if (formatted_specifiers[:css] || formatted_specifiers[:xpath]) && formatted_specifiers.size > 2
38
+ raise ArgumentError, ":xpath and :css specifiers should be the only one when used in #{formatted_specifiers.inspect}"
39
+ end
40
+ formatted_specifiers
41
+ end
42
+
43
+ private :format_specifiers
44
+
45
+ support_element :a, :class => :Link
46
+ alias_method :link, :a
47
+ alias_method :links, :as
48
+ support_element :abbr
49
+ support_element :address, :plural => :addresses
50
+ support_element :area
51
+ support_element :article
52
+ support_element :aside
53
+ support_element :audio
54
+ support_element :b
55
+ support_element :base
56
+ support_element :bdi
57
+ support_element :bdo
58
+ support_element :blockquote
59
+ support_element :body
60
+ support_element :br
61
+ support_element :button, :tag_name => [:button, :submit, :image, :reset], :super_class => :InputElement
62
+ support_element :canvas, :plural => :canvases
63
+ support_element :caption
64
+ support_element :checkbox, :plural => :checkboxes, :class => :CheckBox, :super_class => :InputElement
65
+ support_element :cite
66
+ support_element :code
67
+ support_element :col
68
+ support_element :colgroup
69
+ support_element :command
70
+ support_element :data
71
+ support_element :datalist
72
+ support_element :dd
73
+ support_element :del
74
+ support_element :details, :plural => :detailses
75
+ support_element :dfn
76
+ support_element :div
77
+ support_element :dl
78
+ support_element :dt
79
+ support_element :element, :tag_name => "*", :class => :HTMLElement
80
+ support_element :em
81
+ support_element :embed
82
+ support_element :fieldset, :class => :FieldSet
83
+ alias_method :field_set, :fieldset
84
+ alias_method :field_sets, :fieldsets
85
+ support_element :figcaption
86
+ support_element :figure
87
+ support_element :file_field, :tag_name => :file, :class => :FileField, :super_collection => :InputElement
88
+ support_element :font
89
+ support_element :footer
90
+ support_element :form
91
+ support_element :frame, :tag_name => [:frame, :iframe]
92
+ alias_method :iframe, :frame
93
+ alias_method :iframes, :frames
94
+ support_element :frameset
95
+ support_element :h1
96
+ support_element :h2
97
+ support_element :h3
98
+ support_element :h4
99
+ support_element :h5
100
+ support_element :h6
101
+ support_element :head
102
+ support_element :header
103
+ support_element :hgroup
104
+ support_element :hidden, :super_class => :TextField, :super_collection => :InputElement
105
+ support_element :hr
106
+ # html and htmls?!
107
+ support_element :i
108
+ support_element :img, :class => :Image
109
+ alias_method :image, :img
110
+ alias_method :images, :imgs
111
+ support_element :input, :super_class => :InputElement
112
+ support_element :ins, :plural => :inses
113
+ support_element :kbd
114
+ support_element :keygen
115
+ support_element :label
116
+ support_element :legend
117
+ support_element :li
118
+ support_element :map
119
+ support_element :mark
120
+ support_element :menu
121
+ support_element :meta
122
+ support_element :meter
123
+ support_element :nav
124
+ support_element :noscript
125
+ support_element :object
126
+ support_element :ol
127
+ support_element :optgroup
128
+ support_element :option
129
+ support_element :output
130
+ support_element :p
131
+ support_element :param
132
+ support_element :pre
133
+ support_element :progress, :plural => :progresses
134
+ support_element :q
135
+ support_element :radio, :super_class => :InputElement
136
+ support_element :rp
137
+ support_element :rt
138
+ support_element :ruby, :plural => :rubies
139
+ support_element :s
140
+ support_element :samp
141
+ support_element :script
142
+ support_element :section
143
+ support_element :select, :class => :SelectList, :super_class => :InputElement
144
+ alias_method :select_list, :select
145
+ alias_method :select_lists, :selects
146
+ support_element :small
147
+ support_element :source
148
+ support_element :span
149
+ support_element :strong
150
+ support_element :style
151
+ support_element :sub
152
+ support_element :summary, :plural => :summaries
153
+ support_element :sup
154
+ support_element :table
155
+ support_element :tbody, :class => :TableSection
156
+ support_element :td, :tag_name => [:th, :td], :class => :TableCell
157
+ support_element :text_field, :tag_name => [:text, :password, :textarea], :class => :TextField, :super_class => :InputElement
158
+ support_element :textarea, :class => :TextArea, :super_class => :TextField, :super_collection => :InputElement
159
+ support_element :tfoot, :class => :TableSection
160
+ support_element :th
161
+ support_element :thead, :class => :TableSection
162
+ support_element :time
163
+ support_element :title
164
+ support_element :tr, :class => :TableRow
165
+ support_element :track
166
+ support_element :u
167
+ support_element :ul
168
+ support_element :var
169
+ support_element :video
170
+ support_element :wbr
171
+ end
172
+ end