celerity 0.0.4 → 0.0.6

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 (158) hide show
  1. data/History.txt +33 -0
  2. data/README.txt +19 -9
  3. data/Rakefile +9 -3
  4. data/lib/celerity.rb +39 -39
  5. data/lib/celerity/browser.rb +538 -153
  6. data/lib/celerity/clickable_element.rb +48 -7
  7. data/lib/celerity/collections.rb +155 -131
  8. data/lib/celerity/container.rb +766 -385
  9. data/lib/celerity/default_viewer.rb +10 -0
  10. data/lib/celerity/disabled_element.rb +19 -2
  11. data/lib/celerity/element.rb +152 -83
  12. data/lib/celerity/element_collection.rb +106 -0
  13. data/lib/celerity/element_locator.rb +89 -66
  14. data/lib/celerity/elements/button.rb +23 -13
  15. data/lib/celerity/elements/file_field.rb +17 -5
  16. data/lib/celerity/elements/form.rb +21 -16
  17. data/lib/celerity/elements/frame.rb +75 -53
  18. data/lib/celerity/elements/image.rb +76 -63
  19. data/lib/celerity/elements/label.rb +4 -2
  20. data/lib/celerity/elements/link.rb +30 -18
  21. data/lib/celerity/elements/meta.rb +6 -0
  22. data/lib/celerity/{non_control_elements.rb → elements/non_control_elements.rb} +106 -76
  23. data/lib/celerity/elements/option.rb +16 -2
  24. data/lib/celerity/elements/radio_check.rb +55 -20
  25. data/lib/celerity/elements/select_list.rb +65 -29
  26. data/lib/celerity/elements/table.rb +141 -94
  27. data/lib/celerity/elements/table_cell.rb +13 -6
  28. data/lib/celerity/elements/{table_body.rb → table_elements.rb} +20 -8
  29. data/lib/celerity/elements/table_row.rb +23 -7
  30. data/lib/celerity/elements/text_field.rb +89 -33
  31. data/lib/celerity/exception.rb +77 -41
  32. data/lib/celerity/extra/method_generator.rb +42 -24
  33. data/lib/celerity/htmlunit.rb +49 -0
  34. data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
  35. data/lib/celerity/htmlunit/htmlunit-2.5-SNAPSHOT.jar +0 -0
  36. data/lib/celerity/htmlunit/htmlunit-core-js-2.5-SNAPSHOT.jar +0 -0
  37. data/lib/celerity/htmlunit/nekohtml-1.9.12-20090308.130127-11.jar +0 -0
  38. data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
  39. data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
  40. data/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
  41. data/lib/celerity/identifier.rb +3 -2
  42. data/lib/celerity/input_element.rb +5 -5
  43. data/lib/celerity/listener.rb +135 -0
  44. data/lib/celerity/resources/no_viewer.png +0 -0
  45. data/lib/celerity/util.rb +88 -0
  46. data/lib/celerity/version.rb +4 -3
  47. data/lib/celerity/watir_compatibility.rb +35 -25
  48. data/tasks/jar.rake +57 -0
  49. metadata +35 -142
  50. data.tar.gz.sig +0 -0
  51. data/Manifest.txt +0 -150
  52. data/lib/celerity/element_collections.rb +0 -54
  53. data/lib/celerity/element_map.rb +0 -51
  54. data/lib/celerity/elements/table_footer.rb +0 -30
  55. data/lib/celerity/elements/table_header.rb +0 -30
  56. data/lib/celerity/htmlunit/commons-collections-3.2.jar +0 -0
  57. data/lib/celerity/htmlunit/download.sh +0 -23
  58. data/lib/celerity/htmlunit/htmlunit-2.2.jar +0 -0
  59. data/lib/celerity/htmlunit/htmlunit-core-js-2.2.jar +0 -0
  60. data/lib/celerity/htmlunit/nekohtml-1.9.8.jar +0 -0
  61. data/lib/celerity/htmlunit/xalan-2.7.0.jar +0 -0
  62. data/lib/celerity/htmlunit/xml-apis-1.0.b2.jar +0 -0
  63. data/spec/area_spec.rb +0 -97
  64. data/spec/areas_spec.rb +0 -40
  65. data/spec/browser_spec.rb +0 -266
  66. data/spec/button_spec.rb +0 -227
  67. data/spec/buttons_spec.rb +0 -39
  68. data/spec/checkbox_spec.rb +0 -302
  69. data/spec/checkboxes_spec.rb +0 -38
  70. data/spec/div_spec.rb +0 -207
  71. data/spec/divs_spec.rb +0 -39
  72. data/spec/element_spec.rb +0 -79
  73. data/spec/filefield_spec.rb +0 -123
  74. data/spec/filefields_spec.rb +0 -40
  75. data/spec/form_spec.rb +0 -59
  76. data/spec/forms_spec.rb +0 -41
  77. data/spec/frame_spec.rb +0 -121
  78. data/spec/frames_spec.rb +0 -71
  79. data/spec/hidden_spec.rb +0 -127
  80. data/spec/hiddens_spec.rb +0 -39
  81. data/spec/hn_spec.rb +0 -104
  82. data/spec/hns_spec.rb +0 -45
  83. data/spec/html/2000_spans.html +0 -2009
  84. data/spec/html/bug_duplicate_attributes.html +0 -14
  85. data/spec/html/bug_javascript_001.html +0 -11
  86. data/spec/html/form_js_bug.html +0 -11
  87. data/spec/html/forms_with_input_elements.html +0 -114
  88. data/spec/html/frame_1.html +0 -17
  89. data/spec/html/frame_2.html +0 -16
  90. data/spec/html/frames.html +0 -11
  91. data/spec/html/iframes.html +0 -12
  92. data/spec/html/images.html +0 -27
  93. data/spec/html/images/1.gif +0 -0
  94. data/spec/html/images/2.gif +0 -0
  95. data/spec/html/images/3.gif +0 -0
  96. data/spec/html/images/button.jpg +0 -0
  97. data/spec/html/images/circle.jpg +0 -0
  98. data/spec/html/images/map.gif +0 -0
  99. data/spec/html/images/map2.gif +0 -0
  100. data/spec/html/images/minus.gif +0 -0
  101. data/spec/html/images/originaltriangle.jpg +0 -0
  102. data/spec/html/images/plus.gif +0 -0
  103. data/spec/html/images/square.jpg +0 -0
  104. data/spec/html/images/triangle.jpg +0 -0
  105. data/spec/html/invalid_js.html +0 -11
  106. data/spec/html/latin1_text.html +0 -17
  107. data/spec/html/non_control_elements.html +0 -115
  108. data/spec/html/simple_ajax.html +0 -22
  109. data/spec/html/tables.html +0 -119
  110. data/spec/html/utf8_text.html +0 -15
  111. data/spec/htmlunit_spec.rb +0 -26
  112. data/spec/image_spec.rb +0 -220
  113. data/spec/images_spec.rb +0 -39
  114. data/spec/label_spec.rb +0 -79
  115. data/spec/labels_spec.rb +0 -40
  116. data/spec/li_spec.rb +0 -139
  117. data/spec/link_spec.rb +0 -189
  118. data/spec/links_spec.rb +0 -43
  119. data/spec/lis_spec.rb +0 -40
  120. data/spec/map_spec.rb +0 -102
  121. data/spec/maps_spec.rb +0 -40
  122. data/spec/meta_spec.rb +0 -8
  123. data/spec/ol_spec.rb +0 -87
  124. data/spec/ols_spec.rb +0 -40
  125. data/spec/option_spec.rb +0 -154
  126. data/spec/p_spec.rb +0 -171
  127. data/spec/pre_spec.rb +0 -135
  128. data/spec/pres_spec.rb +0 -40
  129. data/spec/ps_spec.rb +0 -40
  130. data/spec/radio_spec.rb +0 -299
  131. data/spec/radios_spec.rb +0 -42
  132. data/spec/select_list_spec.rb +0 -299
  133. data/spec/select_lists_spec.rb +0 -47
  134. data/spec/span_spec.rb +0 -184
  135. data/spec/spans_spec.rb +0 -64
  136. data/spec/spec.opts +0 -1
  137. data/spec/spec_helper.rb +0 -55
  138. data/spec/table_bodies_spec.rb +0 -57
  139. data/spec/table_body_spec.rb +0 -111
  140. data/spec/table_cell_spec.rb +0 -74
  141. data/spec/table_cells_spec.rb +0 -59
  142. data/spec/table_footer_spec.rb +0 -101
  143. data/spec/table_footers_spec.rb +0 -55
  144. data/spec/table_header_spec.rb +0 -101
  145. data/spec/table_headers_spec.rb +0 -55
  146. data/spec/table_row_spec.rb +0 -104
  147. data/spec/table_rows_spec.rb +0 -58
  148. data/spec/table_spec.rb +0 -160
  149. data/spec/tables_spec.rb +0 -42
  150. data/spec/text_field_spec.rb +0 -323
  151. data/spec/text_fields_spec.rb +0 -44
  152. data/spec/ul_spec.rb +0 -88
  153. data/spec/uls_spec.rb +0 -40
  154. data/spec/watir_compatibility_spec.rb +0 -260
  155. data/support/spec_server.rb +0 -73
  156. data/tasks/rspec.rake +0 -30
  157. data/tasks/specserver.rake +0 -21
  158. metadata.gz.sig +0 -0
@@ -1,12 +1,53 @@
1
1
  module Celerity
2
2
  module ClickableElement
3
-
4
- # clicks the element
3
+
4
+ #
5
+ # click the element
6
+ #
7
+
5
8
  def click
6
- assert_exists
7
- assert_enabled
9
+ assert_exists_and_enabled
8
10
  @container.update_page(@object.click)
9
- end
10
-
11
+ end
12
+
13
+ #
14
+ # double click the element (Celerity only)
15
+ #
16
+
17
+ def double_click
18
+ assert_exists_and_enabled
19
+ @container.update_page(@object.dblClick)
20
+ end
21
+
22
+ #
23
+ # right click the element (Celerity only)
24
+ #
25
+
26
+ def right_click
27
+ assert_exists_and_enabled
28
+ @container.update_page(@object.rightClick)
29
+ end
30
+
31
+ #
32
+ # Click the element and return a new Browser instance with the resulting page.
33
+ # This is useful for elements that trigger popups when clicked.
34
+ #
35
+ # @return [Celerity::Browser]
36
+ #
37
+
38
+ def click_and_attach
39
+ assert_exists_and_enabled
40
+ browser = Browser.new(:log_level => @browser.log_level)
41
+ browser.update_page(@object.click)
42
+
43
+ browser
44
+ end
45
+
46
+ private
47
+
48
+ def assert_exists_and_enabled
49
+ assert_exists
50
+ assert_enabled if respond_to?(:assert_enabled)
51
+ end
11
52
  end
12
- end
53
+ end
@@ -1,132 +1,156 @@
1
- module Celerity
2
-
3
- class Frames < ElementCollections
4
- def element_class; Frame; end
5
- end
6
-
7
- class Buttons < ElementCollections
8
- def element_class; Button; end
9
- end
10
-
11
- class FileFields < ElementCollections
12
- def element_class; FileField; end
13
- end
14
-
15
- class CheckBoxes < ElementCollections
16
- def element_class; CheckBox; end
17
- end
18
-
19
- class Radios < ElementCollections
20
- def element_class; Radio; end
21
- end
22
-
23
- class SelectLists < ElementCollections
24
- def element_class; SelectList; end
25
- end
26
-
27
- class Links < ElementCollections
28
- def element_class; Link; end
29
- end
30
-
31
- class Uls < ElementCollections
32
- def element_class; Ul; end
33
- end
34
-
35
- class Ols < ElementCollections
36
- def element_class; Ol; end
37
- end
38
-
39
- class Lis < ElementCollections
40
- def element_class; Li; end
41
- end
42
-
43
- class Maps < ElementCollections
44
- def element_class; Map; end
45
- end
46
-
47
- class Areas < ElementCollections
48
- def element_class; Area; end
49
- end
50
-
51
- class Images < ElementCollections
52
- def element_class; Image; end
53
- end
54
-
55
- class TextFields < ElementCollections
56
- def element_class; TextField; end
57
- end
58
-
59
- class Hiddens < ElementCollections
60
- def element_class; Hidden; end
61
- end
62
-
63
- class Tables < ElementCollections
64
- def element_class; Table; end
65
- end
66
-
67
- class TableHeaders < ElementCollections
68
- def element_class; TableHeader; end
69
- end
70
- class TableBodies < ElementCollections
71
- def element_class; TableBody; end
72
- end
73
- class TableFooters < ElementCollections
74
- def element_class; TableFooter; end
75
- end
76
-
77
- class TableRows < ElementCollections
78
- def element_class; TableRow; end
79
- end
80
-
81
- class TableCells < ElementCollections
82
- def element_class; TableCell; end
83
- end
84
-
85
- class Labels < ElementCollections
86
- def element_class; Label; end
87
- end
88
-
89
- class Pres < ElementCollections
90
- def element_class; Pre; end
91
- end
92
-
93
- class Ps < ElementCollections
94
- def element_class; P; end
95
- end
96
-
97
- class Spans < ElementCollections
98
- def element_class; Span; end
99
- end
100
-
101
- class Divs < ElementCollections
102
- def element_class; Div; end
103
- end
104
-
105
- class Forms < ElementCollections
106
- def element_class; Form; end
107
- end
108
-
109
- class Options < ElementCollections
110
- def element_class; Option; end
111
- end
112
-
113
- class H1s < ElementCollections
114
- def element_class; H1; end
115
- end
116
- class H2s < ElementCollections
117
- def element_class; H2; end
118
- end
119
- class H3s < ElementCollections
120
- def element_class; H3; end
121
- end
122
- class H4s < ElementCollections
123
- def element_class; H4; end
124
- end
125
- class H5s < ElementCollections
126
- def element_class; H5; end
127
- end
128
- class H6s < ElementCollections
129
- def element_class; H6; end
130
- end
131
-
1
+ module Celerity
2
+
3
+ class Frames < ElementCollection
4
+ def element_class; Frame; end
5
+ end
6
+
7
+ class Buttons < ElementCollection
8
+ def element_class; Button; end
9
+ end
10
+
11
+ class FileFields < ElementCollection
12
+ def element_class; FileField; end
13
+ end
14
+
15
+ class CheckBoxes < ElementCollection
16
+ def element_class; CheckBox; end
17
+ end
18
+
19
+ class Radios < ElementCollection
20
+ def element_class; Radio; end
21
+ end
22
+
23
+ class SelectLists < ElementCollection
24
+ def element_class; SelectList; end
25
+ end
26
+
27
+ class Links < ElementCollection
28
+ def element_class; Link; end
29
+ end
30
+
31
+ class Uls < ElementCollection
32
+ def element_class; Ul; end
33
+ end
34
+
35
+ class Ols < ElementCollection
36
+ def element_class; Ol; end
37
+ end
38
+
39
+ class Lis < ElementCollection
40
+ def element_class; Li; end
41
+ end
42
+
43
+ class Dds < ElementCollection
44
+ def element_class; Dd; end
45
+ end
46
+
47
+ class Dls < ElementCollection
48
+ def element_class; Dl; end
49
+ end
50
+
51
+ class Dts < ElementCollection
52
+ def element_class; Dt; end
53
+ end
54
+
55
+ class Ems < ElementCollection
56
+ def element_class; Em; end
57
+ end
58
+
59
+ class Maps < ElementCollection
60
+ def element_class; Map; end
61
+ end
62
+
63
+ class Areas < ElementCollection
64
+ def element_class; Area; end
65
+ end
66
+
67
+ class Images < ElementCollection
68
+ def element_class; Image; end
69
+ end
70
+
71
+ class TextFields < ElementCollection
72
+ def element_class; TextField; end
73
+ end
74
+
75
+ class Hiddens < ElementCollection
76
+ def element_class; Hidden; end
77
+ end
78
+
79
+ class Tables < ElementCollection
80
+ def element_class; Table; end
81
+ end
82
+
83
+ class TableHeaders < ElementCollection
84
+ def element_class; TableHeader; end
85
+ end
86
+ class TableBodies < ElementCollection
87
+ def element_class; TableBody; end
88
+ end
89
+ class TableFooters < ElementCollection
90
+ def element_class; TableFooter; end
91
+ end
92
+
93
+ class TableRows < ElementCollection
94
+ def element_class; TableRow; end
95
+ end
96
+
97
+ class TableCells < ElementCollection
98
+ def element_class; TableCell; end
99
+ end
100
+
101
+ class Labels < ElementCollection
102
+ def element_class; Label; end
103
+ end
104
+
105
+ class Pres < ElementCollection
106
+ def element_class; Pre; end
107
+ end
108
+
109
+ class Ps < ElementCollection
110
+ def element_class; P; end
111
+ end
112
+
113
+ class Spans < ElementCollection
114
+ def element_class; Span; end
115
+ end
116
+
117
+ class Strongs < ElementCollection
118
+ def element_class; Strong; end
119
+ end
120
+
121
+ class Divs < ElementCollection
122
+ def element_class; Div; end
123
+ end
124
+
125
+ class Forms < ElementCollection
126
+ def element_class; Form; end
127
+ end
128
+
129
+ class Options < ElementCollection
130
+ def element_class; Option; end
131
+ end
132
+
133
+ class Metas < ElementCollection
134
+ def element_class; Meta; end
135
+ end
136
+
137
+ class H1s < ElementCollection
138
+ def element_class; H1; end
139
+ end
140
+ class H2s < ElementCollection
141
+ def element_class; H2; end
142
+ end
143
+ class H3s < ElementCollection
144
+ def element_class; H3; end
145
+ end
146
+ class H4s < ElementCollection
147
+ def element_class; H4; end
148
+ end
149
+ class H5s < ElementCollection
150
+ def element_class; H5; end
151
+ end
152
+ class H6s < ElementCollection
153
+ def element_class; H6; end
154
+ end
155
+
132
156
  end
@@ -1,385 +1,766 @@
1
- module Celerity
2
-
3
- # This class contains methods for accessing elements inside a container.
4
- # (usually the Browser object, meaning the current page).
5
- #
6
- # The most common syntax is
7
- # browser.elem(:attribute, 'value')
8
- #
9
- # Note that the element is located lazily, so no exceptions will be thrown
10
- # if the element doesn't exist until you call a method on the resulting object.
11
- # To do this you would normally use +Element#exists?+ or an action method,
12
- # like +ClickableElement#click+.
13
- #
14
- # You can also pass in a hash:
15
- #
16
- # browser.link(:index => 1).click
17
- #
18
- # All elements support multiple attributes identification using the
19
- # hash syntax (though might not always be compatible with Watir):
20
- #
21
- # browser.span(:class_name => 'product', :index => 5).text
22
- #
23
- # You can also get all the elements of a certain type by using the plural form:
24
- #
25
- # browser.links => #<Celerity::Links:0x7a1c2da2 ...>
26
- #
27
- # See +Celerity::ElementCollections+ for details.
28
- module Container
29
- include Celerity::Exception
30
- attr_accessor :page_container
31
-
32
- def container=(container)
33
- @container = container
34
- @page_container = container.page_container
35
- container
36
- end
37
-
38
- def update_page(page)
39
- @page_container.page = page
40
- end
41
-
42
- def frame(*args)
43
- assert_exists
44
- Frame.new(self, *args)
45
- end
46
-
47
- def frames
48
- assert_exists
49
- Frames.new(self)
50
- end
51
-
52
- def table(*args)
53
- assert_exists
54
- Table.new(self, *args)
55
- end
56
-
57
- def tables
58
- assert_exists
59
- Tables.new(self)
60
- end
61
-
62
- def thead(*args)
63
- assert_exists
64
- TableHeader.new(self, *args)
65
- end
66
-
67
- def theads
68
- assert_exists
69
- TableHeaders.new(self)
70
- end
71
-
72
- def tbody(*args)
73
- assert_exists
74
- TableBody.new(self, *args)
75
- end
76
-
77
- def tbodies
78
- assert_exists
79
- TableBodies.new(self)
80
- end
81
-
82
- def tfoot(*args)
83
- assert_exists
84
- TableFooter.new(self, *args)
85
- end
86
-
87
- def tfoots
88
- assert_exists
89
- TableFooters.new(self)
90
- end
91
- alias_method :tfeet, :tfoots # :-)
92
-
93
- def cell(*args)
94
- assert_exists
95
- TableCell.new(self, *args)
96
- end
97
-
98
- def cells
99
- assert_exists
100
- TableCells.new(self)
101
- end
102
-
103
- def row(*args)
104
- assert_exists
105
- TableRow.new(self, *args)
106
- end
107
-
108
- def rows
109
- assert_exists
110
- TableRows.new(self)
111
- end
112
-
113
- def button(*args)
114
- assert_exists
115
- Button.new(self, *args)
116
- end
117
-
118
- def buttons
119
- assert_exists
120
- Buttons.new(self)
121
- end
122
-
123
- def file_field(*args)
124
- assert_exists
125
- FileField.new(self, *args)
126
- end
127
-
128
- def file_fields
129
- assert_exists
130
- FileFields.new(self)
131
- end
132
-
133
- def text_field(*args)
134
- assert_exists
135
- TextField.new(self, *args)
136
- end
137
-
138
- def text_fields
139
- assert_exists
140
- TextFields.new(self)
141
- end
142
-
143
- def hidden(*args)
144
- assert_exists
145
- Hidden.new(self, *args)
146
- end
147
-
148
- def hiddens
149
- assert_exists
150
- Hiddens.new(self)
151
- end
152
-
153
- def select_list(*args)
154
- assert_exists
155
- SelectList.new(self, *args)
156
- end
157
-
158
- def select_lists
159
- assert_exists
160
- SelectLists.new(self)
161
- end
162
-
163
- def option(*args)
164
- assert_exists
165
- Option.new(self, *args)
166
- end
167
-
168
- def check_box(*args)
169
- assert_exists
170
- CheckBox.new(self, *args)
171
- end
172
-
173
- def checkboxes
174
- assert_exists
175
- CheckBoxes.new(self)
176
- end
177
-
178
- def radio(*args)
179
- assert_exists
180
- Radio.new(self, *args)
181
- end
182
-
183
- def radios
184
- assert_exists
185
- Radios.new(self)
186
- end
187
-
188
- def link(*args)
189
- assert_exists
190
- Link.new(self, *args)
191
- end
192
-
193
- def links
194
- assert_exists
195
- Links.new(self)
196
- end
197
-
198
- def ul(*args)
199
- assert_exists
200
- Ul.new(self, *args)
201
- end
202
-
203
- def uls
204
- assert_exists
205
- Uls.new(self)
206
- end
207
-
208
- def ol(*args)
209
- assert_exists
210
- Ol.new(self, *args)
211
- end
212
-
213
- def ols
214
- assert_exists
215
- Ols.new(self)
216
- end
217
-
218
- def li(*args)
219
- assert_exists
220
- Li.new(self, *args)
221
- end
222
-
223
- def lis
224
- assert_exists
225
- Lis.new(self)
226
- end
227
-
228
- def map(*args)
229
- assert_exists
230
- Map.new(self, *args)
231
- end
232
-
233
- def maps
234
- assert_exists
235
- Maps.new(self)
236
- end
237
-
238
- def area(*args)
239
- assert_exists
240
- Area.new(self, *args)
241
- end
242
-
243
- def areas
244
- assert_exists
245
- Areas.new(self)
246
- end
247
-
248
- def image(*args)
249
- assert_exists
250
- Image.new(self, *args)
251
- end
252
-
253
- def images
254
- assert_exists
255
- Images.new(self)
256
- end
257
-
258
- def div(*args)
259
- assert_exists
260
- Div.new(self, *args)
261
- end
262
-
263
- def divs
264
- assert_exists
265
- Divs.new(self)
266
- end
267
-
268
- def form(*args)
269
- assert_exists
270
- Form.new(self, *args)
271
- end
272
-
273
- def forms
274
- assert_exists
275
- Forms.new(self)
276
- end
277
-
278
- def span(*args)
279
- assert_exists
280
- Span.new(self, *args)
281
- end
282
-
283
- def spans
284
- assert_exists
285
- Spans.new(self)
286
- end
287
-
288
- def p(*args)
289
- assert_exists
290
- P.new(self, *args)
291
- end
292
-
293
- def ps
294
- assert_exists
295
- Ps.new(self)
296
- end
297
-
298
- def pre(*args)
299
- assert_exists
300
- Pre.new(self, *args)
301
- end
302
-
303
- def pres
304
- assert_exists
305
- Pres.new(self)
306
- end
307
-
308
- def label(*args)
309
- assert_exists
310
- Label.new(self, *args)
311
- end
312
-
313
- def labels
314
- assert_exists
315
- Labels.new(self)
316
- end
317
-
318
- def h1(*args)
319
- assert_exists
320
- H1.new(self, *args)
321
- end
322
-
323
- def h2(*args)
324
- assert_exists
325
- H2.new(self, *args)
326
- end
327
-
328
- def h3(*args)
329
- assert_exists
330
- H3.new(self, *args)
331
- end
332
-
333
- def h4(*args)
334
- assert_exists
335
- H4.new(self, *args)
336
- end
337
-
338
- def h5(*args)
339
- assert_exists
340
- H5.new(self, *args)
341
- end
342
-
343
- def h6(*args)
344
- assert_exists
345
- H6.new(self, *args)
346
- end
347
-
348
- def h1s
349
- assert_exists
350
- H1s.new(self)
351
- end
352
-
353
- def h2s
354
- assert_exists
355
- H2s.new(self)
356
- end
357
-
358
- def h3s
359
- assert_exists
360
- H3s.new(self)
361
- end
362
-
363
- def h4s
364
- assert_exists
365
- H4s.new(self)
366
- end
367
-
368
- def h5s
369
- assert_exists
370
- H5s.new(self)
371
- end
372
-
373
- def h6s
374
- assert_exists
375
- H6s.new(self)
376
- end
377
-
378
- private
379
-
380
- def matches?(string, what)
381
- Regexp === what ? string.match(what) : string == what.to_s
382
- end
383
-
384
- end # Container
385
- end # Celerity
1
+ module Celerity
2
+
3
+ #
4
+ # This class contains methods for accessing elements inside a container,
5
+ # usually the Browser object, meaning the current page.
6
+ # The most common syntax is
7
+ # browser.elem(:attribute, 'value')
8
+ #
9
+ # Note that the element is located lazily, so no exceptions will be raised
10
+ # if the element doesn't exist until you call a method on the resulting object.
11
+ # To do this you would normally use Element#exists? or an action method,
12
+ # like ClickableElement#click.
13
+ # You can also pass in a hash:
14
+ #
15
+ # browser.link(:index => 1).click
16
+ #
17
+ # All elements support multiple attributes identification using the
18
+ # hash syntax (though this might not always be compatible with Watir):
19
+ #
20
+ # browser.span(:class_name => 'product', :index => 5).text
21
+ #
22
+ # Checkboxes and radio buttons support a special three-argument syntax:
23
+ #
24
+ # browser.check_box(:name, 'a_name', '1234').set
25
+ #
26
+ # You can also get all the elements of a certain type by using the plural form (@see Celerity::ElementCollection):
27
+ #
28
+ # browser.links # => #<Celerity::Links:0x7a1c2da2 ...>
29
+ #
30
+
31
+ module Container
32
+ include Celerity::Exception
33
+
34
+ # Points back to the Browser instance that contains this element
35
+ attr_reader :browser
36
+
37
+ #
38
+ # Check if the element contains the given text.
39
+ #
40
+ # @param [String, Regexp] expected_text The text to look for.
41
+ # @return [Fixnum, nil] The index of the matched text, or nil if it doesn't match.
42
+ #
43
+
44
+ def contains_text(expected_text)
45
+ assert_exists
46
+ return nil unless respond_to? :text
47
+
48
+ case expected_text
49
+ when Regexp
50
+ text() =~ expected_text
51
+ when String
52
+ text().index(expected_text)
53
+ else
54
+ raise TypeError, "expected String or Regexp, got #{expected_text.inspect}:#{expected_text.class}"
55
+ end
56
+ end
57
+
58
+ #
59
+ # Used internally to update the container object.
60
+ # @api private
61
+ #
62
+
63
+ def container=(container)
64
+ @container = container
65
+ @browser = container.browser
66
+ container
67
+ end
68
+
69
+ #
70
+ # Used internally to update the page object.
71
+ # @api private
72
+ #
73
+
74
+ def update_page(page)
75
+ @browser.page = page
76
+ end
77
+
78
+ #
79
+ # Used internally.
80
+ #
81
+ # @param [String] string The string to match against.
82
+ # @param [Regexp, String, #to_s] what The match we're looking for.
83
+ # @return [Fixnum, true, false, nil]
84
+ #
85
+ # @api private
86
+ #
87
+
88
+ def matches?(string, what)
89
+ Regexp === what ? string =~ what : string == what.to_s
90
+ end
91
+
92
+ #--
93
+ # below methods sorted alphabetically
94
+ #++
95
+
96
+ #
97
+ # @return [Celerity::Area]
98
+ #
99
+
100
+ def area(*args)
101
+ Area.new(self, *args)
102
+ end
103
+
104
+ #
105
+ # @return [Celerity::Areas]
106
+ #
107
+
108
+ def areas
109
+ Areas.new(self)
110
+ end
111
+
112
+ #
113
+ # @return [Celerity::Button]
114
+ #
115
+
116
+ def button(*args)
117
+ Button.new(self, *args)
118
+ end
119
+
120
+ #
121
+ # @return [Celerity::Buttons]
122
+ #
123
+
124
+ def buttons
125
+ Buttons.new(self)
126
+ end
127
+
128
+ #
129
+ # @return [Celerity::TableCell]
130
+ #
131
+
132
+ def cell(*args)
133
+ TableCell.new(self, *args)
134
+ end
135
+
136
+ #
137
+ # @return [Celerity::TableCells]
138
+ #
139
+
140
+ def cells
141
+ TableCells.new(self)
142
+ end
143
+
144
+ #
145
+ # Since finding checkboxes by value is very common, you can use this shorthand:
146
+ #
147
+ # browser.check_box(:name, 'a_name', '1234').set
148
+ #
149
+ # or
150
+ #
151
+ # browser.check_box(:name => 'a_name', :value => '1234').set
152
+ #
153
+ # @return [Celerity::CheckBox]
154
+ #
155
+
156
+ def check_box(*args)
157
+ CheckBox.new(self, *args)
158
+ end
159
+
160
+ #
161
+ # @return [Celerity::CheckBoxes]
162
+ #
163
+
164
+ def checkboxes
165
+ CheckBoxes.new(self)
166
+ end
167
+
168
+ #
169
+ # @return [Celerity::Dd]
170
+ #
171
+
172
+ def dd(*args)
173
+ Dd.new(self, *args)
174
+ end
175
+
176
+ #
177
+ # @return [Celerity::Dds]
178
+ #
179
+
180
+ def dds
181
+ Dds.new(self)
182
+ end
183
+
184
+ #
185
+ # @return [Celerity::Div]
186
+ #
187
+
188
+ def div(*args)
189
+ Div.new(self, *args)
190
+ end
191
+
192
+ #
193
+ # @return [Celerity::Divs]
194
+ #
195
+
196
+ def divs
197
+ Divs.new(self)
198
+ end
199
+
200
+ #
201
+ # @return [Celerity::Dl]
202
+ #
203
+
204
+ def dl(*args)
205
+ Dl.new(self, *args)
206
+ end
207
+
208
+ #
209
+ # @return [Celerity::Dls]
210
+ #
211
+
212
+ def dls
213
+ Dls.new(self)
214
+ end
215
+
216
+ #
217
+ # @return [Celerity::Dt]
218
+ #
219
+
220
+ def dt(*args)
221
+ Dt.new(self, *args)
222
+ end
223
+
224
+ #
225
+ # @return [Celerity::Dts]
226
+ #
227
+
228
+ def dts
229
+ Dts.new(self)
230
+ end
231
+
232
+ #
233
+ # @return [Celerity::Em]
234
+ #
235
+
236
+ def em(*args)
237
+ Em.new(self, *args)
238
+ end
239
+
240
+ #
241
+ # @return [Celerity::Ems]
242
+ #
243
+
244
+ def ems
245
+ Ems.new(self)
246
+ end
247
+
248
+ #
249
+ # @return [Celerity::FileField]
250
+ #
251
+
252
+ def file_field(*args)
253
+ FileField.new(self, *args)
254
+ end
255
+
256
+ #
257
+ # @return [Celerity::FileFields]
258
+ #
259
+
260
+ def file_fields
261
+ FileFields.new(self)
262
+ end
263
+
264
+ #
265
+ # @return [Celerity::Form]
266
+ #
267
+
268
+ def form(*args)
269
+ Form.new(self, *args)
270
+ end
271
+
272
+ #
273
+ # @return [Celerity::Forms]
274
+ #
275
+
276
+ def forms
277
+ Forms.new(self)
278
+ end
279
+
280
+ #
281
+ # @return [Celerity::Frame]
282
+ #
283
+
284
+ def frame(*args)
285
+ Frame.new(self, *args)
286
+ end
287
+
288
+ #
289
+ # @return [Celerity::Frames]
290
+ #
291
+
292
+ def frames
293
+ Frames.new(self)
294
+ end
295
+
296
+ #
297
+ # @return [Celerity::H1]
298
+ #
299
+
300
+ def h1(*args)
301
+ H1.new(self, *args)
302
+ end
303
+
304
+ #
305
+ # @return [Celerity::H1s]
306
+ #
307
+
308
+ def h1s
309
+ H1s.new(self)
310
+ end
311
+
312
+ #
313
+ # @return [Celerity::H2]
314
+ #
315
+
316
+ def h2(*args)
317
+ H2.new(self, *args)
318
+ end
319
+
320
+ #
321
+ # @return [Celerity::H2s]
322
+ #
323
+
324
+ def h2s
325
+ H2s.new(self)
326
+ end
327
+
328
+ #
329
+ # @return [Celerity::H3]
330
+ #
331
+
332
+ def h3(*args)
333
+ H3.new(self, *args)
334
+ end
335
+
336
+ #
337
+ # @return [Celerity::H3s]
338
+ #
339
+
340
+ def h3s
341
+ H3s.new(self)
342
+ end
343
+
344
+ #
345
+ # @return [Celerity::H4]
346
+ #
347
+
348
+ def h4(*args)
349
+ H4.new(self, *args)
350
+ end
351
+
352
+ #
353
+ # @return [Celerity::H4s]
354
+ #
355
+
356
+ def h4s
357
+ H4s.new(self)
358
+ end
359
+
360
+ #
361
+ # @return [Celerity::H5]
362
+ #
363
+
364
+ def h5(*args)
365
+ H5.new(self, *args)
366
+ end
367
+
368
+ #
369
+ # @return [Celerity::H5s]
370
+ #
371
+
372
+ def h5s
373
+ H5s.new(self)
374
+ end
375
+
376
+ #
377
+ # @return [Celerity::H6]
378
+ #
379
+
380
+ def h6(*args)
381
+ H6.new(self, *args)
382
+ end
383
+
384
+ #
385
+ # @return [Celerity::H6s]
386
+ #
387
+
388
+ def h6s
389
+ H6s.new(self)
390
+ end
391
+
392
+ #
393
+ # @return [Celerity::Hidden]
394
+ #
395
+
396
+ def hidden(*args)
397
+ Hidden.new(self, *args)
398
+ end
399
+
400
+ #
401
+ # @return [Celerity::Hiddens]
402
+ #
403
+
404
+ def hiddens
405
+ Hiddens.new(self)
406
+ end
407
+
408
+ #
409
+ # @return [Celerity::Image]
410
+ #
411
+
412
+ def image(*args)
413
+ Image.new(self, *args)
414
+ end
415
+
416
+ #
417
+ # @return [Celerity::Images]
418
+ #
419
+
420
+ def images
421
+ Images.new(self)
422
+ end
423
+
424
+ #
425
+ # @return [Celerity::Label]
426
+ #
427
+
428
+ def label(*args)
429
+ Label.new(self, *args)
430
+ end
431
+
432
+ #
433
+ # @return [Celerity::Labels]
434
+ #
435
+
436
+ def labels
437
+ Labels.new(self)
438
+ end
439
+
440
+ #
441
+ # @return [Celerity::Li]
442
+ #
443
+
444
+ def li(*args)
445
+ Li.new(self, *args)
446
+ end
447
+
448
+ #
449
+ # @return [Celerity::Lis]
450
+ #
451
+
452
+ def lis
453
+ Lis.new(self)
454
+ end
455
+
456
+ #
457
+ # @return [Celerity::Link]
458
+ #
459
+
460
+ def link(*args)
461
+ Link.new(self, *args)
462
+ end
463
+
464
+ #
465
+ # @return [Celerity::Links]
466
+ #
467
+
468
+ def links
469
+ Links.new(self)
470
+ end
471
+
472
+ #
473
+ # @return [Celerity::Map]
474
+ #
475
+
476
+ def map(*args)
477
+ Map.new(self, *args)
478
+ end
479
+
480
+ #
481
+ # @return [Celerity::Maps]
482
+ #
483
+
484
+ def maps
485
+ Maps.new(self)
486
+ end
487
+
488
+ #
489
+ # @return [Celerity::Meta]
490
+ #
491
+
492
+ def meta(*args)
493
+ Meta.new(self, *args)
494
+ end
495
+
496
+ #
497
+ # @return [Celerity::Metas]
498
+ #
499
+
500
+ def metas(*args)
501
+ Metas.new(self, *args)
502
+ end
503
+
504
+ #
505
+ # @return [Celerity::Ol]
506
+ #
507
+
508
+ def ol(*args)
509
+ Ol.new(self, *args)
510
+ end
511
+
512
+ #
513
+ # @return [Celerity::Ols]
514
+ #
515
+
516
+ def ols
517
+ Ols.new(self)
518
+ end
519
+
520
+ #
521
+ # @return [Celerity::Option]
522
+ #
523
+
524
+ def option(*args)
525
+ Option.new(self, *args)
526
+ end
527
+
528
+ #
529
+ # @return [Celerity::P]
530
+ #
531
+
532
+ def p(*args)
533
+ P.new(self, *args)
534
+ end
535
+
536
+ #
537
+ # @return [Celerity::Ps]
538
+ #
539
+
540
+ def ps
541
+ Ps.new(self)
542
+ end
543
+
544
+ #
545
+ # @return [Celerity::Pre]
546
+ #
547
+
548
+ def pre(*args)
549
+ Pre.new(self, *args)
550
+ end
551
+
552
+ #
553
+ # @return [Celerity::Pres]
554
+ #
555
+
556
+ def pres
557
+ Pres.new(self)
558
+ end
559
+
560
+ #
561
+ # Since finding radios by value is very common, you can use this shorthand:
562
+ #
563
+ # browser.radio(:name, 'a_name', '1234').set
564
+ #
565
+ # or
566
+ #
567
+ # browser.radio(:name => 'a_name', :value => '1234').set
568
+ #
569
+ # @return [Celerity::Radio]
570
+ #
571
+
572
+ def radio(*args)
573
+ Radio.new(self, *args)
574
+ end
575
+
576
+ #
577
+ # @return [Celerity::Radios]
578
+ #
579
+
580
+ def radios
581
+ Radios.new(self)
582
+ end
583
+
584
+ #
585
+ # @return [Celerity::TableRow]
586
+ #
587
+
588
+ def row(*args)
589
+ TableRow.new(self, *args)
590
+ end
591
+
592
+ #
593
+ # @return [Celerity::TableRows]
594
+ #
595
+
596
+ def rows
597
+ TableRows.new(self)
598
+ end
599
+
600
+ #
601
+ # @return [Celerity::SelectList]
602
+ #
603
+
604
+ def select_list(*args)
605
+ SelectList.new(self, *args)
606
+ end
607
+
608
+ #
609
+ # @return [Celerity::SelectLists]
610
+ #
611
+
612
+ def select_lists
613
+ SelectLists.new(self)
614
+ end
615
+
616
+ #
617
+ # @return [Celerity::Span]
618
+ #
619
+
620
+ def span(*args)
621
+ Span.new(self, *args)
622
+ end
623
+
624
+ #
625
+ # @return [Celerity::Spans]
626
+ #
627
+
628
+ def spans
629
+ Spans.new(self)
630
+ end
631
+
632
+ #
633
+ # @return [Celerity::Spans]
634
+ #
635
+
636
+ def strong(*args)
637
+ Strong.new(self, *args)
638
+ end
639
+
640
+ #
641
+ # @return [Celerity::Strongs]
642
+ #
643
+
644
+ def strongs
645
+ Strongs.new(self)
646
+ end
647
+
648
+ #
649
+ # @return [Celerity::Table]
650
+ #
651
+
652
+ def table(*args)
653
+ Table.new(self, *args)
654
+ end
655
+
656
+ #
657
+ # @return [Celerity::Tables]
658
+ #
659
+
660
+ def tables
661
+ Tables.new(self)
662
+ end
663
+
664
+ #
665
+ # @return [Celerity::TableBody]
666
+ #
667
+
668
+ def tbody(*args)
669
+ TableBody.new(self, *args)
670
+ end
671
+
672
+ #
673
+ # @return [Celerity::TableBodies]
674
+ #
675
+
676
+ def tbodies
677
+ TableBodies.new(self)
678
+ end
679
+
680
+ #
681
+ # @return [Celerity::TextField]
682
+ #
683
+
684
+ def text_field(*args)
685
+ TextField.new(self, *args)
686
+ end
687
+
688
+ #
689
+ # @return [Celerity::TextFields]
690
+ #
691
+
692
+ def text_fields
693
+ TextFields.new(self)
694
+ end
695
+
696
+ #
697
+ # @return [Celerity::TableFooter]
698
+ #
699
+
700
+ def tfoot(*args)
701
+ TableFooter.new(self, *args)
702
+ end
703
+
704
+ #
705
+ # @return [Celerity::TableFooters]
706
+ #
707
+
708
+ def tfoots
709
+ TableFooters.new(self)
710
+ end
711
+ alias_method :tfeet, :tfoots # :-)
712
+
713
+ #
714
+ # Watir's cells() won't find <th> elements.
715
+ # This is a workaround.
716
+ #
717
+ # @return [Celerity::Th]
718
+ #
719
+
720
+ def th(*args)
721
+ Th.new(self, *args)
722
+ end
723
+
724
+ #
725
+ # FIXME: implement or change api,
726
+ # @see th
727
+ #
728
+
729
+ def ths
730
+ raise NotImplementedError
731
+ end
732
+
733
+ #
734
+ # @return [Celerity::TableHeader]
735
+ #
736
+
737
+ def thead(*args)
738
+ TableHeader.new(self, *args)
739
+ end
740
+
741
+ #
742
+ # @return [Celerity::TableHeaders]
743
+ #
744
+
745
+ def theads
746
+ TableHeaders.new(self)
747
+ end
748
+
749
+ #
750
+ # @return [Celerity::Ul]
751
+ #
752
+
753
+ def ul(*args)
754
+ Ul.new(self, *args)
755
+ end
756
+
757
+ #
758
+ # @return [Celerity::Uls]
759
+ #
760
+
761
+ def uls
762
+ Uls.new(self)
763
+ end
764
+
765
+ end # Container
766
+ end # Celerity