druid-ts 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +27 -0
  3. data/features/async.feature +6 -0
  4. data/features/div.feature +1 -0
  5. data/features/element.feature +4 -0
  6. data/features/hidden_field.feature +0 -2
  7. data/features/html/async.html +13 -0
  8. data/features/html/multi_elements.html +4 -0
  9. data/features/html/static_elements.html +10 -3
  10. data/features/link.feature +1 -0
  11. data/features/multi_elements.feature +135 -25
  12. data/features/select_list.feature +8 -0
  13. data/features/span.feature +2 -0
  14. data/features/step_definations/async_steps.rb +17 -0
  15. data/features/step_definations/element_steps.rb +6 -0
  16. data/features/step_definations/multi_elements_steps.rb +96 -0
  17. data/features/step_definations/select_list_steps.rb +12 -0
  18. data/features/step_definations/table_steps.rb +20 -3
  19. data/features/support/ajax_test_environment.rb +1 -1
  20. data/features/support/page.rb +7 -2
  21. data/features/table.feature +35 -0
  22. data/features/text_area.feature +0 -2
  23. data/features/text_field.feature +1 -2
  24. data/lib/druid.rb +31 -3
  25. data/lib/druid/accessors.rb +184 -146
  26. data/lib/druid/assist.rb +10 -2
  27. data/lib/druid/element_locators.rb +186 -102
  28. data/lib/druid/elements/div.rb +1 -1
  29. data/lib/druid/elements/element.rb +131 -96
  30. data/lib/druid/elements/hidden_field.rb +1 -5
  31. data/lib/druid/elements/link.rb +1 -1
  32. data/lib/druid/elements/select_list.rb +8 -0
  33. data/lib/druid/elements/span.rb +1 -1
  34. data/lib/druid/elements/table.rb +14 -3
  35. data/lib/druid/elements/table_row.rb +17 -2
  36. data/lib/druid/elements/text_area.rb +0 -8
  37. data/lib/druid/elements/text_field.rb +1 -1
  38. data/lib/druid/javascript/yui.rb +19 -0
  39. data/lib/druid/javascript_framework_facade.rb +3 -1
  40. data/lib/druid/nested_elements.rb +1 -1
  41. data/lib/druid/page_factory.rb +25 -0
  42. data/lib/druid/page_populator.rb +1 -0
  43. data/lib/druid/version.rb +1 -1
  44. data/spec/druid/accessors_spec.rb +189 -1
  45. data/spec/druid/druid_spec.rb +6 -0
  46. data/spec/druid/element_locators_spec.rb +276 -0
  47. data/spec/druid/elements/div_spec.rb +1 -1
  48. data/spec/druid/elements/element_spec.rb +11 -0
  49. data/spec/druid/elements/hidden_field_spec.rb +0 -5
  50. data/spec/druid/elements/link_spec.rb +1 -1
  51. data/spec/druid/elements/span_spec.rb +1 -1
  52. data/spec/druid/elements/text_area_spec.rb +0 -5
  53. data/spec/druid/elements/text_field_spec.rb +1 -1
  54. data/spec/druid/page_factory_spec.rb +20 -0
  55. data/spec/druid/page_populator_spec.rb +8 -4
  56. metadata +2 -1
@@ -1,5 +1,6 @@
1
1
  require 'druid/javascript/jquery'
2
2
  require 'druid/javascript/prototype'
3
+ require 'druid/javascript/yui'
3
4
 
4
5
  module Druid
5
6
  #
@@ -56,7 +57,8 @@ module Druid
56
57
  def initialize_script_builder
57
58
  @builder = {
58
59
  :jquery => Druid::Javascript::JQuery,
59
- :prototype => Druid::Javascript::Prototype
60
+ :prototype => Druid::Javascript::Prototype,
61
+ :yui => Druid::Javascript::YUI
60
62
  }
61
63
  end
62
64
 
@@ -53,7 +53,7 @@ module Druid
53
53
  end
54
54
 
55
55
  def checkbox_elements(identifier={:index => 0})
56
- checkboxs_for(identifier)
56
+ checkboxes_for(identifier)
57
57
  end
58
58
 
59
59
  def radio_button_element(identifier={:index => 0})
@@ -61,6 +61,31 @@ module Druid
61
61
  # Support 'on' for readability of usage
62
62
  alias_method :on, :on_page
63
63
 
64
+ #
65
+ # Create a page object if and only if the current page is the same page to be created
66
+ #
67
+ # @example
68
+ # original:
69
+ # on_page(NewProduct).save if @current_page.class == NewProduct
70
+ # on_page(EditProduct).save if @current_page.class == EditProduct
71
+ # new:
72
+ # if_page NewProduct do |page|
73
+ # page.save
74
+ # end
75
+ # if_page EditProduct do |page|
76
+ # page.update
77
+ # end
78
+ # @param [PageObject] a class that has included the Druid module
79
+ # @param [block] an optional block to be called
80
+ # @return [PageObject] the newly created page object
81
+ def if_page(page_class, &block)
82
+ return @current_page unless @current_page.class == page_class
83
+ on_page(page_class, false, &block)
84
+ end
85
+
86
+ # support 'if' for readability of usage
87
+ alias_method :if, :if_page
88
+
64
89
  #
65
90
  # Navigate to a specific page following a predefined path.
66
91
  #
@@ -65,6 +65,7 @@ module Druid
65
65
  end
66
66
 
67
67
  def is_enabled?(key)
68
+ return true if (self.send "#{key}_element").tag_name == "textarea"
68
69
  self.send("#{key}_element").enabled?
69
70
  end
70
71
  end
data/lib/druid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Druid
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.4"
3
3
  end
@@ -158,6 +158,15 @@ describe Druid::Accessors do
158
158
  expect(druid).to have_expected_title
159
159
  end
160
160
 
161
+ it "should validate the by regexp" do
162
+ class RegexpExpectedTitle
163
+ include Druid
164
+ expected_title /\w+ \w+/
165
+ end
166
+ expect(driver).to receive(:title).and_return("Expected Title")
167
+ expect(RegexpExpectedTitle.new(driver)).to have_expected_title
168
+ end
169
+
161
170
  it "should raise error when it does not have expected title" do
162
171
  expect(driver).to receive(:title).twice.and_return("Not Expected")
163
172
  expect {druid.has_expected_title? }.to raise_error
@@ -180,6 +189,184 @@ describe Druid::Accessors do
180
189
  end
181
190
  end
182
191
 
192
+ describe "using default identifiers" do
193
+ class DefaultIdentifier
194
+ include Druid
195
+ text_field(:default_tf)
196
+ hidden_field(:default_hf)
197
+ text_area(:default_ta)
198
+ select_list(:default_sl)
199
+ link(:default_link)
200
+ checkbox(:default_cb)
201
+ radio_button(:default_rb)
202
+ button(:default_but)
203
+ div(:default_div)
204
+ span(:default_span)
205
+ table(:default_tab)
206
+ cell(:default_cell)
207
+ image(:default_im)
208
+ form(:default_form)
209
+ list_item(:default_li)
210
+ unordered_list(:default_ul)
211
+ ordered_list(:default_ol)
212
+ h1(:default_h1)
213
+ h2(:default_h2)
214
+ h3(:default_h3)
215
+ h4(:default_h4)
216
+ h5(:default_h5)
217
+ h6(:default_h6)
218
+ paragraph(:default_p)
219
+ file_field(:default_ff)
220
+ label(:default_lab)
221
+ element(:default_el, :audio)
222
+ end
223
+
224
+ let(:default_identifier) { DefaultIdentifier.new(driver) }
225
+
226
+ before(:each) do
227
+ expect(driver).to receive(:exist?).and_return(true)
228
+ end
229
+
230
+ def mock_driver_for(tag)
231
+ expect(driver).to receive(tag).with(:index => 0).and_return(driver)
232
+ end
233
+
234
+ it "should work with a text_field" do
235
+ mock_driver_for :text_field
236
+ default_identifier.default_tf?
237
+ end
238
+
239
+ it "should work with a hidden field" do
240
+ mock_driver_for :hidden
241
+ default_identifier.default_hf?
242
+ end
243
+
244
+ it "should work with a text area" do
245
+ mock_driver_for :textarea
246
+ default_identifier.default_ta?
247
+ end
248
+
249
+ it "should work with a select list" do
250
+ mock_driver_for :select_list
251
+ default_identifier.default_sl?
252
+ end
253
+
254
+ it "should work with a link" do
255
+ mock_driver_for :link
256
+ default_identifier.default_link?
257
+ end
258
+
259
+ it "should work with a checkbox" do
260
+ mock_driver_for :checkbox
261
+ default_identifier.default_cb?
262
+ end
263
+
264
+ it "should work with a radio button" do
265
+ mock_driver_for :radio
266
+ default_identifier.default_rb?
267
+ end
268
+
269
+ it "should work with a button" do
270
+ mock_driver_for :button
271
+ default_identifier.default_but?
272
+ end
273
+
274
+ it "should work with a div" do
275
+ mock_driver_for :div
276
+ default_identifier.default_div?
277
+ end
278
+
279
+ it "should work with a span" do
280
+ mock_driver_for :span
281
+ default_identifier.default_span?
282
+ end
283
+
284
+ it "should work with a table" do
285
+ mock_driver_for :table
286
+ default_identifier.default_tab?
287
+ end
288
+
289
+ it "should work with a cell" do
290
+ mock_driver_for :td
291
+ default_identifier.default_cell?
292
+ end
293
+
294
+ it "should work with an image" do
295
+ mock_driver_for :image
296
+ default_identifier.default_im?
297
+ end
298
+
299
+ it "should work with a form" do
300
+ mock_driver_for :form
301
+ default_identifier.default_form?
302
+ end
303
+
304
+ it "should work with a list item" do
305
+ mock_driver_for :li
306
+ default_identifier.default_li?
307
+ end
308
+
309
+ it "should work with unordered lists" do
310
+ mock_driver_for :ul
311
+ default_identifier.default_ul?
312
+ end
313
+
314
+ it "should work with ordered lists" do
315
+ mock_driver_for :ol
316
+ default_identifier.default_ol?
317
+ end
318
+
319
+ it "should work with h1" do
320
+ mock_driver_for :h1
321
+ default_identifier.default_h1?
322
+ end
323
+
324
+ it "should work with h2" do
325
+ mock_driver_for :h2
326
+ default_identifier.default_h2?
327
+ end
328
+
329
+ it "should work with h3" do
330
+ mock_driver_for :h3
331
+ default_identifier.default_h3?
332
+ end
333
+
334
+ it "should work with h4" do
335
+ mock_driver_for :h4
336
+ default_identifier.default_h4?
337
+ end
338
+
339
+ it "should work with h5" do
340
+ mock_driver_for :h5
341
+ default_identifier.default_h5?
342
+ end
343
+
344
+ it "should work with h6" do
345
+ mock_driver_for :h6
346
+ default_identifier.default_h6?
347
+ end
348
+
349
+ it "should work with paragraph" do
350
+ mock_driver_for :p
351
+ default_identifier.default_p?
352
+ end
353
+
354
+ it "should work with file_field" do
355
+ mock_driver_for :file_field
356
+ default_identifier.default_ff?
357
+ end
358
+
359
+ it "should work with a label" do
360
+ mock_driver_for :label
361
+ default_identifier.default_lab?
362
+ end
363
+
364
+ it "should work with an element" do
365
+ mock_driver_for :audio
366
+ default_identifier.default_el?
367
+ end
368
+ end
369
+
183
370
  describe "check_box accessors" do
184
371
  context "when called on a page object" do
185
372
  it "should generate accessor methods" do
@@ -285,6 +472,7 @@ describe Druid::Accessors do
285
472
  expect(druid).to respond_to(:first_name)
286
473
  expect(druid).to respond_to(:first_name=)
287
474
  expect(druid).to respond_to(:first_name_element)
475
+ expect(druid).to respond_to(:first_name?)
288
476
  end
289
477
 
290
478
  it "should call a block on the element method when present" do
@@ -544,7 +732,7 @@ describe Druid::Accessors do
544
732
 
545
733
  context "implementation" do
546
734
  it "should set some text on the text area" do
547
- expect(driver).to receive_message_chain(:textarea, :send_keys).with('123 main street')
735
+ expect(driver).to receive_message_chain(:textarea, :set).with('123 main street')
548
736
  druid.address='123 main street'
549
737
  end
550
738
 
@@ -154,6 +154,12 @@ describe Druid do
154
154
  druid.save_screenshot('tim.png')
155
155
  end
156
156
 
157
+ it "should use the overriden timeout value when set" do
158
+ Druid.default_page_wait = 10
159
+ expect(driver).to receive(:wait_until).with(10, nil)
160
+ druid.wait_until
161
+ end
162
+
157
163
  it "should wait until there are no pending ajax requests" do
158
164
  expect(Druid::JavascriptFrameworkFacade).to receive(:pending_requests).and_return('pending requests')
159
165
  expect(driver).to receive(:execute_script).with('pending requests').and_return(0)
@@ -14,96 +14,177 @@ describe Druid::ElementLocators do
14
14
  expect(button).to be_instance_of Druid::Elements::Button
15
15
  end
16
16
 
17
+ it "should find a button element using a default identifier" do
18
+ expect(driver).to receive(:button).with(:index => 0).and_return(driver)
19
+ page.button_element
20
+ end
21
+
17
22
  it "should find all button elements" do
18
23
  expect(driver).to receive(:buttons).with(:id => 'blah').and_return([driver])
19
24
  elements = page.button_elements(:id => 'blah')
20
25
  expect(elements[0]).to be_instance_of Druid::Elements::Button
21
26
  end
22
27
 
28
+ it "should find all buttons with no identifier" do
29
+ expect(driver).to receive(:buttons).with({}).and_return([driver])
30
+ page.button_elements
31
+ end
32
+
23
33
  it "should find a text field element" do
24
34
  expect(driver).to receive(:text_field).with(:id => 'blah').and_return(driver)
25
35
  text_field = page.text_field_element(:id => 'blah')
26
36
  expect(text_field).to be_instance_of Druid::Elements::TextField
27
37
  end
28
38
 
39
+ it "should find a text field element using a default identifier" do
40
+ expect(driver).to receive(:text_field).with(:index => 0).and_return(driver)
41
+ page.text_field_element
42
+ end
43
+
29
44
  it "should find all text field elemnts" do
30
45
  expect(driver).to receive(:text_fields).with(:id => 'blah').and_return([driver])
46
+ expect(driver).to receive(:tag_name).and_return('input')
31
47
  elements = page.text_field_elements(:id => 'blah')
32
48
  expect(elements[0]).to be_instance_of Druid::Elements::TextField
33
49
  end
34
50
 
51
+ it "should find all text fields with no identifier" do
52
+ expect(driver).to receive(:text_fields).with({}).and_return([driver])
53
+ expect(driver).to receive(:tag_name).and_return('input')
54
+ page.text_field_elements
55
+ end
56
+
35
57
  it "should find a hidden field element" do
36
58
  expect(driver).to receive(:hidden).with(:id => 'blah').and_return(driver)
37
59
  element = page.hidden_field_element(:id => 'blah')
38
60
  expect(element).to be_instance_of Druid::Elements::HiddenField
39
61
  end
40
62
 
63
+ it "should find a hidden field element using a default identifier" do
64
+ expect(driver).to receive(:hidden).with(:index => 0).and_return(driver)
65
+ page.hidden_field_element
66
+ end
67
+
41
68
  it "should find all hidden field elements" do
42
69
  expect(driver).to receive(:hiddens).with(:id => 'blah').and_return([driver])
43
70
  elements = page.hidden_field_elements(:id => 'blah')
44
71
  expect(elements[0]).to be_instance_of Druid::Elements::HiddenField
45
72
  end
46
73
 
74
+ it "should find all hidden fields using no identifier" do
75
+ expect(driver).to receive(:hiddens).with({}).and_return([driver])
76
+ page.hidden_field_elements
77
+ end
78
+
47
79
  it "should find a text area element" do
48
80
  expect(driver).to receive(:textarea).with(:id => 'blah').and_return(driver)
49
81
  element = page.text_area_element(:id => "blah")
50
82
  expect(element).to be_instance_of Druid::Elements::TextArea
51
83
  end
52
84
 
85
+ it "should find a text area element using a default identifier" do
86
+ expect(driver).to receive(:textarea).with(:index => 0).and_return(driver)
87
+ page.text_area_element
88
+ end
89
+
53
90
  it "should find all text area elements" do
54
91
  expect(driver).to receive(:textareas).with(:id => 'blah').and_return([driver])
55
92
  elements = page.text_area_elements(:id => 'blah')
56
93
  expect(elements[0]).to be_instance_of Druid::Elements::TextArea
57
94
  end
58
95
 
96
+ it "should find all text areas using no identifier" do
97
+ expect(driver).to receive(:textareas).with({}).and_return([driver])
98
+ page.text_area_elements
99
+ end
100
+
59
101
  it "should find a select list element" do
60
102
  expect(driver).to receive(:select_list).with(:id => 'blah').and_return(driver)
61
103
  element = page.select_list_element(:id => "blah")
62
104
  expect(element).to be_instance_of Druid::Elements::SelectList
63
105
  end
64
106
 
107
+ it "should find a select list element using a default identifier" do
108
+ expect(driver).to receive(:select_list).with(:index => 0).and_return(driver)
109
+ page.select_list_element
110
+ end
111
+
65
112
  it "should find all select list elements" do
66
113
  expect(driver).to receive(:select_lists).with(:id => 'blah').and_return([driver])
67
114
  elements = page.select_list_elements(:id => 'blah')
68
115
  expect(elements[0]).to be_instance_of Druid::Elements::SelectList
69
116
  end
70
117
 
118
+ it "should find all select lists using no identifier" do
119
+ expect(driver).to receive(:select_lists).with({}).and_return([driver])
120
+ page.select_list_elements
121
+ end
122
+
71
123
  it "should find a link element" do
72
124
  expect(driver).to receive(:link).with(:id => 'blah').and_return(driver)
73
125
  element = page.link_element(:id => 'blah')
74
126
  expect(element).to be_instance_of Druid::Elements::Link
75
127
  end
76
128
 
129
+ it "should find a link element using a default identifier" do
130
+ expect(driver).to receive(:link).with(:index => 0).and_return(driver)
131
+ page.link_element
132
+ end
133
+
77
134
  it "should find all link elements" do
78
135
  expect(driver).to receive(:links).with(:id => 'blah').and_return([driver])
79
136
  elements = page.link_elements(:id => 'blah')
80
137
  expect(elements[0]).to be_instance_of Druid::Elements::Link
81
138
  end
82
139
 
140
+ it "should find all links using no identifier" do
141
+ expect(driver).to receive(:links).with({}).and_return([driver])
142
+ page.link_elements
143
+ end
144
+
83
145
  it "should find a check box element" do
84
146
  expect(driver).to receive(:checkbox).with(:id => 'blah').and_return(driver)
85
147
  element = page.checkbox_element(:id => 'blah')
86
148
  expect(element).to be_instance_of Druid::Elements::CheckBox
87
149
  end
88
150
 
151
+ it "should find a check box element using a default identifier" do
152
+ expect(driver).to receive(:checkbox).with(:index => 0).and_return(driver)
153
+ page.checkbox_element
154
+ end
155
+
89
156
  it "should find all check box elements" do
90
157
  expect(driver).to receive(:checkboxes).with(:id => 'blah').and_return([driver])
91
158
  elements = page.checkbox_elements(:id => 'blah')
92
159
  expect(elements[0]).to be_instance_of Druid::Elements::CheckBox
93
160
  end
94
161
 
162
+ it "should find all checkboxes using no identifier" do
163
+ expect(driver).to receive(:checkboxes).with({}).and_return([driver])
164
+ page.checkbox_elements
165
+ end
166
+
95
167
  it "should find a radio button element" do
96
168
  expect(driver).to receive(:radio).with(:id => 'blah').and_return(driver)
97
169
  element = page.radio_button_element(:id => 'blah')
98
170
  expect(element).to be_instance_of Druid::Elements::RadioButton
99
171
  end
100
172
 
173
+ it "should find a radio button element using a default identifier" do
174
+ expect(driver).to receive(:radio).with(:index => 0).and_return(driver)
175
+ page.radio_button_element
176
+ end
177
+
101
178
  it "should find all radio button elements" do
102
179
  expect(driver).to receive(:radios).with(:id => 'blah').and_return([driver])
103
180
  elements = page.radio_button_elements(:id => 'blah')
104
181
  expect(elements[0]).to be_instance_of Druid::Elements::RadioButton
105
182
  end
106
183
 
184
+ it "should find all radio buttons using no identifier" do
185
+ expect(driver).to receive(:radios).with({}).and_return([driver])
186
+ page.radio_button_elements
187
+ end
107
188
 
108
189
  it "should find a div element" do
109
190
  expect(driver).to receive(:div).with(:id => 'blah').and_return(driver)
@@ -111,96 +192,175 @@ describe Druid::ElementLocators do
111
192
  expect(element).to be_instance_of Druid::Elements::Div
112
193
  end
113
194
 
195
+ it "should find a div element using a default identifier" do
196
+ expect(driver).to receive(:div).with(:index => 0).and_return(driver)
197
+ page.div_element
198
+ end
199
+
114
200
  it "should find all div elements" do
115
201
  expect(driver).to receive(:divs).with(:id => 'blah').and_return([driver])
116
202
  elements = page.div_elements(:id => 'blah')
117
203
  expect(elements[0]).to be_instance_of Druid::Elements::Div
118
204
  end
119
205
 
206
+ it "should find all divs using no identifier" do
207
+ expect(driver).to receive(:divs).with({}).and_return([driver])
208
+ page.div_elements
209
+ end
210
+
120
211
  it "should find a span element" do
121
212
  expect(driver).to receive(:span).with(:id => 'blah').and_return(driver)
122
213
  element = page.span_element(:id => 'blah')
123
214
  expect(element).to be_instance_of Druid::Elements::Span
124
215
  end
125
216
 
217
+ it "should find a span element using a default identifier" do
218
+ expect(driver).to receive(:span).with(:index => 0).and_return(driver)
219
+ page.span_element
220
+ end
221
+
126
222
  it "should find all span elements" do
127
223
  expect(driver).to receive(:spans).with(:id => 'blah').and_return([driver])
128
224
  elements = page.span_elements(:id => 'blah')
129
225
  expect(elements[0]).to be_instance_of Druid::Elements::Span
130
226
  end
131
227
 
228
+ it "should find all spans using no identifier" do
229
+ expect(driver).to receive(:spans).with({}).and_return([driver])
230
+ page.span_elements
231
+ end
232
+
132
233
  it "should find a table element" do
133
234
  expect(driver).to receive(:table).with(:id => 'blah').and_return(driver)
134
235
  element = page.table_element(:id => 'blah')
135
236
  expect(element).to be_instance_of Druid::Elements::Table
136
237
  end
137
238
 
239
+ it "should find a table element using a default identifier" do
240
+ expect(driver).to receive(:table).with(:index => 0).and_return(driver)
241
+ page.table_element
242
+ end
243
+
138
244
  it "should find all table elements" do
139
245
  expect(driver).to receive(:tables).with(:id => 'blah').and_return([driver])
140
246
  elements = page.table_elements(:id => 'blah')
141
247
  expect(elements[0]).to be_instance_of Druid::Elements::Table
142
248
  end
143
249
 
250
+ it "should find all tables using no identifier" do
251
+ expect(driver).to receive(:tables).with({}).and_return([driver])
252
+ page.table_elements
253
+ end
254
+
144
255
  it "should find a table cell element" do
145
256
  expect(driver).to receive(:td).with(:id => 'blah').and_return(driver)
146
257
  element = page.cell_element(:id => 'blah')
147
258
  expect(element).to be_instance_of Druid::Elements::TableCell
148
259
  end
149
260
 
261
+ it "should find a table cell element using a default identifier" do
262
+ expect(driver).to receive(:td).with(:index => 0).and_return(driver)
263
+ page.cell_element
264
+ end
265
+
150
266
  it "should find all table cells" do
151
267
  expect(driver).to receive(:tds).with(:id => 'blah').and_return([driver])
152
268
  elements = page.cell_elements(:id => 'blah')
153
269
  expect(elements[0]).to be_instance_of Druid::Elements::TableCell
154
270
  end
155
271
 
272
+ it "should find all table cells using no identifier" do
273
+ expect(driver).to receive(:tds).with({}).and_return([driver])
274
+ page.cell_elements
275
+ end
276
+
156
277
  it "should find an image element" do
157
278
  expect(driver).to receive(:image).with(:id => 'blah').and_return(driver)
158
279
  element = page.image_element(:id => 'blah')
159
280
  expect(element).to be_instance_of Druid::Elements::Image
160
281
  end
161
282
 
283
+ it "should find a image element using a default identifier" do
284
+ expect(driver).to receive(:image).with(:index => 0).and_return(driver)
285
+ page.image_element
286
+ end
287
+
162
288
  it "should find all image elements" do
163
289
  expect(driver).to receive(:images).with(:id => 'blah').and_return([driver])
164
290
  elements = page.image_elements(:id => 'blah')
165
291
  expect(elements[0]).to be_instance_of Druid::Elements::Image
166
292
  end
167
293
 
294
+ it "should find all images using no identifier" do
295
+ expect(driver).to receive(:images).with({}).and_return([driver])
296
+ page.image_elements
297
+ end
298
+
168
299
  it "should find a form element" do
169
300
  expect(driver).to receive(:form).with(:id => 'blah').and_return(driver)
170
301
  element = page.form_element(:id => 'blah')
171
302
  expect(element).to be_instance_of Druid::Elements::Form
172
303
  end
173
304
 
305
+ it "should find a form element using a default identifier" do
306
+ expect(driver).to receive(:form).with(:index => 0).and_return(driver)
307
+ page.form_element
308
+ end
309
+
174
310
  it "should find all form elements" do
175
311
  expect(driver).to receive(:forms).with(:id => 'blah').and_return([driver])
176
312
  elements = page.form_elements(:id => 'blah')
177
313
  expect(elements[0]).to be_instance_of Druid::Elements::Form
178
314
  end
179
315
 
316
+ it "should find all forms using no identifier" do
317
+ expect(driver).to receive(:forms).with({}).and_return([driver])
318
+ page.form_elements
319
+ end
320
+
180
321
  it "should find a list item element" do
181
322
  expect(driver).to receive(:li).with(:id => 'blah').and_return(driver)
182
323
  element = page.list_item_element(:id => 'blah')
183
324
  expect(element).to be_instance_of Druid::Elements::ListItem
184
325
  end
185
326
 
327
+ it "should find a list item element using a default identifier" do
328
+ expect(driver).to receive(:li).with(:index => 0).and_return(driver)
329
+ page.list_item_element
330
+ end
331
+
186
332
  it "should find all list item elements" do
187
333
  expect(driver).to receive(:lis).with(:id => 'blah').and_return([driver])
188
334
  elements = page.list_item_elements(:id => 'blah')
189
335
  expect(elements[0]).to be_instance_of Druid::Elements::ListItem
190
336
  end
191
337
 
338
+ it "should find all list items using no identifier" do
339
+ expect(driver).to receive(:lis).with({}).and_return([driver])
340
+ page.list_item_elements
341
+ end
342
+
192
343
  it "should find an ordered list element" do
193
344
  expect(driver).to receive(:ol).with(:id => 'blah').and_return(driver)
194
345
  element = page.ordered_list_element(:id => 'blah')
195
346
  expect(element).to be_instance_of Druid::Elements::OrderedList
196
347
  end
197
348
 
349
+ it "should find an ordered list element using a default identifier" do
350
+ expect(driver).to receive(:ol).with(:index => 0).and_return(driver)
351
+ page.ordered_list_element
352
+ end
353
+
198
354
  it "should find all ordered list elements" do
199
355
  expect(driver).to receive(:ols).with(:id => 'blah').and_return([driver])
200
356
  elements = page.ordered_list_elements(:id => 'blah')
201
357
  expect(elements[0]).to be_instance_of Druid::Elements::OrderedList
202
358
  end
203
359
 
360
+ it "should find all ordered lists using no identifier" do
361
+ expect(driver).to receive(:ols).with({}).and_return([driver])
362
+ page.ordered_list_elements
363
+ end
204
364
 
205
365
  it "should find an unordered list element" do
206
366
  expect(driver).to receive(:ul).with(:id => 'blah').and_return(driver)
@@ -208,12 +368,21 @@ describe Druid::ElementLocators do
208
368
  expect(element).to be_instance_of Druid::Elements::UnOrderedList
209
369
  end
210
370
 
371
+ it "should find an unordered list element using a default identifier" do
372
+ expect(driver).to receive(:ul).with(:index => 0).and_return(driver)
373
+ page.unordered_list_element
374
+ end
375
+
211
376
  it "should find all unordered list elements" do
212
377
  expect(driver).to receive(:uls).with(:id => 'blah').and_return([driver])
213
378
  elements = page.unordered_list_elements(:id => 'blah')
214
379
  expect(elements[0]).to be_instance_of Druid::Elements::UnOrderedList
215
380
  end
216
381
 
382
+ it "should find all unordered lists using no identifier" do
383
+ expect(driver).to receive(:uls).with({}).and_return([driver])
384
+ page.unordered_list_elements
385
+ end
217
386
 
218
387
  it "should find a h1 element" do
219
388
  expect(driver).to receive(:h1).with(:id => 'blah').and_return(driver)
@@ -221,72 +390,132 @@ describe Druid::ElementLocators do
221
390
  expect(element).to be_instance_of Druid::Elements::Heading
222
391
  end
223
392
 
393
+ it "should find a h1 element using a default identifier" do
394
+ expect(driver).to receive(:h1).with(:index => 0).and_return(driver)
395
+ page.h1_element
396
+ end
397
+
224
398
  it "should find all h1 elements" do
225
399
  expect(driver).to receive(:h1s).with(:id => 'blah').and_return([driver])
226
400
  elements = page.h1_elements(:id => 'blah')
227
401
  expect(elements[0]).to be_instance_of Druid::Elements::Heading
228
402
  end
229
403
 
404
+ it "should find all h1s using no identifier" do
405
+ expect(driver).to receive(:h1s).with({}).and_return([driver])
406
+ page.h1_elements
407
+ end
408
+
230
409
  it "should find a h2 element" do
231
410
  expect(driver).to receive(:h2).with(:id => 'blah').and_return(driver)
232
411
  element = page.h2_element(:id => 'blah')
233
412
  expect(element).to be_instance_of Druid::Elements::Heading
234
413
  end
235
414
 
415
+ it "should find a h2 element using a default identifier" do
416
+ expect(driver).to receive(:h2).with(:index => 0).and_return(driver)
417
+ page.h2_element
418
+ end
419
+
236
420
  it "should find all h2 elements" do
237
421
  expect(driver).to receive(:h2s).with(:id => 'blah').and_return([driver])
238
422
  elements = page.h2_elements(:id => 'blah')
239
423
  expect(elements[0]).to be_instance_of Druid::Elements::Heading
240
424
  end
241
425
 
426
+ it "should find all h2s using no identifier" do
427
+ expect(driver).to receive(:h2s).with({}).and_return([driver])
428
+ page.h2_elements
429
+ end
430
+
242
431
  it "should find a h3 element" do
243
432
  expect(driver).to receive(:h3).with(:id => 'blah').and_return(driver)
244
433
  element = page.h3_element(:id => 'blah')
245
434
  expect(element).to be_instance_of Druid::Elements::Heading
246
435
  end
247
436
 
437
+ it "should find a h3 element using a default identifier" do
438
+ expect(driver).to receive(:h3).with(:index => 0).and_return(driver)
439
+ page.h3_element
440
+ end
441
+
248
442
  it "should find all h3 elements" do
249
443
  expect(driver).to receive(:h3s).with(:id => 'blah').and_return([driver])
250
444
  elements = page.h3_elements(:id => 'blah')
251
445
  expect(elements[0]).to be_instance_of Druid::Elements::Heading
252
446
  end
253
447
 
448
+ it "should find all h3s using no identifier" do
449
+ expect(driver).to receive(:h3s).with({}).and_return([driver])
450
+ page.h3_elements
451
+ end
452
+
254
453
  it "should find a h4 element" do
255
454
  expect(driver).to receive(:h4).with(:id => 'blah').and_return(driver)
256
455
  element = page.h4_element(:id => 'blah')
257
456
  expect(element).to be_instance_of Druid::Elements::Heading
258
457
  end
259
458
 
459
+ it "should find a h4 element using a default identifier" do
460
+ expect(driver).to receive(:h4).with(:index => 0).and_return(driver)
461
+ page.h4_element
462
+ end
463
+
260
464
  it "should find all h4 elements" do
261
465
  expect(driver).to receive(:h4s).with(:id => 'blah').and_return([driver])
262
466
  elements = page.h4_elements(:id => 'blah')
263
467
  expect(elements[0]).to be_instance_of Druid::Elements::Heading
264
468
  end
265
469
 
470
+ it "should find all h4s using no identifier" do
471
+ expect(driver).to receive(:h4s).with({}).and_return([driver])
472
+ page.h4_elements
473
+ end
474
+
266
475
  it "should find a h5 element" do
267
476
  expect(driver).to receive(:h5).with(:id => 'blah').and_return(driver)
268
477
  element = page.h5_element(:id => 'blah')
269
478
  expect(element).to be_instance_of Druid::Elements::Heading
270
479
  end
271
480
 
481
+ it "should find a h5 element using a default identifier" do
482
+ expect(driver).to receive(:h5).with(:index => 0).and_return(driver)
483
+ page.h5_element
484
+ end
485
+
272
486
  it "should find all h5 elements" do
273
487
  expect(driver).to receive(:h5s).with(:id => 'blah').and_return([driver])
274
488
  elements = page.h5_elements(:id => 'blah')
275
489
  expect(elements[0]).to be_instance_of Druid::Elements::Heading
276
490
  end
277
491
 
492
+ it "should find all h5s using no identifier" do
493
+ expect(driver).to receive(:h5s).with({}).and_return([driver])
494
+ page.h5_elements
495
+ end
496
+
278
497
  it "should find a h6 element" do
279
498
  expect(driver).to receive(:h6).with(:id => 'blah').and_return(driver)
280
499
  element = page.h6_element(:id => 'blah')
281
500
  expect(element).to be_instance_of Druid::Elements::Heading
282
501
  end
283
502
 
503
+ it "should find a h6 element using a default identifier" do
504
+ expect(driver).to receive(:h6).with(:index => 0).and_return(driver)
505
+ page.h6_element
506
+ end
507
+
284
508
  it "should find all h6 elements" do
285
509
  expect(driver).to receive(:h6s).with(:id => 'blah').and_return([driver])
286
510
  elements = page.h6_elements(:id => 'blah')
287
511
  expect(elements[0]).to be_instance_of Druid::Elements::Heading
288
512
  end
289
513
 
514
+ it "should find all h6s using no identifier" do
515
+ expect(driver).to receive(:h6s).with({}).and_return([driver])
516
+ page.h6_elements
517
+ end
518
+
290
519
  it "should find a paragraph element" do
291
520
  expect(driver).to receive(:p).with(:id => 'blah').and_return(driver)
292
521
  element = page.paragraph_element(:id => 'blah')
@@ -299,21 +528,68 @@ describe Druid::ElementLocators do
299
528
  expect(elements[0]).to be_instance_of Druid::Elements::Paragraph
300
529
  end
301
530
 
531
+ it "should find a paragraph element using a default identifier" do
532
+ expect(driver).to receive(:p).with(:index => 0).and_return(driver)
533
+ page.paragraph_element
534
+ end
535
+
536
+ it "should find all paragraphs using no identifier" do
537
+ expect(driver).to receive(:ps).with({}).and_return([driver])
538
+ page.paragraph_elements
539
+ end
540
+
302
541
  it "should find a file field element" do
303
542
  expect(driver).to receive(:file_field).with(:id => 'blah').and_return(driver)
304
543
  element = page.file_field_element(:id => 'blah')
305
544
  expect(element).to be_instance_of Druid::Elements::FileField
306
545
  end
307
546
 
547
+ it "should find a file field element using a default identifier" do
548
+ expect(driver).to receive(:file_field).with(:index => 0).and_return(driver)
549
+ page.file_field_element
550
+ end
551
+
552
+ it "should find all file field elements" do
553
+ expect(driver).to receive(:file_fields).with(:id => 'blah').and_return([driver])
554
+ element = page.file_field_elements(:id => 'blah')
555
+ expect(element[0]).to be_instance_of Druid::Elements::FileField
556
+ end
557
+
558
+ it "should find all file fields using no identifier" do
559
+ expect(driver).to receive(:file_fields).with({}).and_return([driver])
560
+ page.file_field_elements
561
+ end
562
+
308
563
  it "should find a label" do
309
564
  expect(driver).to receive(:label).with(:id => 'blah').and_return(driver)
310
565
  element = page.label_element(:id => 'blah')
311
566
  expect(element).to be_instance_of Druid::Elements::Label
312
567
  end
313
568
 
569
+ it "should find a label element using a default identifier" do
570
+ expect(driver).to receive(:label).with(:index => 0).and_return(driver)
571
+ page.label_element
572
+ end
573
+
314
574
  it "should find all label elements" do
315
575
  expect(driver).to receive(:labels).with(:id => 'blah').and_return([driver])
316
576
  elements = page.label_elements(:id => 'blah')
317
577
  expect(elements[0]).to be_instance_of Druid::Elements::Label
318
578
  end
579
+
580
+ it "should find all labels using no identifier" do
581
+ expect(driver).to receive(:labels).with({}).and_return([driver])
582
+ page.label_elements
583
+ end
584
+
585
+ it "should find an element" do
586
+ expect(driver).to receive(:audio).with(:id => 'blah').and_return(driver)
587
+ element = page.element(:audio, :id => 'blah')
588
+ expect(element).to be_instance_of Druid::Elements::Element
589
+ end
590
+
591
+ it "should find an element using a default identifier" do
592
+ expect(driver).to receive(:audio).with(:index => 0).and_return(driver)
593
+ page.element(:audio)
594
+ end
319
595
  end