page-object 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +0 -2
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/ChangeLog +23 -0
  5. data/README.md +2 -0
  6. data/features/button.feature +37 -0
  7. data/features/div.feature +45 -0
  8. data/features/html/static_elements.html +21 -3
  9. data/features/html/success.html +8 -0
  10. data/features/link.feature +1 -4
  11. data/features/step_definitions/accessor_steps.rb +37 -0
  12. data/features/step_definitions/element_steps.rb +18 -0
  13. data/features/step_definitions/table_steps.rb +14 -0
  14. data/features/support/page.rb +26 -1
  15. data/features/table.feature +52 -0
  16. data/features/table_cell.feature +45 -0
  17. data/lib/page-object/accessors.rb +88 -0
  18. data/lib/page-object/elements/button.rb +4 -7
  19. data/lib/page-object/elements/check_box.rb +0 -8
  20. data/lib/page-object/elements/div.rb +12 -0
  21. data/lib/page-object/elements/element.rb +22 -12
  22. data/lib/page-object/elements/link.rb +0 -8
  23. data/lib/page-object/elements/radio_button.rb +0 -8
  24. data/lib/page-object/elements/select_list.rb +0 -9
  25. data/lib/page-object/elements/table.rb +26 -0
  26. data/lib/page-object/elements/table_cell.rb +7 -0
  27. data/lib/page-object/elements/table_row.rb +26 -0
  28. data/lib/page-object/elements/text_field.rb +0 -9
  29. data/lib/page-object/elements.rb +4 -0
  30. data/lib/page-object/platforms/selenium_element.rb +29 -0
  31. data/lib/page-object/platforms/selenium_table.rb +24 -0
  32. data/lib/page-object/platforms/selenium_table_row.rb +16 -0
  33. data/lib/page-object/platforms/watir_element.rb +29 -0
  34. data/lib/page-object/platforms/watir_table.rb +15 -0
  35. data/lib/page-object/platforms/watir_table_row.rb +15 -0
  36. data/lib/page-object/selenium_page_object.rb +68 -1
  37. data/lib/page-object/version.rb +1 -1
  38. data/lib/page-object/watir_page_object.rb +67 -0
  39. data/spec/page-object/accessors_spec.rb +135 -8
  40. data/spec/page-object/elements/div_spec.rb +22 -0
  41. data/spec/page-object/elements/element_spec.rb +10 -1
  42. data/spec/page-object/elements/table_row_spec.rb +25 -0
  43. data/spec/page-object/elements/table_spec.rb +45 -0
  44. metadata +33 -4
  45. data/lib/page-object/selenium_element.rb +0 -12
  46. data/lib/page-object/watir_element.rb +0 -12
@@ -1,3 +1,3 @@
1
1
  module PageObject
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -186,5 +186,72 @@ module PageObject
186
186
  element = @browser.radio(identifier)
187
187
  PageObject::Elements::RadioButton.new(element, :platform => :watir)
188
188
  end
189
+
190
+ #
191
+ # platform method to return the text for a div
192
+ # See PageObject::Accessors#div
193
+ #
194
+ def div_text_for(identifier)
195
+ identifier = Elements::Div.watir_identifier_for identifier
196
+ @browser.div(identifier).text
197
+ end
198
+
199
+ #
200
+ # platform method to return a PageObject::Elements::Div element
201
+ # See PageObject::Accessors#div
202
+ #
203
+ def div_for(identifier)
204
+ identifier = Elements::Div.watir_identifier_for identifier
205
+ element = @browser.div(identifier)
206
+ PageObject::Elements::Div.new(element, :platform => :watir)
207
+ end
208
+
209
+ #
210
+ # platform method to click a button
211
+ # See PageObject::Accessors#button
212
+ #
213
+ def click_button_for(identifier)
214
+ identifier = Elements::Button.watir_identifier_for identifier
215
+ @browser.button(identifier).click
216
+ end
217
+
218
+ #
219
+ # platform method to retrieve a button element
220
+ # See PageObject::Accessors#button
221
+ #
222
+ def button_for(identifier)
223
+ identifier = Elements::Button.watir_identifier_for identifier
224
+ element = @browser.button(identifier)
225
+ PageObject::Elements::Button.new(element, :platform => :watir)
226
+ end
227
+
228
+ #
229
+ # platform method to retrieve a table element
230
+ # See PageObject::Accessors#table
231
+ #
232
+ def table_for(identifier)
233
+ identifier = Elements::Table.watir_identifier_for identifier
234
+ element = @browser.table(identifier)
235
+ PageObject::Elements::Table.new(element, :platform => :watir)
236
+ end
237
+
238
+ #
239
+ # platform method to retrieve the text from a table cell
240
+ # See PageObject::Accessors#cell
241
+ #
242
+ def cell_text_for(identifier)
243
+ identifier = Elements::Table.watir_identifier_for identifier
244
+ @browser.td(identifier).text
245
+ end
246
+
247
+ #
248
+ # platform method to retrieve a table cell element
249
+ # See PageObject::Accessors#cell
250
+ #
251
+ def cell_for(identifier)
252
+ identifier = Elements::Table.watir_identifier_for identifier
253
+ element = @browser.td(identifier)
254
+ PageObject::Elements::TableCell.new(element, :platform => :watir)
255
+ end
189
256
  end
190
257
  end
@@ -3,12 +3,15 @@ require 'spec_helper'
3
3
  class TestPageObject
4
4
  include PageObject
5
5
 
6
- link(:google_search, {:link => 'Google Search'})
7
- text_field(:first_name, {:id => 'first_name'})
8
- select_list(:state, {:id => 'state'})
9
- checkbox(:active, {:id => 'is_active_id'})
10
- radio_button(:first, {:id => 'first_choice'})
11
- button(:click_me, { :id => 'button_submit'})
6
+ link(:google_search, :link => 'Google Search')
7
+ text_field(:first_name, :id => 'first_name')
8
+ select_list(:state, :id => 'state')
9
+ checkbox(:active, :id => 'is_active_id')
10
+ radio_button(:first, :id => 'first_choice')
11
+ button(:click_me, :id => 'button_submit')
12
+ div(:message, :id => 'message_id')
13
+ table(:cart, :id => 'cart_id')
14
+ cell(:total, :id => 'total')
12
15
  end
13
16
 
14
17
  describe PageObject::Accessors do
@@ -85,7 +88,7 @@ describe PageObject::Accessors do
85
88
  context "Selenium implementation" do
86
89
  it "should get the text from the text field element" do
87
90
  selenium_browser.should_receive(:find_element).and_return(selenium_browser)
88
- selenium_browser.should_receive(:value).and_return('Katie')
91
+ selenium_browser.should_receive(:attribute).with('value').and_return('Katie')
89
92
  selenium_page_object.first_name.should == 'Katie'
90
93
  end
91
94
 
@@ -290,8 +293,132 @@ describe PageObject::Accessors do
290
293
  context "when called on a page object" do
291
294
  it "should generate accessor methods" do
292
295
  watir_page_object.should respond_to :click_me
296
+ watir_page_object.should respond_to :click_me_button
297
+ end
298
+ end
299
+
300
+ context "watir implementation" do
301
+ it "should be able to click a button" do
302
+ watir_browser.should_receive(:button).and_return(watir_browser)
303
+ watir_browser.should_receive(:click)
304
+ watir_page_object.click_me
305
+ end
306
+
307
+ it "should retrieve a button element" do
308
+ watir_browser.should_receive(:button).and_return(watir_browser)
309
+ element = watir_page_object.click_me_button
310
+ element.should be_instance_of PageObject::Elements::Button
311
+ end
312
+ end
313
+
314
+ context "selenium implementation" do
315
+ it "should be able to click a button" do
316
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
317
+ selenium_browser.should_receive(:click)
318
+ selenium_page_object.click_me
319
+ end
320
+
321
+ it "should retrieve a button element" do
322
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
323
+ element = selenium_page_object.click_me_button
324
+ element.should be_instance_of PageObject::Elements::Button
325
+
326
+ end
327
+ end
328
+ end
329
+
330
+ describe "div accessors" do
331
+ context "when called on a page object" do
332
+ it "should generate accessor methods" do
333
+ watir_page_object.should respond_to(:message)
334
+ watir_page_object.should respond_to(:message_div)
335
+ end
336
+ end
337
+
338
+ context "watir implementation" do
339
+ it "should retrieve the text from a div" do
340
+ watir_browser.should_receive(:div).and_return(watir_browser)
341
+ watir_browser.should_receive(:text).and_return("Message from div")
342
+ watir_page_object.message.should == "Message from div"
343
+ end
344
+
345
+ it "should retrieve the div element from the page" do
346
+ watir_browser.should_receive(:div).and_return(watir_browser)
347
+ element = watir_page_object.message_div
348
+ element.should be_instance_of PageObject::Elements::Div
349
+ end
350
+ end
351
+
352
+ context "selenium implementation" do
353
+ it "should retrieve the text from a div" do
354
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
355
+ selenium_browser.should_receive(:text).and_return("Message from div")
356
+ selenium_page_object.message.should == "Message from div"
357
+
358
+ end
359
+
360
+ it "should retrieve the div element from the page" do
361
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
362
+ element = selenium_page_object.message_div
363
+ element.should be_instance_of PageObject::Elements::Div
364
+
365
+ end
366
+ end
367
+ end
368
+
369
+ describe "table accessors" do
370
+ context "when called on a page object" do
371
+ it "should generate accessor methods" do
372
+ watir_page_object.should respond_to(:cart_table)
373
+ end
374
+ end
375
+
376
+ context "watir implementation" do
377
+ it "should retrieve the table element from the page" do
378
+ watir_browser.should_receive(:table).and_return(watir_browser)
379
+ element = watir_page_object.cart_table
380
+ element.should be_instance_of PageObject::Elements::Table
381
+ end
382
+ end
383
+
384
+ context "selenium implementation" do
385
+ it "should retrieve the table element from the page" do
386
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
387
+ element = selenium_page_object.cart_table
388
+ element.should be_instance_of(PageObject::Elements::Table)
389
+
390
+ end
391
+ end
392
+ end
393
+
394
+ describe "table cell accessors" do
395
+ context "when called on a page object" do
396
+ it "should generate accessor methods" do
397
+ watir_page_object.should respond_to(:total)
398
+ watir_page_object.should respond_to(:total_cell)
399
+ end
400
+ end
401
+
402
+ context "watir implementation" do
403
+ it "should retrieve the text for the cell" do
404
+ watir_browser.should_receive(:td).and_return(watir_browser)
405
+ watir_browser.should_receive(:text).and_return('10.00')
406
+ watir_page_object.total.should == '10.00'
407
+ end
408
+
409
+ it "should retrieve the cell element from the page" do
410
+ watir_browser.should_receive(:td).and_return(watir_browser)
411
+ element = watir_page_object.total_cell
412
+ element.should be_instance_of PageObject::Elements::TableCell
413
+ end
414
+ end
415
+
416
+ context "selenium implementation" do
417
+ it "should retrieve the text from the cell" do
418
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
419
+ selenium_browser.should_receive(:text).and_return('celldata')
420
+ selenium_page_object.total.should == 'celldata'
293
421
  end
294
422
  end
295
-
296
423
  end
297
424
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'page-object/elements'
3
+
4
+ describe PageObject::Elements::Div do
5
+ let(:div) { PageObject::Elements::Div }
6
+
7
+ describe "when mapping how to find an element" do
8
+ it "should map watir types to same" do
9
+ [:class, :id, :index, :xpath].each do |t|
10
+ identifier = div.watir_identifier_for t => 'value'
11
+ identifier.keys.first.should == t
12
+ end
13
+ end
14
+
15
+ it "should map selenium types to same" do
16
+ [:class, :id, :name, :xpath].each do |t|
17
+ key, value = div.selenium_identifier_for t => 'value'
18
+ key.should == t
19
+ end
20
+ end
21
+ end
22
+ end
@@ -28,6 +28,11 @@ describe PageObject::Elements::Element do
28
28
  watir_driver.should_receive(:exists?).and_return(false)
29
29
  watir_element.exists?.should == false
30
30
  end
31
+
32
+ it "should be able to return the text contained in the element" do
33
+ watir_driver.should_receive(:text).and_return("my text")
34
+ watir_element.text.should == "my text"
35
+ end
31
36
  end
32
37
 
33
38
  context "on a Selenium page-object" do
@@ -48,7 +53,11 @@ describe PageObject::Elements::Element do
48
53
  it "should know when it does not exist" do
49
54
  selenium_element = PageObject::Elements::Element.new(nil, :platform => :selenium)
50
55
  selenium_element.exists?.should == false
51
-
56
+ end
57
+
58
+ it "should be able to return the text contained in the element" do
59
+ selenium_driver.should_receive(:text).and_return("my text")
60
+ selenium_element.text.should == "my text"
52
61
  end
53
62
  end
54
63
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'page-object/elements'
3
+
4
+ describe PageObject::Elements::TableRow do
5
+ let(:table_cell) { double('table_cell') }
6
+ let(:table_row_driver) { double('table_row_driver') }
7
+
8
+ describe "interface" do
9
+ context "for selenium" do
10
+ it "should return a table cell when indexed" do
11
+ @sel_table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :selenium)
12
+ table_row_driver.should_receive(:find_element).with(:xpath, "./th|td[1]").and_return(table_cell)
13
+ @sel_table_row[0].should be_instance_of PageObject::Elements::TableCell
14
+ end
15
+ end
16
+
17
+ context "for watir" do
18
+ it "should return a table cell when indexed" do
19
+ @wat_table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :watir)
20
+ table_row_driver.should_receive(:[]).with(1).and_return(table_cell)
21
+ @wat_table_row[1].should be_instance_of PageObject::Elements::TableCell
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'page-object/elements'
3
+
4
+ describe PageObject::Elements::Table do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :xpath].each do |t|
8
+ identifier = PageObject::Elements::Table.watir_identifier_for t => 'value'
9
+ identifier.keys.first.should == t
10
+ end
11
+ end
12
+
13
+ it "should map selenium types to same" do
14
+ [:class, :id, :name, :xpath].each do |t|
15
+ key, value = PageObject::Elements::Table.selenium_identifier_for t => 'value'
16
+ key.should == t
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "interface" do
22
+ let(:table_element) { double('table_element') }
23
+
24
+ before(:each) do
25
+ table_element.stub(:[])
26
+ table_element.stub(:find_element)
27
+ end
28
+
29
+ context "for watir" do
30
+ it "should return a table row when indexed" do
31
+ wat_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
32
+ table_element.stub(:[]).with(1)
33
+ wat_table[1].should be_instance_of PageObject::Elements::TableRow
34
+ end
35
+ end
36
+
37
+ context "for selenium" do
38
+ it "should return a table row when indexed" do
39
+ sel_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
40
+ table_element.stub(:find_element).with(:xpath, ".//tr[2]")
41
+ sel_table[1].should be_instance_of PageObject::Elements::TableRow
42
+ end
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: page-object
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeff Morgan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-22 00:00:00 -04:00
13
+ date: 2011-05-30 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -79,13 +79,19 @@ extra_rdoc_files: []
79
79
 
80
80
  files:
81
81
  - .gitignore
82
+ - .rspec
83
+ - .rvmrc
84
+ - ChangeLog
82
85
  - Gemfile
83
86
  - LICENSE
84
87
  - README.md
85
88
  - Rakefile
86
89
  - cucumber.yml
90
+ - features/button.feature
87
91
  - features/check_box.feature
92
+ - features/div.feature
88
93
  - features/html/static_elements.html
94
+ - features/html/success.html
89
95
  - features/link.feature
90
96
  - features/page_level_actions.feature
91
97
  - features/radio_button.feature
@@ -94,33 +100,47 @@ files:
94
100
  - features/step_definitions/element_steps.rb
95
101
  - features/step_definitions/page_level_actions_steps.rb
96
102
  - features/step_definitions/page_traversal_steps.rb
103
+ - features/step_definitions/table_steps.rb
97
104
  - features/support/env.rb
98
105
  - features/support/page.rb
99
106
  - features/support/url_helper.rb
107
+ - features/table.feature
108
+ - features/table_cell.feature
100
109
  - features/text_field.feature
101
110
  - lib/page-object.rb
102
111
  - lib/page-object/accessors.rb
103
112
  - lib/page-object/elements.rb
104
113
  - lib/page-object/elements/button.rb
105
114
  - lib/page-object/elements/check_box.rb
115
+ - lib/page-object/elements/div.rb
106
116
  - lib/page-object/elements/element.rb
107
117
  - lib/page-object/elements/link.rb
108
118
  - lib/page-object/elements/radio_button.rb
109
119
  - lib/page-object/elements/select_list.rb
120
+ - lib/page-object/elements/table.rb
121
+ - lib/page-object/elements/table_cell.rb
122
+ - lib/page-object/elements/table_row.rb
110
123
  - lib/page-object/elements/text_field.rb
111
- - lib/page-object/selenium_element.rb
124
+ - lib/page-object/platforms/selenium_element.rb
125
+ - lib/page-object/platforms/selenium_table.rb
126
+ - lib/page-object/platforms/selenium_table_row.rb
127
+ - lib/page-object/platforms/watir_element.rb
128
+ - lib/page-object/platforms/watir_table.rb
129
+ - lib/page-object/platforms/watir_table_row.rb
112
130
  - lib/page-object/selenium_page_object.rb
113
131
  - lib/page-object/version.rb
114
- - lib/page-object/watir_element.rb
115
132
  - lib/page-object/watir_page_object.rb
116
133
  - page-object.gemspec
117
134
  - spec/page-object/accessors_spec.rb
118
135
  - spec/page-object/elements/button_spec.rb
119
136
  - spec/page-object/elements/check_box_spec.rb
137
+ - spec/page-object/elements/div_spec.rb
120
138
  - spec/page-object/elements/element_spec.rb
121
139
  - spec/page-object/elements/link_spec.rb
122
140
  - spec/page-object/elements/radio_button_spec.rb
123
141
  - spec/page-object/elements/select_list_spec.rb
142
+ - spec/page-object/elements/table_row_spec.rb
143
+ - spec/page-object/elements/table_spec.rb
124
144
  - spec/page-object/elements/text_field_spec.rb
125
145
  - spec/page-object/page-object_spec.rb
126
146
  - spec/spec_helper.rb
@@ -153,8 +173,11 @@ signing_key:
153
173
  specification_version: 3
154
174
  summary: Page Object DSL for browser testing
155
175
  test_files:
176
+ - features/button.feature
156
177
  - features/check_box.feature
178
+ - features/div.feature
157
179
  - features/html/static_elements.html
180
+ - features/html/success.html
158
181
  - features/link.feature
159
182
  - features/page_level_actions.feature
160
183
  - features/radio_button.feature
@@ -163,17 +186,23 @@ test_files:
163
186
  - features/step_definitions/element_steps.rb
164
187
  - features/step_definitions/page_level_actions_steps.rb
165
188
  - features/step_definitions/page_traversal_steps.rb
189
+ - features/step_definitions/table_steps.rb
166
190
  - features/support/env.rb
167
191
  - features/support/page.rb
168
192
  - features/support/url_helper.rb
193
+ - features/table.feature
194
+ - features/table_cell.feature
169
195
  - features/text_field.feature
170
196
  - spec/page-object/accessors_spec.rb
171
197
  - spec/page-object/elements/button_spec.rb
172
198
  - spec/page-object/elements/check_box_spec.rb
199
+ - spec/page-object/elements/div_spec.rb
173
200
  - spec/page-object/elements/element_spec.rb
174
201
  - spec/page-object/elements/link_spec.rb
175
202
  - spec/page-object/elements/radio_button_spec.rb
176
203
  - spec/page-object/elements/select_list_spec.rb
204
+ - spec/page-object/elements/table_row_spec.rb
205
+ - spec/page-object/elements/table_spec.rb
177
206
  - spec/page-object/elements/text_field_spec.rb
178
207
  - spec/page-object/page-object_spec.rb
179
208
  - spec/spec_helper.rb