watir 1.6.5 → 1.6.6.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGES +461 -326
  2. data/VERSION +1 -0
  3. data/bin/watir-console +6 -6
  4. data/lib/changes.rb +3 -3
  5. data/lib/license.rb +38 -38
  6. data/lib/readme.rb +140 -140
  7. data/lib/watir/WindowHelper.rb +49 -49
  8. data/lib/watir/camel_case.rb +66 -66
  9. data/lib/watir/clickJSDialog.rb +19 -19
  10. data/lib/watir/close_all.rb +37 -37
  11. data/lib/watir/collections.rb +392 -344
  12. data/lib/watir/container.rb +857 -815
  13. data/lib/watir/contrib/enabled_popup.rb +20 -20
  14. data/lib/watir/contrib/ie-new-process.rb +27 -27
  15. data/lib/watir/contrib/page_checker.rb +29 -29
  16. data/lib/watir/cookiemanager.rb +55 -55
  17. data/lib/watir/core.rb +28 -0
  18. data/lib/watir/core_ext.rb +17 -17
  19. data/lib/watir/datahandler.rb +107 -107
  20. data/lib/watir/dialog.rb +46 -46
  21. data/lib/watir/element.rb +351 -343
  22. data/lib/watir/element_collections.rb +97 -97
  23. data/lib/watir/form.rb +170 -170
  24. data/lib/watir/frame.rb +59 -59
  25. data/lib/watir/html_element.rb +22 -0
  26. data/lib/watir/ie-class.rb +1006 -1009
  27. data/lib/watir/ie-process.rb +39 -39
  28. data/lib/watir/ie.rb +70 -133
  29. data/lib/watir/image.rb +130 -130
  30. data/lib/watir/input_elements.rb +614 -572
  31. data/lib/watir/irb-history.rb +30 -30
  32. data/lib/watir/link.rb +64 -64
  33. data/lib/watir/locator.rb +200 -176
  34. data/lib/watir/logger.rb +19 -19
  35. data/lib/watir/modal_dialog.rb +122 -122
  36. data/lib/watir/module.rb +37 -0
  37. data/lib/watir/non_control_elements.rb +145 -145
  38. data/lib/watir/page-container.rb +116 -107
  39. data/lib/watir/popup.rb +29 -29
  40. data/lib/watir/process.rb +19 -19
  41. data/lib/watir/screen_capture.rb +115 -115
  42. data/lib/watir/setFileDialog.rb +16 -16
  43. data/lib/watir/table.rb +395 -362
  44. data/lib/watir/watir_simple.rb +475 -475
  45. data/lib/watir/win32.rb +35 -35
  46. data/lib/watir/win32ole.rb +14 -14
  47. data/lib/watir/winClicker.rb +496 -496
  48. data/rakefile.rb +70 -0
  49. data/unittests/all_tests.rb +10 -10
  50. data/unittests/buttons_xpath_test.rb +69 -69
  51. data/unittests/checkbox_test.rb +179 -179
  52. data/unittests/checkbox_xpath_test.rb +107 -107
  53. data/unittests/click_no_wait_test.rb +21 -0
  54. data/unittests/core_tests.rb +17 -17
  55. data/unittests/css_test.rb +42 -35
  56. data/unittests/defer_test.rb +46 -46
  57. data/unittests/dialog_test.rb +77 -77
  58. data/unittests/div2_xpath_test.rb +21 -21
  59. data/unittests/div_test.rb +188 -188
  60. data/unittests/div_xpath_test.rb +96 -96
  61. data/unittests/element_test.rb +49 -0
  62. data/unittests/errorchecker_test.rb +32 -22
  63. data/unittests/filefield_test.rb +39 -39
  64. data/unittests/filefield_xpath_test.rb +33 -33
  65. data/unittests/form_test.rb +280 -280
  66. data/unittests/form_xpath_test.rb +252 -252
  67. data/unittests/frame_test.rb +155 -155
  68. data/unittests/google_form_test.rb +15 -15
  69. data/unittests/html/JavascriptClick.html +39 -39
  70. data/unittests/html/blankpage.html +11 -11
  71. data/unittests/html/buttons1.html +40 -40
  72. data/unittests/html/checkboxes1.html +89 -89
  73. data/unittests/html/click_no_wait.html +14 -0
  74. data/unittests/html/complex_table.html +36 -36
  75. data/unittests/html/cssTest.html +42 -42
  76. data/unittests/html/depot_store.html +59 -59
  77. data/unittests/html/div.html +93 -93
  78. data/unittests/html/div_xml.html +20 -20
  79. data/unittests/html/fileupload.html +45 -45
  80. data/unittests/html/formTest1.html +38 -38
  81. data/unittests/html/forms2.html +44 -44
  82. data/unittests/html/forms3.html +131 -131
  83. data/unittests/html/forms4.html +27 -27
  84. data/unittests/html/frame_buttons.html +3 -3
  85. data/unittests/html/frame_links.html +3 -3
  86. data/unittests/html/frame_multi.html +4 -4
  87. data/unittests/html/google_india.html +119 -119
  88. data/unittests/html/iframeTest.html +12 -12
  89. data/unittests/html/iframeTest1.html +6 -6
  90. data/unittests/html/iframeTest2.html +5 -5
  91. data/unittests/html/images1.html +66 -66
  92. data/unittests/html/javascriptevents.html +35 -35
  93. data/unittests/html/link_pass.html +10 -10
  94. data/unittests/html/links1.html +38 -38
  95. data/unittests/html/links2.html +10 -10
  96. data/unittests/html/links_multi.html +14 -14
  97. data/unittests/html/list_matters.html +720 -720
  98. data/unittests/html/lists.html +17 -17
  99. data/unittests/html/map_test.html +31 -31
  100. data/unittests/html/modal_dialog.html +10 -10
  101. data/unittests/html/modal_dialog_launcher.html +11 -11
  102. data/unittests/html/nestedFrames.html +6 -6
  103. data/unittests/html/new_browser.html +16 -16
  104. data/unittests/html/pass.html +12 -12
  105. data/unittests/html/popups1.html +59 -59
  106. data/unittests/html/pre.html +27 -27
  107. data/unittests/html/radioButtons1.html +71 -71
  108. data/unittests/html/select_tealeaf.html +54 -54
  109. data/unittests/html/selectboxes1.html +52 -52
  110. data/unittests/html/simple_table.html +26 -26
  111. data/unittests/html/simple_table_buttons.html +104 -104
  112. data/unittests/html/simple_table_columns.html +76 -76
  113. data/unittests/html/table1.html +181 -181
  114. data/unittests/html/tableCell_using_xpath.html +19 -19
  115. data/unittests/html/table_and_tablerow_to_a.html +174 -0
  116. data/unittests/html/textarea.html +30 -30
  117. data/unittests/html/textfields1.html +88 -88
  118. data/unittests/html/textsearch.html +44 -44
  119. data/unittests/html/wallofcheckboxes.html +1003 -1003
  120. data/unittests/html/xpath_nbsp.html +12 -12
  121. data/unittests/ie_exists_test.rb +33 -33
  122. data/unittests/ie_mock.rb +94 -94
  123. data/unittests/ie_test.rb +51 -51
  124. data/unittests/images_test.rb +157 -157
  125. data/unittests/images_xpath_test.rb +91 -91
  126. data/unittests/links_multi_test.rb +48 -48
  127. data/unittests/links_test.rb +175 -175
  128. data/unittests/links_xpath_test.rb +39 -39
  129. data/unittests/lists_test.rb +32 -32
  130. data/unittests/map_test.rb +98 -98
  131. data/unittests/minmax_test.rb +31 -31
  132. data/unittests/navigate_test.rb +39 -39
  133. data/unittests/nbsp_xpath_test.rb +16 -16
  134. data/unittests/non_core_tests.rb +12 -12
  135. data/unittests/other/WindowLogonExample.rb +27 -27
  136. data/unittests/other/WindowLogonExtra.rb +6 -6
  137. data/unittests/other/all_tests_concurrent.rb +57 -57
  138. data/unittests/other/jscriptExtraAlert.rb +6 -6
  139. data/unittests/other/jscriptExtraConfirmCancel.rb +6 -6
  140. data/unittests/other/jscriptExtraConfirmOk.rb +6 -6
  141. data/unittests/other/jscriptPushButton.rb +6 -6
  142. data/unittests/other/jscript_test.rb +63 -63
  143. data/unittests/other/navigate_exception_test.rb +24 -24
  144. data/unittests/other/rexml_unit_test.rb +27 -27
  145. data/unittests/other/screen_capture_test.rb +54 -54
  146. data/unittests/other/testcase_method_order_test.rb +35 -35
  147. data/unittests/other/testcase_verify_test.rb +24 -24
  148. data/unittests/other/wait_until_test.rb +99 -99
  149. data/unittests/pagecontainstext_test.rb +69 -69
  150. data/unittests/parent_child_test.rb +43 -43
  151. data/unittests/perf_test.rb +20 -20
  152. data/unittests/popups_test.rb +43 -43
  153. data/unittests/pre_test.rb +53 -53
  154. data/unittests/radios_test.rb +212 -212
  155. data/unittests/radios_xpath_test.rb +101 -101
  156. data/unittests/security_setting_test.rb +23 -23
  157. data/unittests/selectbox_test.rb +148 -148
  158. data/unittests/selectbox_xpath_test.rb +113 -113
  159. data/unittests/setup.rb +87 -77
  160. data/unittests/speed_settings_test.rb +67 -67
  161. data/unittests/table_and_tablerow_to_a_test.rb +117 -0
  162. data/unittests/table_cell_using_xpath_test.rb +35 -35
  163. data/unittests/table_test.rb +376 -376
  164. data/unittests/table_xpath_test.rb +110 -110
  165. data/unittests/test_tests.rb +9 -9
  166. data/unittests/textarea_test.rb +92 -92
  167. data/unittests/textarea_xpath_test.rb +78 -78
  168. data/unittests/textfield_for_ch_char_test.rb +31 -31
  169. data/unittests/textfields_test.rb +218 -218
  170. data/unittests/textfields_xpath_test.rb +111 -111
  171. data/unittests/window_tests.rb +10 -10
  172. data/unittests/windows/attach_to_existing_window_test.rb +53 -53
  173. data/unittests/windows/attach_to_new_window_test.rb +83 -83
  174. data/unittests/windows/close_window_test.rb +20 -20
  175. data/unittests/windows/frame_links_test.rb +25 -25
  176. data/unittests/windows/ie-each_test.rb +47 -47
  177. data/unittests/windows/iedialog_test.rb +54 -54
  178. data/unittests/windows/js_events_test.rb +42 -55
  179. data/unittests/windows/modal_dialog_test.rb +128 -128
  180. data/unittests/windows/new_test.rb +57 -57
  181. data/unittests/windows/open_close_test.rb +18 -18
  182. data/unittests/windows/send_keys_test.rb +33 -33
  183. data/unittests/xpath_tests.rb +10 -10
  184. metadata +85 -31
  185. data/lib/watir/utils.rb +0 -20
  186. data/lib/watir/version.rb +0 -5
@@ -1,67 +1,67 @@
1
- # These are provided for backwards compatability with Watir 1.1
2
-
3
- module Watir
4
- module Container
5
- alias waitForIE wait
6
- alias fileField file_field
7
- alias textField text_field
8
- alias selectBox select_list
9
- alias checkBox checkbox
10
- end
11
- class IE
12
- alias getStatus status
13
- alias getDocument document
14
- alias pageContainsText contains_text
15
- alias waitForIE wait
16
- alias getHTML html
17
- alias getText text
18
- alias showFrames show_frames
19
- alias showForms show_forms
20
- alias showImages show_images
21
- alias showLinks show_links
22
- alias showActive show_active
23
- alias showAllObjects show_all_objects
24
- def getIE; @ie; end
25
-
26
- end
27
- class Element
28
- alias getOLEObject ole_object
29
- alias fireEvent fire_event
30
- alias innerText text
31
- alias afterText after_text
32
- alias beforeText before_text
33
- end
34
- class Frame
35
- alias getDocument document
36
- alias waitForIE wait
37
- end
38
- class Form
39
- alias waitForIE wait
40
- end
41
-
42
-
43
- class Image
44
- alias fileCreatedDate file_created_date
45
- alias fileSize file_size
46
- alias hasLoaded? loaded?
47
- end
48
-
49
- class RadioCheckCommon
50
- alias getState set?
51
- alias isSet? set?
52
- end
53
-
54
- class TextField
55
- alias readOnly? :readonly?
56
- alias getContents value
57
- alias maxLength maxlength
58
- alias dragContentsTo drag_contents_to
59
- end
60
-
61
- class SelectList
62
- alias getAllContents options
63
- alias getSelectedItems selected_options
64
- alias clearSelection clear
65
- alias includes? include?
66
- end
1
+ # These are provided for backwards compatability with Watir 1.1
2
+
3
+ module Watir
4
+ module Container
5
+ alias waitForIE wait
6
+ alias fileField file_field
7
+ alias textField text_field
8
+ alias selectBox select_list
9
+ alias checkBox checkbox
10
+ end
11
+ class IE
12
+ alias getStatus status
13
+ alias getDocument document
14
+ alias pageContainsText contains_text
15
+ alias waitForIE wait
16
+ alias getHTML html
17
+ alias getText text
18
+ alias showFrames show_frames
19
+ alias showForms show_forms
20
+ alias showImages show_images
21
+ alias showLinks show_links
22
+ alias showActive show_active
23
+ alias showAllObjects show_all_objects
24
+ def getIE; @ie; end
25
+
26
+ end
27
+ class Element
28
+ alias getOLEObject ole_object
29
+ alias fireEvent fire_event
30
+ alias innerText text
31
+ alias afterText after_text
32
+ alias beforeText before_text
33
+ end
34
+ class Frame
35
+ alias getDocument document
36
+ alias waitForIE wait
37
+ end
38
+ class Form
39
+ alias waitForIE wait
40
+ end
41
+
42
+
43
+ class Image
44
+ alias fileCreatedDate file_created_date
45
+ alias fileSize file_size
46
+ alias hasLoaded? loaded?
47
+ end
48
+
49
+ class RadioCheckCommon
50
+ alias getState set?
51
+ alias isSet? set?
52
+ end
53
+
54
+ class TextField
55
+ alias readOnly? :readonly?
56
+ alias getContents value
57
+ alias maxLength maxlength
58
+ alias dragContentsTo drag_contents_to
59
+ end
60
+
61
+ class SelectList
62
+ alias getAllContents options
63
+ alias getSelectedItems selected_options
64
+ alias clearSelection clear
65
+ alias includes? include?
66
+ end
67
67
  end
@@ -1,19 +1,19 @@
1
- #
2
- # clickJSDialog.rb
3
- #
4
- #
5
- # This file contains the JS clicker when it runs as a separate process
6
-
7
- $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..'))
8
- puts $LOAD_PATH
9
- require 'watir/winClicker'
10
-
11
- button = "OK"
12
- button = ARGV[0] unless ARGV[0] == nil
13
- sleepTime = 0
14
- sleepTime = ARGV[1] unless ARGV[1] == nil
15
-
16
-
17
- clicker= WinClicker.new
18
- result = clicker.clickJavaScriptDialog( button )
19
- clicker = nil
1
+ #
2
+ # clickJSDialog.rb
3
+ #
4
+ #
5
+ # This file contains the JS clicker when it runs as a separate process
6
+
7
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..'))
8
+ puts $LOAD_PATH
9
+ require 'watir/winClicker'
10
+
11
+ button = "OK"
12
+ button = ARGV[0] unless ARGV[0] == nil
13
+ sleepTime = 0
14
+ sleepTime = ARGV[1] unless ARGV[1] == nil
15
+
16
+
17
+ clicker= WinClicker.new
18
+ result = clicker.clickJavaScriptDialog( button )
19
+ clicker = nil
@@ -1,38 +1,38 @@
1
- require 'watir/ie'
2
-
3
- module Watir
4
- class IE
5
- # close all ie browser windows
6
- def self.close_all
7
- close_all_but nil
8
- end
9
- # find other ie browser windows and close them
10
- def close_others
11
- IE.close_all_but self
12
- end
13
- private
14
- def self.close_all_but(except=nil)
15
- Watir::IE.each do |ie|
16
- ie.close_modal
17
- ie.close unless except and except.hwnd == ie.hwnd
18
- end
19
- sleep 1.0 # replace with polling for window count to be zero?
20
- end
21
- public
22
- # close modal dialog. unlike IE#modal_dialog.close, does not wait for dialog
23
- # to appear and does not raise exception if no window is found.
24
- # returns true if modal was found and close, otherwise false
25
- def close_modal
26
- begin
27
- original_attach_timeout = IE.attach_timeout
28
- IE.attach_timeout = 0
29
- self.modal_dialog.close
30
- true
31
- rescue NoMatchingWindowFoundException, TimeOutException
32
- false
33
- ensure
34
- IE.attach_timeout = original_attach_timeout
35
- end
36
- end
37
- end
1
+ require 'watir/ie'
2
+
3
+ module Watir
4
+ class IE
5
+ # close all ie browser windows
6
+ def self.close_all
7
+ close_all_but nil
8
+ end
9
+ # find other ie browser windows and close them
10
+ def close_others
11
+ IE.close_all_but self
12
+ end
13
+ private
14
+ def self.close_all_but(except=nil)
15
+ Watir::IE.each do |ie|
16
+ ie.close_modal
17
+ ie.close unless except and except.hwnd == ie.hwnd
18
+ end
19
+ sleep 1.0 # replace with polling for window count to be zero?
20
+ end
21
+ public
22
+ # close modal dialog. unlike IE#modal_dialog.close, does not wait for dialog
23
+ # to appear and does not raise exception if no window is found.
24
+ # returns true if modal was found and close, otherwise false
25
+ def close_modal
26
+ begin
27
+ original_attach_timeout = IE.attach_timeout
28
+ IE.attach_timeout = 0
29
+ self.modal_dialog.close
30
+ true
31
+ rescue NoMatchingWindowFoundException, TimeOutException
32
+ false
33
+ ensure
34
+ IE.attach_timeout = original_attach_timeout
35
+ end
36
+ end
37
+ end
38
38
  end
@@ -1,344 +1,392 @@
1
- module Watir
2
- #--
3
- # These classes are not for public consumption, so we switch off rdoc
4
-
5
- # presumes element_class or element_tag is defined
6
- # for subclasses of ElementCollections
7
- module CommonCollection
8
- def element_tag
9
- element_class::TAG
10
- end
11
-
12
- def length
13
- @container.document.getElementsByTagName(element_tag).length
14
- end
15
- alias_method :size, :length
16
- end
17
-
18
- # This class is used as part of the .show method of the iterators class
19
- # it would not normally be used by a user
20
- class AttributeLengthPairs
21
-
22
- # This class is used as part of the .show method of the iterators class
23
- # it would not normally be used by a user
24
- class AttributeLengthHolder
25
- attr_accessor :attribute
26
- attr_accessor :length
27
-
28
- def initialize(attrib, length)
29
- @attribute = attrib
30
- @length = length
31
- end
32
- end
33
-
34
- def initialize(attrib=nil, length=nil)
35
- @attr=[]
36
- add(attrib, length) if attrib
37
- @index_counter = 0
38
- end
39
-
40
- # BUG: Untested. (Null implementation passes all tests.)
41
- def add(attrib, length)
42
- @attr << AttributeLengthHolder.new(attrib, length)
43
- end
44
-
45
- def delete(attrib)
46
- item_to_delete = nil
47
- @attr.each_with_index do |e,i|
48
- item_to_delete = i if e.attribute == attrib
49
- end
50
- @attr.delete_at(item_to_delete) unless item_to_delete == nil
51
- end
52
-
53
- def next
54
- temp = @attr[@index_counter]
55
- @index_counter += 1
56
- return temp
57
- end
58
-
59
- def each
60
- 0.upto(@attr.length-1) { |i | yield @attr[i] }
61
- end
62
- end
63
-
64
- # resume rdoc
65
- #++
66
-
67
- # this class accesses the buttons in the document as a collection
68
- # it would normally only be accessed by the Watir::Container#buttons method
69
- class Buttons < ElementCollections
70
- def element_class; Button; end
71
- def length
72
- get_length_of_input_objects(["button", "submit", "image"])
73
- end
74
-
75
- private
76
- def set_show_items
77
- super
78
- @show_attributes.add("disabled", 9)
79
- @show_attributes.add("value", 20)
80
- end
81
- end
82
-
83
- # this class accesses the file fields in the document as a collection
84
- # normal access is via the Container#file_fields method
85
- class FileFields < ElementCollections
86
- def element_class; FileField; end
87
- def length
88
- get_length_of_input_objects(["file"])
89
- end
90
-
91
- private
92
- def set_show_items
93
- super
94
- @show_attributes.add("disabled", 9)
95
- @show_attributes.add("value", 20)
96
- end
97
- end
98
-
99
- # this class accesses the check boxes in the document as a collection
100
- # Normally a user would not need to create this object as it is returned by the Watir::Container#checkboxes method
101
- class CheckBoxes < ElementCollections
102
- def element_class; CheckBox; end
103
- def length
104
- get_length_of_input_objects("checkbox")
105
- end
106
-
107
- private
108
- def iterator_object(i)
109
- @container.checkbox(:index, i + 1)
110
- end
111
- end
112
-
113
- # this class accesses the radio buttons in the document as a collection
114
- # Normally a user would not need to create this object as it is returned by the Watir::Container#radios method
115
- class Radios < ElementCollections
116
- def element_class; Radio; end
117
- def length
118
- get_length_of_input_objects("radio")
119
- end
120
-
121
- private
122
- def iterator_object(i)
123
- @container.radio(:index, i + 1)
124
- end
125
- end
126
-
127
- # this class accesses the select boxes in the document as a collection
128
- # Normally a user would not need to create this object as it is returned by the Watir::Container#select_lists method
129
- class SelectLists < ElementCollections
130
- include CommonCollection
131
- def element_class; SelectList; end
132
- def element_tag; 'SELECT'; end
133
- end
134
-
135
- # this class accesses the links in the document as a collection
136
- # Normally a user would not need to create this object as it is returned by the Watir::Container#links method
137
- class Links < ElementCollections
138
- include CommonCollection
139
- def element_class; Link; end
140
- def element_tag; 'A'; end
141
-
142
- private
143
- def set_show_items
144
- super
145
- @show_attributes.add("href", 60)
146
- @show_attributes.add("innerText", 60)
147
- end
148
- end
149
-
150
- class Lis < ElementCollections
151
- include CommonCollection
152
- def element_class; Li; end
153
-
154
- def set_show_items
155
- super
156
- @show_attributes.delete( "name")
157
- @show_attributes.add( "className" , 20)
158
- end
159
- end
160
-
161
- # this class accesses the maps in the document as a collection
162
- # Normally a user would not need to create this object as it is returned by the Watir::Container#maps method
163
- class Maps < ElementCollections
164
- include CommonCollection
165
- def element_class; Map; end
166
- def element_tag; 'MAP'; end
167
- end
168
-
169
-
170
- # this class accesses the areas in the document as a collection
171
- # Normally a user would not need to create this object as it is returned by the Watir::Container#areas method
172
- class Areas < ElementCollections
173
- include CommonCollection
174
- def element_class; Area; end
175
- def element_tag; 'AREA'; end
176
- end
177
-
178
- # this class collects the images in the container
179
- # An instance is returned by Watir::Container#images
180
- class Images < ElementCollections
181
- def element_class; Image; end
182
- def length
183
- all = @container.document.all
184
- imgs = []
185
- all.each{|n| imgs << n if n.nodeName == "IMG"}
186
- imgs.length
187
- end
188
-
189
- private
190
- def set_show_items
191
- super
192
- @show_attributes.add("src", 60)
193
- @show_attributes.add("alt", 30)
194
- end
195
- end
196
-
197
- # this class accesses the text fields in the document as a collection
198
- # Normally a user would not need to create this object as it is returned by the Watir::Container#text_fields method
199
- class TextFields < ElementCollections
200
- def element_class; TextField; end
201
- def length
202
- # text areas are also included in the TextFields, but we need to get them seperately
203
- get_length_of_input_objects(["text", "password"]) +
204
- @container.document.getElementsByTagName("textarea").length
205
- end
206
- end
207
-
208
- # this class accesses the hidden fields in the document as a collection
209
- # Normally a user would not need to create this object as it is returned by the Watir::Container#hiddens method
210
- class Hiddens < ElementCollections
211
- def element_class; Hidden; end
212
- def length
213
- get_length_of_input_objects("hidden")
214
- end
215
- end
216
-
217
- # this class accesses the text fields in the document as a collection
218
- # Normally a user would not need to create this object as it is returned by the Watir::Container#tables method
219
- class Tables < ElementCollections
220
- include CommonCollection
221
- def element_class; Table; end
222
- def element_tag; 'TABLE'; end
223
-
224
- private
225
- def set_show_items
226
- super
227
- @show_attributes.delete("name")
228
- end
229
- end
230
- # this class accesses the table rows in the document as a collection
231
- # Normally a user would not need to create this object as it is returned by the Watir::Container#rows method
232
- class TableRows < ElementCollections
233
- include CommonCollection
234
- def element_class; TableRow; end
235
- def element_tag; 'TR'; end
236
- end
237
- # this class accesses the table cells in the document as a collection
238
- # Normally a user would not need to create this object as it is returned by the Watir::Container#cells method
239
- class TableCells < ElementCollections
240
- include CommonCollection
241
- def element_class; TableCell; end
242
- def element_tag; 'TD'; end
243
- end
244
- # this class accesses the labels in the document as a collection
245
- # Normally a user would not need to create this object as it is returned by the Watir::Container#labels method
246
- class Labels < ElementCollections
247
- include CommonCollection
248
- def element_class; Label; end
249
- def element_tag; 'LABEL'; end
250
-
251
- private
252
- def set_show_items
253
- super
254
- @show_attributes.add("htmlFor", 20)
255
- end
256
- end
257
-
258
- # this class accesses the pre tags in the document as a collection
259
- # Normally a user would not need to create this object as it is returned by the Watir::Container#pres method
260
- class Pres < ElementCollections
261
- include CommonCollection
262
- def element_class; Pre; end
263
-
264
- private
265
- def set_show_items
266
- super
267
- @show_attributes.delete("name")
268
- @show_attributes.add("className", 20)
269
- end
270
- end
271
-
272
- # this class accesses the p tags in the document as a collection
273
- # Normally a user would not need to create this object as it is returned by the Watir::Container#ps method
274
- class Ps < ElementCollections
275
- include CommonCollection
276
- def element_class; P; end
277
-
278
- private
279
- def set_show_items
280
- super
281
- @show_attributes.delete("name")
282
- @show_attributes.add("className", 20)
283
- end
284
-
285
- end
286
- # this class accesses the spans in the document as a collection
287
- # Normally a user would not need to create this object as it is returned by the Watir::Container#spans method
288
- class Spans < ElementCollections
289
- include CommonCollection
290
- def element_class; Span; end
291
-
292
- private
293
- def set_show_items
294
- super
295
- @show_attributes.delete("name")
296
- @show_attributes.add("className", 20)
297
- end
298
- end
299
-
300
- # this class accesses the divs in the document as a collection
301
- # Normally a user would not need to create this object as it is returned by the Watir::Container#divs method
302
- class Divs < ElementCollections
303
- include CommonCollection
304
- def element_class; Div; end
305
-
306
- private
307
- def set_show_items
308
- super
309
- @show_attributes.delete("name")
310
- @show_attributes.add("className", 20)
311
- end
312
- end
313
-
314
- class Dls < ElementCollections
315
- include CommonCollection
316
- def element_class; Dl; end
317
- def element_tag; Dl::TAG; end
318
- end
319
-
320
- class Dts < ElementCollections
321
- include CommonCollection
322
- def element_class; Dt; end
323
- def element_tag; Dt::TAG; end
324
- end
325
-
326
- class Dds < ElementCollections
327
- include CommonCollection
328
- def element_class; Dd; end
329
- def element_tag; Dd::TAG; end
330
- end
331
-
332
- class Strongs < ElementCollections
333
- include CommonCollection
334
- def element_class; Strong; end
335
- def element_tag; Strong::TAG; end
336
- end
337
-
338
- class Ems < ElementCollections
339
- include CommonCollection
340
- def element_class; Em; end
341
- def element_tag; Em::TAG; end
342
- end
343
-
344
- end
1
+ module Watir
2
+ #--
3
+ # These classes are not for public consumption, so we switch off rdoc
4
+
5
+ # presumes element_class or element_tag is defined
6
+ # for subclasses of ElementCollections
7
+ module CommonCollection #:nodoc:all
8
+ def element_tag
9
+ element_class::TAG
10
+ end
11
+
12
+ def length
13
+ @container.document.getElementsByTagName(element_tag).length
14
+ end
15
+ alias_method :size, :length
16
+ end
17
+
18
+ # This class is used as part of the .show method of the iterators class
19
+ # it would not normally be used by a user
20
+ class AttributeLengthPairs #:nodoc:all
21
+
22
+ # This class is used as part of the .show method of the iterators class
23
+ # it would not normally be used by a user
24
+ class AttributeLengthHolder
25
+ attr_accessor :attribute
26
+ attr_accessor :length
27
+
28
+ def initialize(attrib, length)
29
+ @attribute = attrib
30
+ @length = length
31
+ end
32
+ end
33
+
34
+ def initialize(attrib=nil, length=nil)
35
+ @attr=[]
36
+ add(attrib, length) if attrib
37
+ @index_counter = 0
38
+ end
39
+
40
+ # BUG: Untested. (Null implementation passes all tests.)
41
+ def add(attrib, length)
42
+ @attr << AttributeLengthHolder.new(attrib, length)
43
+ end
44
+
45
+ def delete(attrib)
46
+ item_to_delete = nil
47
+ @attr.each_with_index do |e,i|
48
+ item_to_delete = i if e.attribute == attrib
49
+ end
50
+ @attr.delete_at(item_to_delete) unless item_to_delete == nil
51
+ end
52
+
53
+ def next
54
+ temp = @attr[@index_counter]
55
+ @index_counter += 1
56
+ return temp
57
+ end
58
+
59
+ def each
60
+ 0.upto(@attr.length-1) { |i | yield @attr[i] }
61
+ end
62
+ end
63
+
64
+ # resume rdoc
65
+ #++
66
+
67
+ # this class accesses the buttons in the document as a collection
68
+ # it would normally only be accessed by the Watir::Container#buttons method
69
+ class Buttons < ElementCollections
70
+ def element_class; Button; end
71
+ # number of buttons
72
+ # browser.buttons.length
73
+ def length
74
+ get_length_of_input_objects(["button", "submit", "image"])
75
+ end
76
+
77
+ private
78
+ def set_show_items
79
+ super
80
+ @show_attributes.add("disabled", 9)
81
+ @show_attributes.add("value", 20)
82
+ end
83
+ end
84
+
85
+ # this class accesses the file fields in the document as a collection
86
+ # normal access is via the Container#file_fields method
87
+ class FileFields < ElementCollections
88
+ def element_class; FileField; end
89
+ # number of file_fields
90
+ # browser.file_fields.length
91
+ def length
92
+ get_length_of_input_objects(["file"])
93
+ end
94
+
95
+ private
96
+ def set_show_items
97
+ super
98
+ @show_attributes.add("disabled", 9)
99
+ @show_attributes.add("value", 20)
100
+ end
101
+ end
102
+
103
+ # this class accesses the check boxes in the document as a collection
104
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#checkboxes method
105
+ class CheckBoxes < ElementCollections
106
+ def element_class; CheckBox; end
107
+ # number of checkboxes
108
+ # browser.checkboxes.length
109
+ def length
110
+ get_length_of_input_objects("checkbox")
111
+ end
112
+
113
+ private
114
+ def iterator_object(i)
115
+ @container.checkbox(:index, i + 1)
116
+ end
117
+ end
118
+
119
+ # this class accesses the radio buttons in the document as a collection
120
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#radios method
121
+ class Radios < ElementCollections
122
+ def element_class; Radio; end
123
+ # number of radios
124
+ # browser.radios.length
125
+ def length
126
+ get_length_of_input_objects("radio")
127
+ end
128
+
129
+ private
130
+ def iterator_object(i)
131
+ @container.radio(:index, i + 1)
132
+ end
133
+ end
134
+
135
+ # this class accesses the select boxes in the document as a collection
136
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#select_lists method
137
+ class SelectLists < ElementCollections
138
+ include CommonCollection
139
+ def element_class; SelectList; end
140
+ def element_tag; 'SELECT'; end
141
+ end
142
+
143
+ # this class accesses the links in the document as a collection
144
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#links method
145
+ class Links < ElementCollections
146
+ include CommonCollection
147
+ def element_class; Link; end
148
+ def element_tag; 'A'; end
149
+
150
+ private
151
+ def set_show_items
152
+ super
153
+ @show_attributes.add("href", 60)
154
+ @show_attributes.add("innerText", 60)
155
+ end
156
+ end
157
+
158
+ class Lis < ElementCollections
159
+ include CommonCollection
160
+ def element_class; Li; end
161
+
162
+ private
163
+ def set_show_items
164
+ super
165
+ @show_attributes.delete( "name")
166
+ @show_attributes.add( "className" , 20)
167
+ end
168
+ end
169
+
170
+ # this class accesses the maps in the document as a collection
171
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#maps method
172
+ class Maps < ElementCollections
173
+ include CommonCollection
174
+ def element_class; Map; end
175
+ def element_tag; 'MAP'; end
176
+ end
177
+
178
+
179
+ # this class accesses the areas in the document as a collection
180
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#areas method
181
+ class Areas < ElementCollections
182
+ include CommonCollection
183
+ def element_class; Area; end
184
+ def element_tag; 'AREA'; end
185
+ end
186
+
187
+ # this class collects the images in the container
188
+ # An instance is returned by Watir::Container#images
189
+ class Images < ElementCollections
190
+ def element_class; Image; end
191
+ # number of images
192
+ # browser.images.length
193
+ def length
194
+ all = @container.document.all
195
+ imgs = []
196
+ all.each{|n| imgs << n if n.nodeName == "IMG"}
197
+ imgs.length
198
+ end
199
+
200
+ private
201
+ def set_show_items
202
+ super
203
+ @show_attributes.add("src", 60)
204
+ @show_attributes.add("alt", 30)
205
+ end
206
+ end
207
+
208
+ # this class accesses the text fields in the document as a collection
209
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#text_fields method
210
+ class TextFields < ElementCollections
211
+ def element_class; TextField; end
212
+ # number of text_fields
213
+ # browser.text_fields.length
214
+ def length
215
+ # text areas are also included in the TextFields, but we need to get them seperately
216
+ get_length_of_input_objects(["text", "password"]) +
217
+ @container.document.getElementsByTagName("textarea").length
218
+ end
219
+ end
220
+
221
+ # this class accesses the hidden fields in the document as a collection
222
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#hiddens method
223
+ class Hiddens < ElementCollections
224
+ def element_class; Hidden; end
225
+ # number of hidden elements
226
+ # browser.hiddens.length
227
+ def length
228
+ get_length_of_input_objects("hidden")
229
+ end
230
+ end
231
+
232
+ # this class accesses the text fields in the document as a collection
233
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#tables method
234
+ class Tables < ElementCollections
235
+ include CommonCollection
236
+ def element_class; Table; end
237
+ def element_tag; 'TABLE'; end
238
+
239
+ private
240
+ def set_show_items
241
+ super
242
+ @show_attributes.delete("name")
243
+ end
244
+ end
245
+ # this class accesses the table rows in the document as a collection
246
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#rows method
247
+ class TableRows < ElementCollections
248
+ include CommonCollection
249
+ def element_class; TableRow; end
250
+ def element_tag; 'TR'; end
251
+ end
252
+ # this class accesses the table cells in the document as a collection
253
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#cells method
254
+ class TableCells < ElementCollections
255
+ include CommonCollection
256
+ def element_class; TableCell; end
257
+ def element_tag; 'TD'; end
258
+ end
259
+ # this class accesses the labels in the document as a collection
260
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#labels method
261
+ class Labels < ElementCollections
262
+ include CommonCollection
263
+ def element_class; Label; end
264
+ def element_tag; 'LABEL'; end
265
+
266
+ private
267
+ def set_show_items
268
+ super
269
+ @show_attributes.add("htmlFor", 20)
270
+ end
271
+ end
272
+
273
+ # this class accesses the pre tags in the document as a collection
274
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#pres method
275
+ class Pres < ElementCollections
276
+ include CommonCollection
277
+ def element_class; Pre; end
278
+
279
+ private
280
+ def set_show_items
281
+ super
282
+ @show_attributes.delete("name")
283
+ @show_attributes.add("className", 20)
284
+ end
285
+ end
286
+
287
+ # this class accesses the p tags in the document as a collection
288
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#ps method
289
+ class Ps < ElementCollections
290
+ include CommonCollection
291
+ def element_class; P; end
292
+
293
+ private
294
+ def set_show_items
295
+ super
296
+ @show_attributes.delete("name")
297
+ @show_attributes.add("className", 20)
298
+ end
299
+
300
+ end
301
+ # this class accesses the spans in the document as a collection
302
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#spans method
303
+ class Spans < ElementCollections
304
+ include CommonCollection
305
+ def element_class; Span; end
306
+
307
+ private
308
+ def set_show_items
309
+ super
310
+ @show_attributes.delete("name")
311
+ @show_attributes.add("className", 20)
312
+ end
313
+ end
314
+
315
+ # this class accesses the divs in the document as a collection
316
+ # Normally a user would not need to create this object as it is returned by the Watir::Container#divs method
317
+ class Divs < ElementCollections
318
+ include CommonCollection
319
+ def element_class; Div; end
320
+
321
+ private
322
+ def set_show_items
323
+ super
324
+ @show_attributes.delete("name")
325
+ @show_attributes.add("className", 20)
326
+ end
327
+ end
328
+
329
+ class Dls < ElementCollections
330
+ include CommonCollection
331
+ def element_class; Dl; end
332
+ def element_tag; Dl::TAG; end
333
+ end
334
+
335
+ class Dts < ElementCollections
336
+ include CommonCollection
337
+ def element_class; Dt; end
338
+ def element_tag; Dt::TAG; end
339
+ end
340
+
341
+ class Dds < ElementCollections
342
+ include CommonCollection
343
+ def element_class; Dd; end
344
+ def element_tag; Dd::TAG; end
345
+ end
346
+
347
+ class Strongs < ElementCollections
348
+ include CommonCollection
349
+ def element_class; Strong; end
350
+ def element_tag; Strong::TAG; end
351
+ end
352
+
353
+ class Ems < ElementCollections
354
+ include CommonCollection
355
+ def element_class; Em; end
356
+ def element_tag; Em::TAG; end
357
+ end
358
+
359
+ class HTMLElements < ElementCollections
360
+ include CommonCollection
361
+ def element_class; HTMLElement; end
362
+ def element_tag; '*'; end
363
+
364
+ def initialize(container, how, what)
365
+ @how = how
366
+ @what = what
367
+ if how == :index
368
+ raise MissingWayOfFindingObjectException,
369
+ "#{self.class} does not support attribute #{@how}"
370
+ end
371
+ super(container)
372
+ end
373
+
374
+ def length
375
+ count = 0
376
+ each {|element| count += 1 }
377
+ count
378
+ end
379
+ alias :size :length
380
+
381
+ def each
382
+ @container.locate_all_elements(@how, @what).each { |element| yield element }
383
+ end
384
+
385
+ def iterator_object(i)
386
+ count = 0
387
+ each {|e| return e if count == i;count += 1;}
388
+ end
389
+
390
+ end
391
+
392
+ end