watir 1.6.2 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/CHANGES +326 -188
  2. data/bin/watir-console +7 -8
  3. data/lib/changes.rb +3 -3
  4. data/lib/license.rb +38 -38
  5. data/lib/readme.rb +140 -140
  6. data/lib/watir/WindowHelper.rb +49 -49
  7. data/lib/watir/camel_case.rb +66 -45
  8. data/lib/watir/clickJSDialog.rb +19 -19
  9. data/lib/watir/close_all.rb +37 -37
  10. data/lib/watir/collections.rb +344 -312
  11. data/lib/watir/container.rb +815 -753
  12. data/lib/watir/contrib/enabled_popup.rb +20 -20
  13. data/lib/watir/contrib/ie-new-process.rb +27 -27
  14. data/lib/watir/contrib/page_checker.rb +29 -29
  15. data/lib/watir/cookiemanager.rb +55 -55
  16. data/lib/watir/core_ext.rb +18 -0
  17. data/lib/watir/datahandler.rb +107 -107
  18. data/lib/watir/dialog.rb +46 -46
  19. data/lib/watir/element.rb +343 -312
  20. data/lib/watir/element_collections.rb +97 -81
  21. data/lib/watir/form.rb +170 -170
  22. data/lib/watir/frame.rb +59 -59
  23. data/lib/watir/ie-class.rb +1009 -1003
  24. data/lib/watir/ie-process.rb +39 -39
  25. data/lib/watir/ie.rb +133 -132
  26. data/lib/watir/image.rb +130 -130
  27. data/lib/watir/input_elements.rb +572 -539
  28. data/lib/watir/irb-history.rb +30 -30
  29. data/lib/watir/link.rb +64 -64
  30. data/lib/watir/locator.rb +176 -161
  31. data/lib/watir/logger.rb +19 -19
  32. data/lib/watir/modal_dialog.rb +122 -122
  33. data/lib/watir/non_control_elements.rb +145 -127
  34. data/lib/watir/page-container.rb +107 -105
  35. data/lib/watir/popup.rb +29 -29
  36. data/lib/watir/process.rb +19 -19
  37. data/lib/watir/screen_capture.rb +115 -115
  38. data/lib/watir/setFileDialog.rb +16 -16
  39. data/lib/watir/table.rb +362 -362
  40. data/lib/watir/utils.rb +19 -19
  41. data/lib/watir/version.rb +5 -5
  42. data/lib/watir/watir_simple.rb +475 -475
  43. data/lib/watir/win32.rb +35 -28
  44. data/lib/watir/win32ole.rb +14 -6
  45. data/lib/watir/winClicker.rb +496 -479
  46. data/unittests/all_tests.rb +10 -10
  47. data/unittests/buttons_xpath_test.rb +69 -69
  48. data/unittests/checkbox_test.rb +179 -176
  49. data/unittests/checkbox_xpath_test.rb +107 -107
  50. data/unittests/core_tests.rb +17 -16
  51. data/unittests/css_test.rb +35 -35
  52. data/unittests/defer_test.rb +46 -46
  53. data/unittests/dialog_test.rb +77 -77
  54. data/unittests/div2_xpath_test.rb +21 -21
  55. data/unittests/div_test.rb +188 -183
  56. data/unittests/div_xpath_test.rb +96 -96
  57. data/unittests/errorchecker_test.rb +22 -22
  58. data/unittests/filefield_test.rb +39 -40
  59. data/unittests/filefield_xpath_test.rb +33 -33
  60. data/unittests/form_test.rb +280 -293
  61. data/unittests/form_xpath_test.rb +252 -253
  62. data/unittests/frame_test.rb +155 -157
  63. data/unittests/google_form_test.rb +15 -15
  64. data/unittests/html/JavascriptClick.html +39 -39
  65. data/unittests/html/blankpage.html +11 -11
  66. data/unittests/html/buttons1.html +40 -40
  67. data/unittests/html/checkboxes1.html +89 -89
  68. data/unittests/html/complex_table.html +36 -36
  69. data/unittests/html/cssTest.html +42 -42
  70. data/unittests/html/depot_store.html +51 -51
  71. data/unittests/html/div.html +93 -93
  72. data/unittests/html/div_xml.html +20 -20
  73. data/unittests/html/fileupload.html +45 -45
  74. data/unittests/html/formTest1.html +38 -38
  75. data/unittests/html/forms2.html +44 -44
  76. data/unittests/html/forms3.html +131 -131
  77. data/unittests/html/forms4.html +27 -27
  78. data/unittests/html/frame_buttons.html +3 -3
  79. data/unittests/html/frame_links.html +3 -3
  80. data/unittests/html/frame_multi.html +4 -4
  81. data/unittests/html/google_india.html +107 -107
  82. data/unittests/html/iframeTest.html +12 -12
  83. data/unittests/html/iframeTest1.html +6 -6
  84. data/unittests/html/iframeTest2.html +5 -5
  85. data/unittests/html/images1.html +66 -66
  86. data/unittests/html/javascriptevents.html +35 -35
  87. data/unittests/html/link_pass.html +10 -10
  88. data/unittests/html/links1.html +38 -38
  89. data/unittests/html/links2.html +10 -10
  90. data/unittests/html/links_multi.html +14 -14
  91. data/unittests/html/list_matters.html +720 -720
  92. data/unittests/html/lists.html +17 -17
  93. data/unittests/html/map_test.html +31 -31
  94. data/unittests/html/modal_dialog.html +10 -10
  95. data/unittests/html/modal_dialog_launcher.html +11 -11
  96. data/unittests/html/nestedFrames.html +6 -6
  97. data/unittests/html/new_browser.html +16 -16
  98. data/unittests/html/pass.html +12 -12
  99. data/unittests/html/popups1.html +59 -59
  100. data/unittests/html/pre.html +27 -27
  101. data/unittests/html/radioButtons1.html +71 -71
  102. data/unittests/html/select_tealeaf.html +54 -54
  103. data/unittests/html/selectboxes1.html +52 -55
  104. data/unittests/html/simple_table.html +26 -26
  105. data/unittests/html/simple_table_buttons.html +104 -104
  106. data/unittests/html/simple_table_columns.html +76 -76
  107. data/unittests/html/table1.html +181 -181
  108. data/unittests/html/tableCell_using_xpath.html +19 -19
  109. data/unittests/html/textarea.html +30 -30
  110. data/unittests/html/textfields1.html +88 -88
  111. data/unittests/html/textsearch.html +44 -44
  112. data/unittests/html/wallofcheckboxes.html +1003 -1003
  113. data/unittests/html/xpath_nbsp.html +12 -12
  114. data/unittests/ie_exists_test.rb +33 -33
  115. data/unittests/ie_mock.rb +94 -94
  116. data/unittests/ie_test.rb +51 -50
  117. data/unittests/images_test.rb +157 -157
  118. data/unittests/images_xpath_test.rb +91 -91
  119. data/unittests/links_multi_test.rb +48 -48
  120. data/unittests/links_test.rb +175 -177
  121. data/unittests/links_xpath_test.rb +39 -39
  122. data/unittests/map_test.rb +98 -98
  123. data/unittests/minmax_test.rb +31 -31
  124. data/unittests/navigate_test.rb +39 -39
  125. data/unittests/nbsp_xpath_test.rb +16 -16
  126. data/unittests/non_core_tests.rb +12 -12
  127. data/unittests/other/WindowLogonExample.rb +27 -27
  128. data/unittests/other/WindowLogonExtra.rb +6 -6
  129. data/unittests/other/all_tests_concurrent.rb +57 -57
  130. data/unittests/{windows → other}/jscriptExtraAlert.rb +6 -6
  131. data/unittests/{windows → other}/jscriptExtraConfirmCancel.rb +6 -6
  132. data/unittests/{windows → other}/jscriptExtraConfirmOk.rb +6 -6
  133. data/unittests/{windows → other}/jscriptPushButton.rb +6 -6
  134. data/unittests/{windows → other}/jscript_test.rb +63 -63
  135. data/unittests/other/navigate_exception_test.rb +24 -24
  136. data/unittests/other/rexml_unit_test.rb +27 -24
  137. data/unittests/other/screen_capture_test.rb +54 -54
  138. data/unittests/other/testcase_method_order_test.rb +35 -35
  139. data/unittests/other/testcase_verify_test.rb +24 -24
  140. data/unittests/other/wait_until_test.rb +99 -99
  141. data/unittests/pagecontainstext_test.rb +69 -69
  142. data/unittests/parent_child_test.rb +43 -43
  143. data/unittests/perf_test.rb +20 -20
  144. data/unittests/popups_test.rb +43 -43
  145. data/unittests/pre_test.rb +53 -53
  146. data/unittests/radios_test.rb +212 -212
  147. data/unittests/radios_xpath_test.rb +101 -101
  148. data/unittests/security_setting_test.rb +23 -23
  149. data/unittests/selectbox_test.rb +148 -139
  150. data/unittests/selectbox_xpath_test.rb +113 -113
  151. data/unittests/setup.rb +77 -75
  152. data/unittests/speed_settings_test.rb +67 -65
  153. data/unittests/table_cell_using_xpath_test.rb +35 -35
  154. data/unittests/table_test.rb +376 -362
  155. data/unittests/table_xpath_test.rb +110 -110
  156. data/unittests/test_tests.rb +9 -9
  157. data/unittests/textarea_test.rb +92 -92
  158. data/unittests/textarea_xpath_test.rb +78 -78
  159. data/unittests/textfield_for_ch_char_test.rb +31 -29
  160. data/unittests/textfields_test.rb +218 -218
  161. data/unittests/textfields_xpath_test.rb +111 -111
  162. data/unittests/window_tests.rb +10 -7
  163. data/unittests/windows/attach_to_existing_window_test.rb +53 -52
  164. data/unittests/windows/attach_to_new_window_test.rb +83 -82
  165. data/unittests/windows/close_window_test.rb +20 -20
  166. data/unittests/windows/frame_links_test.rb +25 -25
  167. data/unittests/windows/ie-each_test.rb +47 -47
  168. data/unittests/windows/iedialog_test.rb +54 -54
  169. data/unittests/windows/js_events_test.rb +55 -55
  170. data/unittests/windows/modal_dialog_test.rb +128 -126
  171. data/unittests/windows/new_test.rb +57 -55
  172. data/unittests/windows/open_close_test.rb +18 -18
  173. data/unittests/windows/send_keys_test.rb +33 -32
  174. data/unittests/xpath_tests.rb +10 -10
  175. metadata +20 -20
  176. data/lib/watir/contrib/visible.rb +0 -47
  177. data/unittests/iostring.rb +0 -30
  178. data/unittests/iostring_test.rb +0 -48
@@ -1,46 +1,46 @@
1
- require 'watir/ie'
2
- # TODO: move this file to watir/contrib
3
-
4
- module Watir
5
-
6
- class Dialog
7
- WindowName = 'Windows Internet Explorer'
8
- def button(name)
9
- DialogButton.new(name)
10
- end
11
- def close
12
- # TODO: register autoit before use
13
- autoit = WIN32OLE.new('AutoItX3.Control')
14
- autoit.WinClose WindowName, ""
15
- end
16
- def exists?
17
- # TODO: register autoit before use
18
- autoit = WIN32OLE.new('AutoItX3.Control')
19
- found = autoit.WinWait(WindowName, "", 1)
20
- return found == 1
21
- end
22
- end
23
-
24
- def dialog
25
- Dialog.new
26
- end
27
-
28
- class DialogButton
29
- def initialize(name)
30
- @name = name
31
- end
32
- def click
33
- # TODO: register autoit before use
34
- autoit = WIN32OLE.new('AutoItX3.Control')
35
- autoit.WinWait Dialog::WindowName, "", 1
36
- name_pattern = Regexp.new "^#{@name}$"
37
- unless name_pattern =~ autoit.WinGetText(Dialog::WindowName, "")
38
- raise Watir::Exception::UnknownObjectException
39
- end
40
- autoit.Send "{ENTER}"
41
- end
42
- end
43
-
44
- end
45
-
46
-
1
+ require 'watir/ie'
2
+ # TODO: move this file to watir/contrib
3
+
4
+ module Watir
5
+
6
+ class Dialog
7
+ WindowName = 'Windows Internet Explorer'
8
+ def button(name)
9
+ DialogButton.new(name)
10
+ end
11
+ def close
12
+ # TODO: register autoit before use
13
+ autoit = WIN32OLE.new('AutoItX3.Control')
14
+ autoit.WinClose WindowName, ""
15
+ end
16
+ def exists?
17
+ # TODO: register autoit before use
18
+ autoit = WIN32OLE.new('AutoItX3.Control')
19
+ found = autoit.WinWait(WindowName, "", 1)
20
+ return found == 1
21
+ end
22
+ end
23
+
24
+ def dialog
25
+ Dialog.new
26
+ end
27
+
28
+ class DialogButton
29
+ def initialize(name)
30
+ @name = name
31
+ end
32
+ def click
33
+ # TODO: register autoit before use
34
+ autoit = WIN32OLE.new('AutoItX3.Control')
35
+ autoit.WinWait Dialog::WindowName, "", 1
36
+ name_pattern = Regexp.new "^#{@name}$"
37
+ unless name_pattern =~ autoit.WinGetText(Dialog::WindowName, "")
38
+ raise Watir::Exception::UnknownObjectException
39
+ end
40
+ autoit.Send "{ENTER}"
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+
@@ -1,312 +1,343 @@
1
- module Watir
2
- # Base class for html elements.
3
- # This is not a class that users would normally access.
4
- class Element # Wrapper
5
- include Watir::Exception
6
- include Container # presumes @container is defined
7
- attr_accessor :container
8
-
9
- # number of spaces that separate the property from the value in the to_s method
10
- TO_S_SIZE = 14
11
-
12
- # ole_object - the ole object for the element being wrapped
13
- def initialize(ole_object)
14
- @o = ole_object
15
- @original_color = nil
16
- end
17
-
18
- # Return the ole object, allowing any methods of the DOM that Watir doesn't support to be used.
19
- def ole_object # BUG: should use an attribute reader and rename the instance variable
20
- return @o
21
- end
22
- def ole_object=(o)
23
- @o = o
24
- end
25
-
26
- private
27
- def self.def_wrap(ruby_method_name, ole_method_name=nil)
28
- ole_method_name = ruby_method_name unless ole_method_name
29
- class_eval "def #{ruby_method_name}
30
- assert_exists
31
- ole_object.invoke('#{ole_method_name}')
32
- end"
33
- end
34
- def self.def_wrap_guard(method_name)
35
- class_eval "def #{method_name}
36
- assert_exists
37
- begin
38
- ole_object.invoke('#{method_name}')
39
- rescue
40
- ''
41
- end
42
- end"
43
- end
44
-
45
-
46
-
47
- public
48
- def assert_exists
49
- locate if defined?(locate)
50
- unless ole_object
51
- raise UnknownObjectException.new(
52
- Watir::Exception.message_for_unable_to_locate(@how, @what))
53
- end
54
- end
55
- def assert_enabled
56
- unless enabled?
57
- raise ObjectDisabledException, "object #{@how} and #{@what} is disabled"
58
- end
59
- end
60
-
61
- # return the name of the element (as defined in html)
62
- def_wrap_guard :name
63
- # return the id of the element
64
- def_wrap_guard :id
65
- # return whether the element is disabled
66
- def_wrap :disabled
67
- alias disabled? disabled
68
- # return the value of the element
69
- def_wrap_guard :value
70
- # return the title of the element
71
- def_wrap_guard :title
72
- # return the style of the element
73
- def_wrap_guard :style
74
-
75
- def_wrap_guard :alt
76
- def_wrap_guard :src
77
-
78
- # return the type of the element
79
- def_wrap_guard :type # input elements only
80
- # return the url the link points to
81
- def_wrap :href # link only
82
- # return the ID of the control that this label is associated with
83
- def_wrap :for, :htmlFor # label only
84
- # return the class name of the element
85
- # raise an ObjectNotFound exception if the object cannot be found
86
- def_wrap :class_name, :className
87
- # return the unique COM number for the element
88
- def_wrap :unique_number, :uniqueNumber
89
- # Return the outer html of the object - see http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/outerhtml.asp?frame=true
90
- def_wrap :html, :outerHTML
91
-
92
- # return the text before the element
93
- def before_text # label only
94
- assert_exists
95
- begin
96
- ole_object.getAdjacentText("afterEnd").strip
97
- rescue
98
- ''
99
- end
100
- end
101
-
102
- # return the text after the element
103
- def after_text # label only
104
- assert_exists
105
- begin
106
- ole_object.getAdjacentText("beforeBegin").strip
107
- rescue
108
- ''
109
- end
110
- end
111
-
112
- # Return the innerText of the object
113
- # Raise an ObjectNotFound exception if the object cannot be found
114
- def text
115
- assert_exists
116
- return ole_object.innerText.strip
117
- end
118
-
119
- def ole_inner_elements
120
- assert_exists
121
- return ole_object.all
122
- end
123
- private :ole_inner_elements
124
-
125
- def document
126
- assert_exists
127
- return ole_object
128
- end
129
-
130
- # Return the element immediately containing self.
131
- def parent
132
- assert_exists
133
- result = Element.new(ole_object.parentelement)
134
- result.set_container self
135
- result
136
- end
137
-
138
- include Comparable
139
- def <=> other
140
- assert_exists
141
- other.assert_exists
142
- ole_object.sourceindex <=> other.ole_object.sourceindex
143
- end
144
-
145
- # Return true if self is contained earlier in the html than other.
146
- alias :before? :<
147
- # Return true if self is contained later in the html than other.
148
- alias :after? :>
149
-
150
- def typingspeed
151
- @container.typingspeed
152
- end
153
- def type_keys
154
- return @container.type_keys if @type_keys.nil?
155
- @type_keys
156
- end
157
- def activeObjectHighLightColor
158
- @container.activeObjectHighLightColor
159
- end
160
-
161
- # Return an array with many of the properties, in a format to be used by the to_s method
162
- def string_creator
163
- n = []
164
- n << "type:".ljust(TO_S_SIZE) + self.type
165
- n << "id:".ljust(TO_S_SIZE) + self.id.to_s
166
- n << "name:".ljust(TO_S_SIZE) + self.name.to_s
167
- n << "value:".ljust(TO_S_SIZE) + self.value.to_s
168
- n << "disabled:".ljust(TO_S_SIZE) + self.disabled.to_s
169
- return n
170
- end
171
- private :string_creator
172
-
173
- # Display basic details about the object. Sample output for a button is shown.
174
- # Raises UnknownObjectException if the object is not found.
175
- # name b4
176
- # type button
177
- # id b5
178
- # value Disabled Button
179
- # disabled true
180
- def to_s
181
- assert_exists
182
- return string_creator.join("\n")
183
- end
184
-
185
- # This method is responsible for setting and clearing the colored highlighting on the currently active element.
186
- # use :set to set the highlight
187
- # :clear to clear the highlight
188
- # TODO: Make this two methods: set_highlight & clear_highlight
189
- # TODO: Remove begin/rescue blocks
190
- def highlight(set_or_clear)
191
- if set_or_clear == :set
192
- begin
193
- @original_color ||= style.backgroundColor
194
- style.backgroundColor = @container.activeObjectHighLightColor
195
- rescue
196
- @original_color = nil
197
- end
198
- else # BUG: assumes is :clear, but could actually be anything
199
- begin
200
- style.backgroundColor = @original_color unless @original_color == nil
201
- rescue
202
- # we could be here for a number of reasons...
203
- # e.g. page may have reloaded and the reference is no longer valid
204
- ensure
205
- @original_color = nil
206
- end
207
- end
208
- end
209
- private :highlight
210
-
211
- # This method clicks the active element.
212
- # raises: UnknownObjectException if the object is not found
213
- # ObjectDisabledException if the object is currently disabled
214
- def click
215
- click!
216
- @container.wait
217
- end
218
-
219
- def click_no_wait
220
- assert_enabled
221
-
222
- highlight(:set)
223
- object = "#{self.class}.new(self, :unique_number, #{self.unique_number})"
224
- @page_container.eval_in_spawned_process(object + ".click!")
225
- highlight(:clear)
226
- end
227
-
228
- def click!
229
- assert_enabled
230
-
231
- highlight(:set)
232
- ole_object.click
233
- highlight(:clear)
234
- end
235
-
236
- # Flash the element the specified number of times.
237
- # Defaults to 10 flashes.
238
- def flash number=10
239
- assert_exists
240
- number.times do
241
- highlight(:set)
242
- sleep 0.05
243
- highlight(:clear)
244
- sleep 0.05
245
- end
246
- nil
247
- end
248
-
249
- # Executes a user defined "fireEvent" for objects with JavaScript events tied to them such as DHTML menus.
250
- # usage: allows a generic way to fire javascript events on page objects such as "onMouseOver", "onClick", etc.
251
- # raises: UnknownObjectException if the object is not found
252
- # ObjectDisabledException if the object is currently disabled
253
- def fire_event(event)
254
- assert_enabled
255
-
256
- highlight(:set)
257
- ole_object.fireEvent(event)
258
- @container.wait
259
- highlight(:clear)
260
- end
261
-
262
- # This method sets focus on the active element.
263
- # raises: UnknownObjectException if the object is not found
264
- # ObjectDisabledException if the object is currently disabled
265
- def focus
266
- assert_enabled
267
- ole_object.focus
268
- end
269
-
270
- # Returns whether this element actually exists.
271
- def exists?
272
- begin
273
- locate if defined?(locate)
274
- rescue WIN32OLERuntimeError
275
- @o = nil
276
- end
277
- @o ? true: false
278
- end
279
- alias :exist? :exists?
280
-
281
- # Returns true if the element is enabled, false if it isn't.
282
- # raises: UnknownObjectException if the object is not found
283
- def enabled?
284
- assert_exists
285
- return ! disabled
286
- end
287
-
288
- # Get attribute value for any attribute of the element.
289
- # Returns null if attribute doesn't exist.
290
- def attribute_value(attribute_name)
291
- assert_exists
292
- return ole_object.getAttribute(attribute_name)
293
- end
294
-
295
- end
296
-
297
- class ElementMapper # Still to be used
298
- include Container
299
-
300
- def initialize wrapper_class, container, how, what
301
- @wrapper_class = wrapper_class
302
- set_container
303
- @how = how
304
- @what = what
305
- end
306
-
307
- def method_missing method, *args
308
- locate
309
- @wrapper_class.new(@o).send(method, *args)
310
- end
311
- end
312
- end
1
+ module Watir
2
+ # Base class for html elements.
3
+ # This is not a class that users would normally access.
4
+ class Element # Wrapper
5
+ include Watir::Exception
6
+ include Container # presumes @container is defined
7
+ attr_accessor :container
8
+
9
+ # number of spaces that separate the property from the value in the to_s method
10
+ TO_S_SIZE = 14
11
+
12
+ # ole_object - the ole object for the element being wrapped
13
+ def initialize(ole_object)
14
+ @o = ole_object
15
+ @original_color = nil
16
+ end
17
+
18
+ # Return the ole object, allowing any methods of the DOM that Watir doesn't support to be used.
19
+ def ole_object # BUG: should use an attribute reader and rename the instance variable
20
+ return @o
21
+ end
22
+ def ole_object=(o)
23
+ @o = o
24
+ end
25
+
26
+ def inspect
27
+ '#<%s:0x%x located=%s how=%s what=%s>' % [self.class, hash*2, !!ole_object, @how.inspect, @what.inspect]
28
+ end
29
+
30
+ private
31
+ def self.def_wrap(ruby_method_name, ole_method_name=nil)
32
+ ole_method_name = ruby_method_name unless ole_method_name
33
+ class_eval "def #{ruby_method_name}
34
+ assert_exists
35
+ ole_object.invoke('#{ole_method_name}')
36
+ end"
37
+ end
38
+ def self.def_wrap_guard(method_name)
39
+ class_eval "def #{method_name}
40
+ assert_exists
41
+ begin
42
+ ole_object.invoke('#{method_name}')
43
+ rescue
44
+ ''
45
+ end
46
+ end"
47
+ end
48
+
49
+
50
+
51
+ public
52
+ def assert_exists
53
+ locate if respond_to?(:locate)
54
+ unless ole_object
55
+ raise UnknownObjectException.new(
56
+ Watir::Exception.message_for_unable_to_locate(@how, @what))
57
+ end
58
+ end
59
+ def assert_enabled
60
+ unless enabled?
61
+ raise ObjectDisabledException, "object #{@how} and #{@what} is disabled"
62
+ end
63
+ end
64
+
65
+ # return the name of the element (as defined in html)
66
+ def_wrap_guard :name
67
+ # return the id of the element
68
+ def_wrap_guard :id
69
+ # return whether the element is disabled
70
+ def_wrap :disabled
71
+ alias disabled? disabled
72
+ # return the value of the element
73
+ def_wrap_guard :value
74
+ # return the title of the element
75
+ def_wrap_guard :title
76
+ # return the style of the element
77
+ def_wrap_guard :style
78
+
79
+ def_wrap_guard :alt
80
+ def_wrap_guard :src
81
+
82
+ # return the type of the element
83
+ def_wrap_guard :type # input elements only
84
+ # return the url the link points to
85
+ def_wrap :href # link only
86
+ # return the ID of the control that this label is associated with
87
+ def_wrap :for, :htmlFor # label only
88
+ # return the class name of the element
89
+ # raise an ObjectNotFound exception if the object cannot be found
90
+ def_wrap :class_name, :className
91
+ # return the unique COM number for the element
92
+ def_wrap :unique_number, :uniqueNumber
93
+ # Return the outer html of the object - see http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/outerhtml.asp?frame=true
94
+ def_wrap :html, :outerHTML
95
+
96
+ # return the text before the element
97
+ def before_text # label only
98
+ assert_exists
99
+ begin
100
+ ole_object.getAdjacentText("afterEnd").strip
101
+ rescue
102
+ ''
103
+ end
104
+ end
105
+
106
+ # return the text after the element
107
+ def after_text # label only
108
+ assert_exists
109
+ begin
110
+ ole_object.getAdjacentText("beforeBegin").strip
111
+ rescue
112
+ ''
113
+ end
114
+ end
115
+
116
+ # Return the innerText of the object
117
+ # Raise an ObjectNotFound exception if the object cannot be found
118
+ def text
119
+ assert_exists
120
+ return ole_object.innerText.strip
121
+ end
122
+
123
+ def ole_inner_elements
124
+ assert_exists
125
+ return ole_object.all
126
+ end
127
+ private :ole_inner_elements
128
+
129
+ def document
130
+ assert_exists
131
+ return ole_object
132
+ end
133
+
134
+ # Return the element immediately containing self.
135
+ def parent
136
+ assert_exists
137
+ result = Element.new(ole_object.parentelement)
138
+ result.set_container self
139
+ result
140
+ end
141
+
142
+ include Comparable
143
+ def <=> other
144
+ assert_exists
145
+ other.assert_exists
146
+ ole_object.sourceindex <=> other.ole_object.sourceindex
147
+ end
148
+
149
+ # Return true if self is contained earlier in the html than other.
150
+ alias :before? :<
151
+ # Return true if self is contained later in the html than other.
152
+ alias :after? :>
153
+
154
+ def typingspeed
155
+ @container.typingspeed
156
+ end
157
+ def type_keys
158
+ return @container.type_keys if @type_keys.nil?
159
+ @type_keys
160
+ end
161
+ def activeObjectHighLightColor
162
+ @container.activeObjectHighLightColor
163
+ end
164
+
165
+ # Return an array with many of the properties, in a format to be used by the to_s method
166
+ def string_creator
167
+ n = []
168
+ n << "type:".ljust(TO_S_SIZE) + self.type
169
+ n << "id:".ljust(TO_S_SIZE) + self.id.to_s
170
+ n << "name:".ljust(TO_S_SIZE) + self.name.to_s
171
+ n << "value:".ljust(TO_S_SIZE) + self.value.to_s
172
+ n << "disabled:".ljust(TO_S_SIZE) + self.disabled.to_s
173
+ return n
174
+ end
175
+ private :string_creator
176
+
177
+ # Display basic details about the object. Sample output for a button is shown.
178
+ # Raises UnknownObjectException if the object is not found.
179
+ # name b4
180
+ # type button
181
+ # id b5
182
+ # value Disabled Button
183
+ # disabled true
184
+ def to_s
185
+ assert_exists
186
+ return string_creator.join("\n")
187
+ end
188
+
189
+ # This method is responsible for setting and clearing the colored highlighting on the currently active element.
190
+ # use :set to set the highlight
191
+ # :clear to clear the highlight
192
+ # TODO: Make this two methods: set_highlight & clear_highlight
193
+ # TODO: Remove begin/rescue blocks
194
+ def highlight(set_or_clear)
195
+ if set_or_clear == :set
196
+ begin
197
+ @original_color ||= style.backgroundColor
198
+ style.backgroundColor = @container.activeObjectHighLightColor
199
+ rescue
200
+ @original_color = nil
201
+ end
202
+ else # BUG: assumes is :clear, but could actually be anything
203
+ begin
204
+ style.backgroundColor = @original_color unless @original_color == nil
205
+ rescue
206
+ # we could be here for a number of reasons...
207
+ # e.g. page may have reloaded and the reference is no longer valid
208
+ ensure
209
+ @original_color = nil
210
+ end
211
+ end
212
+ end
213
+ private :highlight
214
+
215
+ # This method clicks the active element.
216
+ # raises: UnknownObjectException if the object is not found
217
+ # ObjectDisabledException if the object is currently disabled
218
+ def click
219
+ click!
220
+ @container.wait
221
+ end
222
+
223
+ def click_no_wait
224
+ assert_enabled
225
+
226
+ highlight(:set)
227
+ object = "#{self.class}.new(self, :unique_number, #{self.unique_number})"
228
+ @page_container.eval_in_spawned_process(object + ".click!")
229
+ highlight(:clear)
230
+ end
231
+
232
+ def click!
233
+ assert_enabled
234
+
235
+ highlight(:set)
236
+ ole_object.click
237
+ highlight(:clear)
238
+ end
239
+
240
+ # Flash the element the specified number of times.
241
+ # Defaults to 10 flashes.
242
+ def flash number=10
243
+ assert_exists
244
+ number.times do
245
+ highlight(:set)
246
+ sleep 0.05
247
+ highlight(:clear)
248
+ sleep 0.05
249
+ end
250
+ nil
251
+ end
252
+
253
+ # Executes a user defined "fireEvent" for objects with JavaScript events tied to them such as DHTML menus.
254
+ # usage: allows a generic way to fire javascript events on page objects such as "onMouseOver", "onClick", etc.
255
+ # raises: UnknownObjectException if the object is not found
256
+ # ObjectDisabledException if the object is currently disabled
257
+ def fire_event(event)
258
+ assert_enabled
259
+
260
+ highlight(:set)
261
+ ole_object.fireEvent(event)
262
+ @container.wait
263
+ highlight(:clear)
264
+ end
265
+
266
+ # This method sets focus on the active element.
267
+ # raises: UnknownObjectException if the object is not found
268
+ # ObjectDisabledException if the object is currently disabled
269
+ def focus
270
+ assert_enabled
271
+ ole_object.focus
272
+ end
273
+
274
+ # Returns whether this element actually exists.
275
+ def exists?
276
+ begin
277
+ locate if defined?(locate)
278
+ rescue WIN32OLERuntimeError
279
+ @o = nil
280
+ end
281
+ @o ? true: false
282
+ end
283
+ alias :exist? :exists?
284
+
285
+ # Returns true if the element is enabled, false if it isn't.
286
+ # raises: UnknownObjectException if the object is not found
287
+ def enabled?
288
+ assert_exists
289
+ return ! disabled
290
+ end
291
+
292
+ # If any parent element isn't visible then we cannot write to the
293
+ # element. The only realiable way to determine this is to iterate
294
+ # up the DOM element tree checking every element to make sure it's
295
+ # visible.
296
+ def visible?
297
+ # Now iterate up the DOM element tree and return false if any
298
+ # parent element isn't visible or is disabled.
299
+ assert_exists
300
+ object = @o
301
+ while object
302
+ begin
303
+ if object.currentstyle.invoke('visibility') =~ /^hidden$/i
304
+ return false
305
+ end
306
+ if object.currentstyle.invoke('display') =~ /^none$/i
307
+ return false
308
+ end
309
+ if object.invoke('isDisabled')
310
+ return false
311
+ end
312
+ rescue WIN32OLERuntimeError
313
+ end
314
+ object = object.parentElement
315
+ end
316
+ true
317
+ end
318
+
319
+ # Get attribute value for any attribute of the element.
320
+ # Returns null if attribute doesn't exist.
321
+ def attribute_value(attribute_name)
322
+ assert_exists
323
+ return ole_object.getAttribute(attribute_name)
324
+ end
325
+
326
+ end
327
+
328
+ class ElementMapper # Still to be used
329
+ include Container
330
+
331
+ def initialize wrapper_class, container, how, what
332
+ @wrapper_class = wrapper_class
333
+ set_container
334
+ @how = how
335
+ @what = what
336
+ end
337
+
338
+ def method_missing method, *args
339
+ locate
340
+ @wrapper_class.new(@o).send(method, *args)
341
+ end
342
+ end
343
+ end