page-object 0.6.7 → 0.6.8
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.
- data/.travis.yml +0 -1
- data/ChangeLog +11 -1
- data/features/html/static_elements.html +9 -4
- data/features/select_list.feature +3 -0
- data/features/step_definitions/select_list_steps.rb +8 -0
- data/features/step_definitions/table_steps.rb +8 -0
- data/features/support/page.rb +5 -4
- data/features/table.feature +8 -0
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +3 -1
- data/lib/page-object/platforms/selenium_webdriver/select_list.rb +8 -1
- data/lib/page-object/platforms/selenium_webdriver/table.rb +1 -0
- data/lib/page-object/platforms/selenium_webdriver/table_row.rb +1 -0
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +1 -1
- data/lib/page-object/platforms/watir_webdriver/table.rb +1 -0
- data/lib/page-object/platforms/watir_webdriver/table_row.rb +1 -0
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +2 -2
- data/spec/page-object/elements/select_list_spec.rb +12 -3
- data/spec/page-object/selenium_accessors_spec.rb +505 -0
- data/spec/page-object/watir_accessors_spec.rb +1020 -0
- metadata +20 -18
- data/spec/page-object/accessors_spec.rb +0 -1455
@@ -0,0 +1,1020 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class WatirAccessorsTestPageObject
|
4
|
+
include PageObject
|
5
|
+
|
6
|
+
page_url "http://apple.com"
|
7
|
+
expected_title "Expected Title"
|
8
|
+
expected_element :google_search
|
9
|
+
link(:google_search, :link => 'Google Search')
|
10
|
+
text_field(:first_name, :id => 'first_name')
|
11
|
+
hidden_field(:social_security_number, :id => 'ssn')
|
12
|
+
text_area(:address, :id => 'address')
|
13
|
+
select_list(:state, :id => 'state')
|
14
|
+
checkbox(:active, :id => 'is_active_id')
|
15
|
+
radio_button(:first, :id => 'first_choice')
|
16
|
+
button(:click_me, :id => 'button_submit')
|
17
|
+
div(:message, :id => 'message_id')
|
18
|
+
table(:cart, :id => 'cart_id')
|
19
|
+
cell(:total, :id => 'total')
|
20
|
+
span(:alert, :id => 'alert_id')
|
21
|
+
image(:logo, :id => 'logo')
|
22
|
+
form(:login, :id => 'login')
|
23
|
+
list_item(:item_one, :id => 'one')
|
24
|
+
unordered_list(:menu, :id => 'main_menu')
|
25
|
+
ordered_list(:top_five, :id => 'top')
|
26
|
+
h1(:heading1, :id => 'main_heading')
|
27
|
+
h2(:heading2, :id => 'main_heading')
|
28
|
+
h3(:heading3, :id => 'main_heading')
|
29
|
+
h4(:heading4, :id => 'main_heading')
|
30
|
+
h5(:heading5, :id => 'main_heading')
|
31
|
+
h6(:heading6, :id => 'main_heading')
|
32
|
+
paragraph(:first_para, :id => 'first')
|
33
|
+
file_field(:upload_me, :id => 'the_file')
|
34
|
+
end
|
35
|
+
|
36
|
+
class WatirBlockPageObject
|
37
|
+
include PageObject
|
38
|
+
|
39
|
+
attr_reader :value
|
40
|
+
|
41
|
+
text_field :first_name do |element|
|
42
|
+
"text_field"
|
43
|
+
end
|
44
|
+
hidden_field :secret do |element|
|
45
|
+
"hidden_field"
|
46
|
+
end
|
47
|
+
text_area :address do |element|
|
48
|
+
"text_area"
|
49
|
+
end
|
50
|
+
select_list :state do |element|
|
51
|
+
"select_list"
|
52
|
+
end
|
53
|
+
link :continue do |element|
|
54
|
+
"link"
|
55
|
+
end
|
56
|
+
checkbox :active do |element|
|
57
|
+
"checkbox"
|
58
|
+
end
|
59
|
+
radio_button :first do |element|
|
60
|
+
"radio_button"
|
61
|
+
end
|
62
|
+
button :click_me do |element|
|
63
|
+
"button"
|
64
|
+
end
|
65
|
+
div :footer do |element|
|
66
|
+
"div"
|
67
|
+
end
|
68
|
+
span :alert do |element|
|
69
|
+
"span"
|
70
|
+
end
|
71
|
+
table :cart do |element|
|
72
|
+
"table"
|
73
|
+
end
|
74
|
+
cell :total do |element|
|
75
|
+
"cell"
|
76
|
+
end
|
77
|
+
image :logo do |element|
|
78
|
+
"image"
|
79
|
+
end
|
80
|
+
form :login do |element|
|
81
|
+
"form"
|
82
|
+
end
|
83
|
+
list_item :item_one do |element|
|
84
|
+
"list_item"
|
85
|
+
end
|
86
|
+
unordered_list :menu do |element|
|
87
|
+
"unordered_list"
|
88
|
+
end
|
89
|
+
ordered_list :top_five do |element|
|
90
|
+
"ordered_list"
|
91
|
+
end
|
92
|
+
h1 :heading1 do |element|
|
93
|
+
"h1"
|
94
|
+
end
|
95
|
+
h2 :heading2 do |element|
|
96
|
+
"h2"
|
97
|
+
end
|
98
|
+
h3 :heading3 do |element|
|
99
|
+
"h3"
|
100
|
+
end
|
101
|
+
h4 :heading4 do |element|
|
102
|
+
"h4"
|
103
|
+
end
|
104
|
+
h5 :heading5 do |element|
|
105
|
+
"h5"
|
106
|
+
end
|
107
|
+
h6 :heading6 do |element|
|
108
|
+
"h6"
|
109
|
+
end
|
110
|
+
paragraph :first_para do |element|
|
111
|
+
"p"
|
112
|
+
end
|
113
|
+
file_field :a_file do |element|
|
114
|
+
"file_field"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe PageObject::Accessors do
|
119
|
+
let(:watir_browser) { mock_watir_browser }
|
120
|
+
let(:watir_page_object) { WatirAccessorsTestPageObject.new(watir_browser) }
|
121
|
+
let(:block_page_object) { WatirBlockPageObject.new(watir_browser) }
|
122
|
+
|
123
|
+
context "goto a page" do
|
124
|
+
|
125
|
+
it "should navigate to a page when requested" do
|
126
|
+
watir_browser.should_receive(:goto)
|
127
|
+
WatirAccessorsTestPageObject.new(watir_browser, true)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should call a method when page_url called with a symbol" do
|
131
|
+
class SymbolPageUrl
|
132
|
+
include PageObject
|
133
|
+
page_url :custom_url
|
134
|
+
def custom_url
|
135
|
+
"custom"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
watir_browser.should_receive(:goto).with('custom')
|
139
|
+
SymbolPageUrl.new(watir_browser, true)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should not navigate to a page when not requested" do
|
143
|
+
watir_browser.should_not_receive(:goto)
|
144
|
+
WatirAccessorsTestPageObject.new(watir_browser)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should not navigate to a page when 'page_url' not specified" do
|
148
|
+
watir_browser.should_not_receive(:goto)
|
149
|
+
WatirBlockPageObject.new(watir_browser, true)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "validating the page title" do
|
154
|
+
|
155
|
+
it "should validate the title" do
|
156
|
+
watir_browser.should_receive(:title).and_return("Expected Title")
|
157
|
+
watir_page_object.should have_expected_title
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should raise error when it does not have expected title" do
|
161
|
+
watir_browser.should_receive(:title).twice.and_return("Not Expected")
|
162
|
+
expect { watir_page_object.has_expected_title? }.to raise_error
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "validating the existence of an element" do
|
167
|
+
it "should validate an element exists" do
|
168
|
+
watir_page_object.should_receive(:google_search_element).and_return(watir_browser)
|
169
|
+
watir_browser.should_receive(:when_present).and_return(true)
|
170
|
+
watir_page_object.has_expected_element?
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should handle non-existent elements gracefully" do
|
174
|
+
class FakePage
|
175
|
+
include PageObject
|
176
|
+
expected_element :foo
|
177
|
+
end
|
178
|
+
FakePage.new(watir_browser).should_not have_expected_element
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "using default identifiers" do
|
183
|
+
class WatirDefaultIdentifier
|
184
|
+
include PageObject
|
185
|
+
text_field(:default_tf)
|
186
|
+
hidden_field(:default_hf)
|
187
|
+
text_area(:default_ta)
|
188
|
+
select_list(:default_sl)
|
189
|
+
link(:default_link)
|
190
|
+
checkbox(:default_cb)
|
191
|
+
radio_button(:default_rb)
|
192
|
+
button(:default_but)
|
193
|
+
div(:default_div)
|
194
|
+
span(:default_span)
|
195
|
+
table(:default_tab)
|
196
|
+
cell(:default_cell)
|
197
|
+
image(:default_im)
|
198
|
+
form(:default_form)
|
199
|
+
list_item(:default_li)
|
200
|
+
unordered_list(:default_ul)
|
201
|
+
ordered_list(:default_ol)
|
202
|
+
h1(:default_h1)
|
203
|
+
h2(:default_h2)
|
204
|
+
h3(:default_h3)
|
205
|
+
h4(:default_h4)
|
206
|
+
h5(:default_h5)
|
207
|
+
h6(:default_h6)
|
208
|
+
paragraph(:default_p)
|
209
|
+
file_field(:default_ff)
|
210
|
+
label(:default_lab)
|
211
|
+
element(:default_el, :audio)
|
212
|
+
end
|
213
|
+
|
214
|
+
let(:default_identifier) { WatirDefaultIdentifier.new(watir_browser) }
|
215
|
+
|
216
|
+
def mock_driver_for(tag)
|
217
|
+
watir_browser.should_receive(tag).with(:index => 0).and_return(watir_browser)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should work with a text_field" do
|
221
|
+
mock_driver_for :text_field
|
222
|
+
default_identifier.default_tf?
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should work with a hidden field" do
|
226
|
+
mock_driver_for :hidden
|
227
|
+
default_identifier.default_hf?
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should work with a text area" do
|
231
|
+
mock_driver_for :textarea
|
232
|
+
default_identifier.default_ta?
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should work with a select list" do
|
236
|
+
mock_driver_for :select_list
|
237
|
+
default_identifier.default_sl?
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should work with a link" do
|
241
|
+
mock_driver_for :link
|
242
|
+
default_identifier.default_link?
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should work with a checkbox" do
|
246
|
+
mock_driver_for :checkbox
|
247
|
+
default_identifier.default_cb?
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should work with a radio button" do
|
251
|
+
mock_driver_for :radio
|
252
|
+
default_identifier.default_rb?
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should work with a button" do
|
256
|
+
mock_driver_for :button
|
257
|
+
default_identifier.default_but?
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should work with a div" do
|
261
|
+
mock_driver_for :div
|
262
|
+
default_identifier.default_div?
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should work with a span" do
|
266
|
+
mock_driver_for :span
|
267
|
+
default_identifier.default_span?
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should work for a table" do
|
271
|
+
mock_driver_for :table
|
272
|
+
default_identifier.default_tab_element.should_not be_nil
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should work for a cell" do
|
276
|
+
mock_driver_for :td
|
277
|
+
default_identifier.default_cell?
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should work for an image" do
|
281
|
+
mock_driver_for :image
|
282
|
+
default_identifier.default_im?
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should work for a form" do
|
286
|
+
mock_driver_for :form
|
287
|
+
default_identifier.default_form?
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should work for a list item" do
|
291
|
+
mock_driver_for :li
|
292
|
+
default_identifier.default_li?
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should work for unordered lists" do
|
296
|
+
mock_driver_for :ul
|
297
|
+
default_identifier.default_ul?
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should work for ordered lists" do
|
301
|
+
mock_driver_for :ol
|
302
|
+
default_identifier.default_ol?
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should work for h1" do
|
306
|
+
mock_driver_for :h1
|
307
|
+
default_identifier.default_h1?
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should work for h2" do
|
311
|
+
mock_driver_for :h2
|
312
|
+
default_identifier.default_h2?
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should work for h3" do
|
316
|
+
mock_driver_for :h3
|
317
|
+
default_identifier.default_h3?
|
318
|
+
end
|
319
|
+
|
320
|
+
it "should work for a h4" do
|
321
|
+
mock_driver_for :h4
|
322
|
+
default_identifier.default_h4?
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should work for a h5" do
|
326
|
+
mock_driver_for :h5
|
327
|
+
default_identifier.default_h5?
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should work for a h6" do
|
331
|
+
mock_driver_for :h6
|
332
|
+
default_identifier.default_h6?
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should work with a paragraph" do
|
336
|
+
mock_driver_for :p
|
337
|
+
default_identifier.default_p?
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should work with a file_field" do
|
341
|
+
mock_driver_for :file_field
|
342
|
+
default_identifier.default_ff?
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should work with a label" do
|
346
|
+
mock_driver_for :label
|
347
|
+
default_identifier.default_lab?
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should work with an element" do
|
351
|
+
mock_driver_for :audio
|
352
|
+
default_identifier.default_el?
|
353
|
+
end
|
354
|
+
|
355
|
+
end
|
356
|
+
|
357
|
+
context "link accessors" do
|
358
|
+
context "when called on a page object" do
|
359
|
+
it "should generate accessor methods" do
|
360
|
+
watir_page_object.should respond_to(:google_search)
|
361
|
+
watir_page_object.should respond_to(:google_search_element)
|
362
|
+
watir_page_object.should respond_to(:google_search_link)
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should call a block on the element method when present" do
|
366
|
+
block_page_object.continue_element.should == "link"
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
it "should select a link" do
|
371
|
+
watir_browser.stub_chain(:link, :click)
|
372
|
+
watir_page_object.google_search
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should return a link element" do
|
376
|
+
watir_browser.should_receive(:link).and_return(watir_browser)
|
377
|
+
element = watir_page_object.google_search_element
|
378
|
+
element.should be_instance_of PageObject::Elements::Link
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
|
383
|
+
describe "text_field accessors" do
|
384
|
+
context "when called on a page object" do
|
385
|
+
it "should generate accessor methods" do
|
386
|
+
watir_page_object.should respond_to(:first_name)
|
387
|
+
watir_page_object.should respond_to(:first_name=)
|
388
|
+
watir_page_object.should respond_to(:first_name_element)
|
389
|
+
watir_page_object.should respond_to(:first_name_text_field)
|
390
|
+
watir_page_object.should respond_to(:first_name?)
|
391
|
+
end
|
392
|
+
|
393
|
+
it "should call a block on the element method when present" do
|
394
|
+
block_page_object.first_name_element.should == "text_field"
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should get the text from the text field element" do
|
399
|
+
watir_browser.should_receive(:text_field).and_return(watir_browser)
|
400
|
+
watir_browser.should_receive(:value).and_return('Kim')
|
401
|
+
watir_page_object.first_name.should == 'Kim'
|
402
|
+
end
|
403
|
+
|
404
|
+
it "should set some text on a text field element" do
|
405
|
+
watir_browser.should_receive(:text_field).and_return(watir_browser)
|
406
|
+
watir_browser.should_receive(:set).with('Kim')
|
407
|
+
watir_page_object.first_name = 'Kim'
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should retrieve a text field element" do
|
411
|
+
watir_browser.should_receive(:text_field).and_return(watir_browser)
|
412
|
+
element = watir_page_object.first_name_element
|
413
|
+
element.should be_instance_of PageObject::Elements::TextField
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
|
418
|
+
describe "hidden field accessors" do
|
419
|
+
context "when called on a page object" do
|
420
|
+
it "should generate accessor methods" do
|
421
|
+
watir_page_object.should respond_to(:social_security_number)
|
422
|
+
watir_page_object.should respond_to(:social_security_number_element)
|
423
|
+
watir_page_object.should respond_to(:social_security_number_hidden_field)
|
424
|
+
end
|
425
|
+
|
426
|
+
it "should call a block on the element method when present" do
|
427
|
+
block_page_object.secret_element.should == "hidden_field"
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
it "should get the text from a hidden field" do
|
432
|
+
watir_browser.should_receive(:hidden).and_return(watir_browser)
|
433
|
+
watir_browser.should_receive(:value).and_return("value")
|
434
|
+
watir_page_object.social_security_number.should == "value"
|
435
|
+
end
|
436
|
+
|
437
|
+
it "should retrieve a hidden field element" do
|
438
|
+
watir_browser.should_receive(:hidden).and_return(watir_browser)
|
439
|
+
element = watir_page_object.social_security_number_element
|
440
|
+
element.should be_instance_of(PageObject::Elements::HiddenField)
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
describe "text area accessors" do
|
445
|
+
context "when called on a page object" do
|
446
|
+
it "should generate accessor methods" do
|
447
|
+
watir_page_object.should respond_to(:address)
|
448
|
+
watir_page_object.should respond_to(:address=)
|
449
|
+
watir_page_object.should respond_to(:address_element)
|
450
|
+
watir_page_object.should respond_to(:address_text_area)
|
451
|
+
end
|
452
|
+
|
453
|
+
it "should call a block on the element method when present" do
|
454
|
+
block_page_object.address_element.should == "text_area"
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
it "should set some text on the text area" do
|
459
|
+
watir_browser.should_receive(:textarea).and_return(watir_browser)
|
460
|
+
watir_browser.should_receive(:set).with("123 main street")
|
461
|
+
watir_page_object.address = "123 main street"
|
462
|
+
end
|
463
|
+
|
464
|
+
it "should get the text from the text area" do
|
465
|
+
watir_browser.should_receive(:textarea).and_return(watir_browser)
|
466
|
+
watir_browser.should_receive(:value).and_return("123 main street")
|
467
|
+
watir_page_object.address.should == "123 main street"
|
468
|
+
end
|
469
|
+
|
470
|
+
it "should retrieve a text area element" do
|
471
|
+
watir_browser.should_receive(:textarea).and_return(watir_browser)
|
472
|
+
element = watir_page_object.address_element
|
473
|
+
element.should be_instance_of PageObject::Elements::TextArea
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
describe "select_list accessors" do
|
478
|
+
context "when called on a page object" do
|
479
|
+
it "should generate accessor methods" do
|
480
|
+
watir_page_object.should respond_to :state
|
481
|
+
watir_page_object.should respond_to :state=
|
482
|
+
watir_page_object.should respond_to(:state_element)
|
483
|
+
watir_page_object.should respond_to(:state_select_list)
|
484
|
+
end
|
485
|
+
|
486
|
+
it "should call a block on the element method when present" do
|
487
|
+
block_page_object.state_element.should == "select_list"
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
it "should get the current item from a select list" do
|
492
|
+
selected = "OH"
|
493
|
+
selected.should_receive(:selected?).and_return(selected)
|
494
|
+
selected.should_receive(:text).and_return("OH")
|
495
|
+
watir_browser.should_receive(:select_list).and_return watir_browser
|
496
|
+
watir_browser.should_receive(:options).and_return([selected])
|
497
|
+
watir_page_object.state.should == "OH"
|
498
|
+
end
|
499
|
+
|
500
|
+
it "should set the current item of a select list" do
|
501
|
+
watir_browser.should_receive(:select_list).and_return watir_browser
|
502
|
+
watir_browser.should_receive(:select).with("OH")
|
503
|
+
watir_page_object.state = "OH"
|
504
|
+
end
|
505
|
+
|
506
|
+
it "should retreive the select list element" do
|
507
|
+
watir_browser.should_receive(:select_list).and_return(watir_browser)
|
508
|
+
element = watir_page_object.state_element
|
509
|
+
element.should be_instance_of PageObject::Elements::SelectList
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
|
514
|
+
describe "check_box accessors" do
|
515
|
+
context "when called on a page object" do
|
516
|
+
it "should generate accessor methods" do
|
517
|
+
watir_page_object.should respond_to :check_active
|
518
|
+
watir_page_object.should respond_to :uncheck_active
|
519
|
+
watir_page_object.should respond_to :active_checked?
|
520
|
+
watir_page_object.should respond_to :active_element
|
521
|
+
watir_page_object.should respond_to :active_checkbox
|
522
|
+
end
|
523
|
+
|
524
|
+
it "should call a block on the element method when present" do
|
525
|
+
block_page_object.active_element.should == "checkbox"
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
it "should check a check box element" do
|
530
|
+
watir_browser.should_receive(:checkbox).and_return(watir_browser)
|
531
|
+
watir_browser.should_receive(:set)
|
532
|
+
watir_page_object.check_active
|
533
|
+
end
|
534
|
+
|
535
|
+
it "should clear a check box element" do
|
536
|
+
watir_browser.should_receive(:checkbox).and_return(watir_browser)
|
537
|
+
watir_browser.should_receive(:clear)
|
538
|
+
watir_page_object.uncheck_active
|
539
|
+
end
|
540
|
+
|
541
|
+
it "should know if a check box element is selected" do
|
542
|
+
watir_browser.should_receive(:checkbox).and_return(watir_browser)
|
543
|
+
watir_browser.should_receive(:set?).and_return(true)
|
544
|
+
watir_page_object.active_checked?.should be_true
|
545
|
+
end
|
546
|
+
|
547
|
+
it "should retrieve a checkbox element" do
|
548
|
+
watir_browser.should_receive(:checkbox).and_return(watir_browser)
|
549
|
+
element = watir_page_object.active_element
|
550
|
+
element.should be_instance_of PageObject::Elements::CheckBox
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
554
|
+
|
555
|
+
describe "radio accessors" do
|
556
|
+
context "when called on a page object" do
|
557
|
+
it "should generate accessor methods" do
|
558
|
+
watir_page_object.should respond_to :select_first
|
559
|
+
watir_page_object.should respond_to :clear_first
|
560
|
+
watir_page_object.should respond_to :first_selected?
|
561
|
+
watir_page_object.should respond_to(:first_element)
|
562
|
+
watir_page_object.should respond_to(:first_radio_button)
|
563
|
+
end
|
564
|
+
|
565
|
+
it "should call a block on the element method when present" do
|
566
|
+
block_page_object.first_element.should == "radio_button"
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
it "should select a radio button" do
|
571
|
+
watir_browser.should_receive(:radio).and_return(watir_browser)
|
572
|
+
watir_browser.should_receive(:set)
|
573
|
+
watir_page_object.select_first
|
574
|
+
end
|
575
|
+
|
576
|
+
it "should clear a radio button" do
|
577
|
+
watir_browser.should_receive(:radio).and_return(watir_browser)
|
578
|
+
watir_browser.should_receive(:clear)
|
579
|
+
watir_page_object.clear_first
|
580
|
+
end
|
581
|
+
|
582
|
+
it "should determine if a radio is selected" do
|
583
|
+
watir_browser.should_receive(:radio).and_return(watir_browser)
|
584
|
+
watir_browser.should_receive(:set?)
|
585
|
+
watir_page_object.first_selected?
|
586
|
+
end
|
587
|
+
|
588
|
+
it "should retrieve a radio button element" do
|
589
|
+
watir_browser.should_receive(:radio).and_return(watir_browser)
|
590
|
+
element = watir_page_object.first_element
|
591
|
+
element.should be_instance_of PageObject::Elements::RadioButton
|
592
|
+
end
|
593
|
+
end
|
594
|
+
|
595
|
+
describe "button accessors" do
|
596
|
+
context "when called on a page object" do
|
597
|
+
it "should generate accessor methods" do
|
598
|
+
watir_page_object.should respond_to :click_me
|
599
|
+
watir_page_object.should respond_to :click_me_element
|
600
|
+
watir_page_object.should respond_to :click_me_button
|
601
|
+
end
|
602
|
+
|
603
|
+
it "should call a block on the element method when present" do
|
604
|
+
block_page_object.click_me_element.should == "button"
|
605
|
+
end
|
606
|
+
end
|
607
|
+
|
608
|
+
it "should be able to click a button" do
|
609
|
+
watir_browser.should_receive(:button).and_return(watir_browser)
|
610
|
+
watir_browser.should_receive(:click)
|
611
|
+
watir_page_object.click_me
|
612
|
+
end
|
613
|
+
|
614
|
+
it "should retrieve a button element" do
|
615
|
+
watir_browser.should_receive(:button).and_return(watir_browser)
|
616
|
+
element = watir_page_object.click_me_element
|
617
|
+
element.should be_instance_of PageObject::Elements::Button
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
describe "div accessors" do
|
622
|
+
context "when called on a page object" do
|
623
|
+
it "should generate accessor methods" do
|
624
|
+
watir_page_object.should respond_to(:message)
|
625
|
+
watir_page_object.should respond_to(:message_element)
|
626
|
+
watir_page_object.should respond_to(:message_div)
|
627
|
+
end
|
628
|
+
|
629
|
+
it "should call a block on the element method when present" do
|
630
|
+
block_page_object.footer_element.should == "div"
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
it "should retrieve the text from a div" do
|
635
|
+
watir_browser.should_receive(:div).and_return(watir_browser)
|
636
|
+
watir_browser.should_receive(:text).and_return("Message from div")
|
637
|
+
watir_page_object.message.should == "Message from div"
|
638
|
+
end
|
639
|
+
|
640
|
+
it "should retrieve the div element from the page" do
|
641
|
+
watir_browser.should_receive(:div).and_return(watir_browser)
|
642
|
+
element = watir_page_object.message_element
|
643
|
+
element.should be_instance_of PageObject::Elements::Div
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
describe "span accessors" do
|
648
|
+
context "when called on a page object" do
|
649
|
+
it "should generate accessor methods" do
|
650
|
+
watir_page_object.should respond_to(:alert)
|
651
|
+
watir_page_object.should respond_to(:alert_element)
|
652
|
+
watir_page_object.should respond_to(:alert_span)
|
653
|
+
end
|
654
|
+
|
655
|
+
it "should call a block on the element method when present" do
|
656
|
+
block_page_object.alert_element.should == "span"
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
it "should retrieve the text from a span" do
|
661
|
+
watir_browser.should_receive(:span).and_return(watir_browser)
|
662
|
+
watir_browser.should_receive(:text).and_return("Alert")
|
663
|
+
watir_page_object.alert.should == "Alert"
|
664
|
+
end
|
665
|
+
|
666
|
+
it "should retrieve the span element from the page" do
|
667
|
+
watir_browser.should_receive(:span).and_return(watir_browser)
|
668
|
+
element = watir_page_object.alert_element
|
669
|
+
element.should be_instance_of PageObject::Elements::Span
|
670
|
+
end
|
671
|
+
end
|
672
|
+
|
673
|
+
describe "table accessors" do
|
674
|
+
context "when called on a page object" do
|
675
|
+
it "should generate accessor methods" do
|
676
|
+
watir_page_object.should respond_to(:cart_element)
|
677
|
+
watir_page_object.should respond_to(:cart_table)
|
678
|
+
end
|
679
|
+
|
680
|
+
it "should call a block on the element method when present" do
|
681
|
+
block_page_object.cart_element.should == "table"
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
it "should retrieve the table element from the page" do
|
686
|
+
watir_browser.should_receive(:table).and_return(watir_browser)
|
687
|
+
element = watir_page_object.cart_element
|
688
|
+
element.should be_instance_of PageObject::Elements::Table
|
689
|
+
end
|
690
|
+
end
|
691
|
+
|
692
|
+
describe "table cell accessors" do
|
693
|
+
context "when called on a page object" do
|
694
|
+
it "should generate accessor methods" do
|
695
|
+
watir_page_object.should respond_to(:total)
|
696
|
+
watir_page_object.should respond_to(:total_element)
|
697
|
+
watir_page_object.should respond_to(:total_cell)
|
698
|
+
end
|
699
|
+
|
700
|
+
it "should call a block on the element method when present" do
|
701
|
+
block_page_object.total_element.should == "cell"
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
it "should retrieve the text for the cell" do
|
706
|
+
watir_browser.should_receive(:td).and_return(watir_browser)
|
707
|
+
watir_browser.should_receive(:text).and_return('10.00')
|
708
|
+
watir_page_object.total.should == '10.00'
|
709
|
+
end
|
710
|
+
|
711
|
+
it "should retrieve the cell element from the page" do
|
712
|
+
watir_browser.should_receive(:td).and_return(watir_browser)
|
713
|
+
element = watir_page_object.total_element
|
714
|
+
element.should be_instance_of PageObject::Elements::TableCell
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
describe "image accessors" do
|
719
|
+
context "when called on a page object" do
|
720
|
+
it "should generate accessor methods" do
|
721
|
+
watir_page_object.should respond_to(:logo_element)
|
722
|
+
watir_page_object.should respond_to(:logo_image)
|
723
|
+
end
|
724
|
+
|
725
|
+
it "should call a block on the element method when present" do
|
726
|
+
block_page_object.logo_element.should == "image"
|
727
|
+
end
|
728
|
+
end
|
729
|
+
|
730
|
+
it "should retrieve the image element from the page" do
|
731
|
+
watir_browser.should_receive(:image).and_return(watir_browser)
|
732
|
+
element = watir_page_object.logo_element
|
733
|
+
element.should be_instance_of PageObject::Elements::Image
|
734
|
+
end
|
735
|
+
end
|
736
|
+
|
737
|
+
describe "form accessors" do
|
738
|
+
context "when called on a page object" do
|
739
|
+
it "should generate accessor methods" do
|
740
|
+
watir_page_object.should respond_to(:login_element)
|
741
|
+
watir_page_object.should respond_to(:login_form)
|
742
|
+
end
|
743
|
+
|
744
|
+
it "should call a block on the element method when present" do
|
745
|
+
block_page_object.login_element.should == "form"
|
746
|
+
end
|
747
|
+
end
|
748
|
+
|
749
|
+
it "should retrieve the form element from the page" do
|
750
|
+
watir_browser.should_receive(:form).and_return(watir_browser)
|
751
|
+
element = watir_page_object.login_element
|
752
|
+
element.should be_instance_of PageObject::Elements::Form
|
753
|
+
end
|
754
|
+
end
|
755
|
+
|
756
|
+
describe "list item accessors" do
|
757
|
+
context "when called on a page object" do
|
758
|
+
it "should generate accessor methods" do
|
759
|
+
watir_page_object.should respond_to(:item_one)
|
760
|
+
watir_page_object.should respond_to(:item_one_element)
|
761
|
+
watir_page_object.should respond_to(:item_one_list_item)
|
762
|
+
end
|
763
|
+
|
764
|
+
it "should call a block on the element method when present" do
|
765
|
+
block_page_object.item_one_element.should == "list_item"
|
766
|
+
end
|
767
|
+
end
|
768
|
+
|
769
|
+
it "should retrieve the text from the list item" do
|
770
|
+
watir_browser.should_receive(:li).and_return(watir_browser)
|
771
|
+
watir_browser.should_receive(:text).and_return("value")
|
772
|
+
watir_page_object.item_one.should == "value"
|
773
|
+
end
|
774
|
+
|
775
|
+
it "should retrieve the list item element from the page" do
|
776
|
+
watir_browser.should_receive(:li).and_return(watir_browser)
|
777
|
+
element = watir_page_object.item_one_element
|
778
|
+
element.should be_instance_of PageObject::Elements::ListItem
|
779
|
+
end
|
780
|
+
end
|
781
|
+
|
782
|
+
describe "unordered list accessors" do
|
783
|
+
context "when called on a page object" do
|
784
|
+
it "should generate accessor methods" do
|
785
|
+
watir_page_object.should respond_to(:menu_element)
|
786
|
+
watir_page_object.should respond_to(:menu_unordered_list)
|
787
|
+
end
|
788
|
+
|
789
|
+
it "should call a block on the element method when present" do
|
790
|
+
block_page_object.menu_element.should == "unordered_list"
|
791
|
+
end
|
792
|
+
end
|
793
|
+
|
794
|
+
it "should retrieve the element from the page" do
|
795
|
+
watir_browser.should_receive(:ul).and_return(watir_browser)
|
796
|
+
element = watir_page_object.menu_element
|
797
|
+
element.should be_instance_of PageObject::Elements::UnorderedList
|
798
|
+
end
|
799
|
+
end
|
800
|
+
|
801
|
+
describe "ordered list accessors" do
|
802
|
+
context "when called on a page object" do
|
803
|
+
it "should generate accessor methods" do
|
804
|
+
watir_page_object.should respond_to(:top_five_element)
|
805
|
+
watir_page_object.should respond_to(:top_five_ordered_list)
|
806
|
+
end
|
807
|
+
|
808
|
+
it "should call a block on the element method when present" do
|
809
|
+
block_page_object.top_five_element.should == "ordered_list"
|
810
|
+
end
|
811
|
+
end
|
812
|
+
|
813
|
+
it "should retrieve the element from the page" do
|
814
|
+
watir_browser.should_receive(:ol).and_return(watir_browser)
|
815
|
+
element = watir_page_object.top_five_element
|
816
|
+
element.should be_instance_of PageObject::Elements::OrderedList
|
817
|
+
end
|
818
|
+
end
|
819
|
+
|
820
|
+
describe "h1 accessors" do
|
821
|
+
context "when called on a page object" do
|
822
|
+
it "should generate accessor methods" do
|
823
|
+
watir_page_object.should respond_to(:heading1)
|
824
|
+
watir_page_object.should respond_to(:heading1_element)
|
825
|
+
end
|
826
|
+
|
827
|
+
it "should call a block on the element method when present" do
|
828
|
+
block_page_object.heading1_element.should == "h1"
|
829
|
+
end
|
830
|
+
end
|
831
|
+
|
832
|
+
it "should retrieve the text from the h1" do
|
833
|
+
watir_browser.should_receive(:h1).and_return(watir_browser)
|
834
|
+
watir_browser.should_receive(:text).and_return("value")
|
835
|
+
watir_page_object.heading1.should == "value"
|
836
|
+
end
|
837
|
+
|
838
|
+
it "should retrieve the element from the page" do
|
839
|
+
watir_browser.should_receive(:h1).and_return(watir_browser)
|
840
|
+
element = watir_page_object.heading1_element
|
841
|
+
element.should be_instance_of PageObject::Elements::Heading
|
842
|
+
end
|
843
|
+
end
|
844
|
+
|
845
|
+
describe "h2 accessors" do
|
846
|
+
context "when called on a page object" do
|
847
|
+
it "should generate accessor methods" do
|
848
|
+
watir_page_object.should respond_to(:heading2)
|
849
|
+
watir_page_object.should respond_to(:heading2_element)
|
850
|
+
end
|
851
|
+
|
852
|
+
it "should call a block on the element method when present" do
|
853
|
+
block_page_object.heading2_element.should == "h2"
|
854
|
+
end
|
855
|
+
end
|
856
|
+
|
857
|
+
it "should retrieve the text from the h2" do
|
858
|
+
watir_browser.should_receive(:h2).and_return(watir_browser)
|
859
|
+
watir_browser.should_receive(:text).and_return("value")
|
860
|
+
watir_page_object.heading2.should == "value"
|
861
|
+
end
|
862
|
+
|
863
|
+
it "should retrieve the element from the page" do
|
864
|
+
watir_browser.should_receive(:h2).and_return(watir_browser)
|
865
|
+
element = watir_page_object.heading2_element
|
866
|
+
element.should be_instance_of PageObject::Elements::Heading
|
867
|
+
end
|
868
|
+
end
|
869
|
+
|
870
|
+
describe "h3 accessors" do
|
871
|
+
context "when called on a page object" do
|
872
|
+
it "should generate accessor methods" do
|
873
|
+
watir_page_object.should respond_to(:heading3)
|
874
|
+
watir_page_object.should respond_to(:heading3_element)
|
875
|
+
end
|
876
|
+
|
877
|
+
it "should call a block on the element method when present" do
|
878
|
+
block_page_object.heading3_element.should == "h3"
|
879
|
+
end
|
880
|
+
end
|
881
|
+
|
882
|
+
it "should retrieve the text from the h3" do
|
883
|
+
watir_browser.should_receive(:h3).and_return(watir_browser)
|
884
|
+
watir_browser.should_receive(:text).and_return("value")
|
885
|
+
watir_page_object.heading3.should == "value"
|
886
|
+
end
|
887
|
+
|
888
|
+
it "should retrieve the element from the page" do
|
889
|
+
watir_browser.should_receive(:h3).and_return(watir_browser)
|
890
|
+
element = watir_page_object.heading3_element
|
891
|
+
element.should be_instance_of PageObject::Elements::Heading
|
892
|
+
end
|
893
|
+
end
|
894
|
+
|
895
|
+
describe "h4 accessors" do
|
896
|
+
context "when called on a page object" do
|
897
|
+
it "should generate accessor methods" do
|
898
|
+
watir_page_object.should respond_to(:heading4)
|
899
|
+
watir_page_object.should respond_to(:heading4_element)
|
900
|
+
end
|
901
|
+
|
902
|
+
it "should call a block on the element method when present" do
|
903
|
+
block_page_object.heading4_element.should == "h4"
|
904
|
+
end
|
905
|
+
end
|
906
|
+
|
907
|
+
it "should retrieve the text from the h4" do
|
908
|
+
watir_browser.should_receive(:h4).and_return(watir_browser)
|
909
|
+
watir_browser.should_receive(:text).and_return("value")
|
910
|
+
watir_page_object.heading4.should == "value"
|
911
|
+
end
|
912
|
+
|
913
|
+
it "should retrieve the element from the page" do
|
914
|
+
watir_browser.should_receive(:h4).and_return(watir_browser)
|
915
|
+
element = watir_page_object.heading4_element
|
916
|
+
element.should be_instance_of PageObject::Elements::Heading
|
917
|
+
end
|
918
|
+
end
|
919
|
+
|
920
|
+
describe "h5 accessors" do
|
921
|
+
context "when called on a page object" do
|
922
|
+
it "should generate accessor methods" do
|
923
|
+
watir_page_object.should respond_to(:heading5)
|
924
|
+
watir_page_object.should respond_to(:heading5_element)
|
925
|
+
end
|
926
|
+
|
927
|
+
it "should call a block on the element method when present" do
|
928
|
+
block_page_object.heading5_element.should == "h5"
|
929
|
+
end
|
930
|
+
end
|
931
|
+
|
932
|
+
it "should retrieve the text from the h5" do
|
933
|
+
watir_browser.should_receive(:h5).and_return(watir_browser)
|
934
|
+
watir_browser.should_receive(:text).and_return("value")
|
935
|
+
watir_page_object.heading5.should == "value"
|
936
|
+
end
|
937
|
+
|
938
|
+
it "should retrieve the element from the page" do
|
939
|
+
watir_browser.should_receive(:h5).and_return(watir_browser)
|
940
|
+
element = watir_page_object.heading5_element
|
941
|
+
element.should be_instance_of PageObject::Elements::Heading
|
942
|
+
end
|
943
|
+
end
|
944
|
+
|
945
|
+
describe "h6 accessors" do
|
946
|
+
context "when called on a page object" do
|
947
|
+
it "should generate accessor methods" do
|
948
|
+
watir_page_object.should respond_to(:heading6)
|
949
|
+
watir_page_object.should respond_to(:heading6_element)
|
950
|
+
end
|
951
|
+
|
952
|
+
it "should call a block on the element method when present" do
|
953
|
+
block_page_object.heading6_element.should == "h6"
|
954
|
+
end
|
955
|
+
end
|
956
|
+
|
957
|
+
it "should retrieve the text from the h6" do
|
958
|
+
watir_browser.should_receive(:h6).and_return(watir_browser)
|
959
|
+
watir_browser.should_receive(:text).and_return("value")
|
960
|
+
watir_page_object.heading6.should == "value"
|
961
|
+
end
|
962
|
+
|
963
|
+
it "should retrieve the element from the page" do
|
964
|
+
watir_browser.should_receive(:h6).and_return(watir_browser)
|
965
|
+
element = watir_page_object.heading6_element
|
966
|
+
element.should be_instance_of PageObject::Elements::Heading
|
967
|
+
end
|
968
|
+
end
|
969
|
+
|
970
|
+
|
971
|
+
describe "p accessors" do
|
972
|
+
context "when called on a page object" do
|
973
|
+
it "should generate accessor methods" do
|
974
|
+
watir_page_object.should respond_to(:first_para)
|
975
|
+
watir_page_object.should respond_to(:first_para_element)
|
976
|
+
end
|
977
|
+
|
978
|
+
it "should call a block on the element method when present" do
|
979
|
+
block_page_object.first_para_element.should == "p"
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
983
|
+
it "should retrieve the text from the p" do
|
984
|
+
watir_browser.should_receive(:p).and_return(watir_browser)
|
985
|
+
watir_browser.should_receive(:text).and_return("value")
|
986
|
+
watir_page_object.first_para.should == "value"
|
987
|
+
end
|
988
|
+
|
989
|
+
it "should retrieve the element from the page" do
|
990
|
+
watir_browser.should_receive(:p).and_return(watir_browser)
|
991
|
+
element = watir_page_object.first_para_element
|
992
|
+
element.should be_instance_of PageObject::Elements::Paragraph
|
993
|
+
end
|
994
|
+
end
|
995
|
+
|
996
|
+
describe "file_field accessors" do
|
997
|
+
context "when called on a page object" do
|
998
|
+
it "should generate accessor methods" do
|
999
|
+
watir_page_object.should respond_to(:upload_me=)
|
1000
|
+
watir_page_object.should respond_to(:upload_me_element)
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
it "should call a block on the element method when present" do
|
1004
|
+
block_page_object.a_file_element.should == "file_field"
|
1005
|
+
end
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
it "should set the file name" do
|
1009
|
+
watir_browser.should_receive(:file_field).and_return(watir_browser)
|
1010
|
+
watir_browser.should_receive(:set).with('some_file')
|
1011
|
+
watir_page_object.upload_me = 'some_file'
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
it "should retrieve a text field element" do
|
1015
|
+
watir_browser.should_receive(:file_field).and_return(watir_browser)
|
1016
|
+
element = watir_page_object.upload_me_element
|
1017
|
+
element.should be_instance_of PageObject::Elements::FileField
|
1018
|
+
end
|
1019
|
+
end
|
1020
|
+
end
|