page-object 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/ChangeLog +20 -2
  2. data/features/div.feature +1 -1
  3. data/features/element.feature +160 -0
  4. data/features/html/images/circle.png +0 -0
  5. data/features/html/static_elements.html +8 -0
  6. data/features/image.feature +32 -0
  7. data/features/span.feature +37 -0
  8. data/features/step_definitions/accessor_steps.rb +29 -3
  9. data/features/step_definitions/element_steps.rb +33 -0
  10. data/features/support/page.rb +13 -0
  11. data/lib/page-object/accessors.rb +32 -2
  12. data/lib/page-object/elements.rb +2 -0
  13. data/lib/page-object/elements/button.rb +13 -0
  14. data/lib/page-object/elements/element.rb +1 -0
  15. data/lib/page-object/elements/image.rb +26 -0
  16. data/lib/page-object/elements/link.rb +11 -0
  17. data/lib/page-object/elements/span.rb +12 -0
  18. data/lib/page-object/platforms/selenium_button.rb +13 -0
  19. data/lib/page-object/platforms/selenium_element.rb +63 -1
  20. data/lib/page-object/platforms/selenium_image.rb +22 -0
  21. data/lib/page-object/platforms/selenium_link.rb +13 -0
  22. data/lib/page-object/platforms/selenium_table.rb +1 -1
  23. data/lib/page-object/platforms/watir_element.rb +63 -1
  24. data/lib/page-object/platforms/watir_image.rb +20 -0
  25. data/lib/page-object/selenium_page_object.rb +29 -0
  26. data/lib/page-object/version.rb +1 -1
  27. data/lib/page-object/watir_page_object.rb +29 -0
  28. data/page-object.gemspec +2 -2
  29. data/spec/page-object/accessors_spec.rb +64 -0
  30. data/spec/page-object/elements/button_spec.rb +11 -0
  31. data/spec/page-object/elements/element_spec.rb +50 -0
  32. data/spec/page-object/elements/image_spec.rb +62 -0
  33. data/spec/page-object/elements/link_spec.rb +11 -0
  34. data/spec/page-object/elements/span_spec.rb +22 -0
  35. metadata +22 -4
@@ -12,6 +12,8 @@ class TestPageObject
12
12
  div(:message, :id => 'message_id')
13
13
  table(:cart, :id => 'cart_id')
14
14
  cell(:total, :id => 'total')
15
+ span(:alert, :id => 'alert_id')
16
+ image(:logo, :id => 'logo')
15
17
  end
16
18
 
17
19
  describe PageObject::Accessors do
@@ -366,6 +368,44 @@ describe PageObject::Accessors do
366
368
  end
367
369
  end
368
370
 
371
+ describe "span accessors" do
372
+ context "when called on a page object" do
373
+ it "should generate accessor methods" do
374
+ watir_page_object.should respond_to(:alert)
375
+ watir_page_object.should respond_to(:alert_span)
376
+ end
377
+ end
378
+
379
+ context "watir implementation" do
380
+ it "should retrieve the text from a span" do
381
+ watir_browser.should_receive(:span).and_return(watir_browser)
382
+ watir_browser.should_receive(:text).and_return("Alert")
383
+ watir_page_object.alert.should == "Alert"
384
+ end
385
+
386
+ it "should retrieve the span element from the page" do
387
+ watir_browser.should_receive(:span).and_return(watir_browser)
388
+ element = watir_page_object.alert_span
389
+ element.should be_instance_of PageObject::Elements::Span
390
+ end
391
+ end
392
+
393
+ context "selenium implementation" do
394
+ it "should retrieve the text from a span" do
395
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
396
+ selenium_browser.should_receive(:text).and_return("Alert")
397
+ selenium_page_object.alert.should == "Alert"
398
+ end
399
+
400
+ it "should retrieve the span element from the page" do
401
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
402
+ element = selenium_page_object.alert_span
403
+ element.should be_instance_of PageObject::Elements::Span
404
+
405
+ end
406
+ end
407
+ end
408
+
369
409
  describe "table accessors" do
370
410
  context "when called on a page object" do
371
411
  it "should generate accessor methods" do
@@ -421,4 +461,28 @@ describe PageObject::Accessors do
421
461
  end
422
462
  end
423
463
  end
464
+
465
+ describe "image accessors" do
466
+ context "when called on a page object" do
467
+ it "should generate accessor methods" do
468
+ watir_page_object.should respond_to(:logo_image)
469
+ end
470
+ end
471
+
472
+ context "watir implementation" do
473
+ it "should retrieve the image element from the page" do
474
+ watir_browser.should_receive(:image).and_return(watir_browser)
475
+ element = watir_page_object.logo_image
476
+ element.should be_instance_of PageObject::Elements::Image
477
+ end
478
+ end
479
+
480
+ context "selenium implementation" do
481
+ it "should retrieve the image element from the page" do
482
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
483
+ element = selenium_page_object.logo_image
484
+ element.should be_instance_of PageObject::Elements::Image
485
+ end
486
+ end
487
+ end
424
488
  end
@@ -20,4 +20,15 @@ describe PageObject::Elements::Button do
20
20
  end
21
21
  end
22
22
 
23
+ describe "interface" do
24
+ let(:button_element) { double('button_element') }
25
+
26
+ context "for selenium" do
27
+ it "should return error when asked for its' text" do
28
+ button = PageObject::Elements::Button.new(button_element, :platform => :selenium)
29
+ lambda {button.text}.should raise_error
30
+ end
31
+ end
32
+ end
33
+
23
34
  end
@@ -33,6 +33,31 @@ describe PageObject::Elements::Element do
33
33
  watir_driver.should_receive(:text).and_return("my text")
34
34
  watir_element.text.should == "my text"
35
35
  end
36
+
37
+ it "should know when it is equal to another" do
38
+ watir_driver.should_receive(:==).and_return(true)
39
+ watir_element.should == watir_element
40
+ end
41
+
42
+ it "should return its tag name" do
43
+ watir_driver.should_receive(:tag_name).and_return("h1")
44
+ watir_element.tag_name.should == "h1"
45
+ end
46
+
47
+ it "should know its value" do
48
+ watir_driver.should_receive(:value).and_return("value")
49
+ watir_element.value.should == "value"
50
+ end
51
+
52
+ it "should know how to retrieve the value of an attribute" do
53
+ watir_driver.should_receive(:attribute_value).and_return(true)
54
+ watir_element.attribute("readonly").should be_true
55
+ end
56
+
57
+ it "should be clickable" do
58
+ watir_driver.should_receive(:click)
59
+ watir_element.click
60
+ end
36
61
  end
37
62
 
38
63
  context "on a Selenium page-object" do
@@ -59,5 +84,30 @@ describe PageObject::Elements::Element do
59
84
  selenium_driver.should_receive(:text).and_return("my text")
60
85
  selenium_element.text.should == "my text"
61
86
  end
87
+
88
+ it "should know when it is equal to another" do
89
+ selenium_driver.should_receive(:==).and_return(true)
90
+ selenium_element.should == selenium_element
91
+ end
92
+
93
+ it "should return its tag name" do
94
+ selenium_driver.should_receive(:tag_name).and_return("h1")
95
+ selenium_element.tag_name.should == "h1"
96
+ end
97
+
98
+ it "should know its value" do
99
+ selenium_driver.should_receive(:attribute).with('value').and_return("value")
100
+ selenium_element.value.should == "value"
101
+ end
102
+
103
+ it "should know how to retrieve the value of an attribute" do
104
+ selenium_driver.should_receive(:attribute).and_return(true)
105
+ selenium_element.attribute('readonly').should be_true
106
+ end
107
+
108
+ it "should be clickable" do
109
+ selenium_driver.should_receive(:click)
110
+ selenium_element.click
111
+ end
62
112
  end
63
113
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'page-object/elements'
3
+
4
+ describe PageObject::Elements::Image do
5
+ let(:image) { PageObject::Elements::Image }
6
+
7
+ describe "when mapping how to find an element" do
8
+ it "should map watir types to same" do
9
+ [:class, :id, :index, :name, :xpath].each do |t|
10
+ identifier = image.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 = image.selenium_identifier_for t => 'value'
18
+ key.should == t
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "interface" do
24
+ let(:image_element) { double('image_element') }
25
+
26
+ before(:each) do
27
+ image_element.stub(:size).and_return(image_element)
28
+ end
29
+
30
+ context "for watir" do
31
+ it "should know the images width" do
32
+ image = PageObject::Elements::Image.new(image_element, :platform => :watir)
33
+ image_element.should_receive(:width).and_return(100)
34
+ image.width.should == 100
35
+ end
36
+
37
+ it "should know the images height" do
38
+ image = PageObject::Elements::Image.new(image_element, :platform => :watir)
39
+ image_element.should_receive(:height).and_return(120)
40
+ image.height.should == 120
41
+ end
42
+ end
43
+
44
+ context "for selenium" do
45
+ it "should know the images width" do
46
+ dim = double('dimension')
47
+ image = PageObject::Elements::Image.new(image_element, :platform => :selenium)
48
+ image_element.should_receive(:size).and_return(dim)
49
+ dim.should_receive(:width).and_return(100)
50
+ image.width.should == 100
51
+ end
52
+
53
+ it "should know the images height" do
54
+ dim = double('dimension')
55
+ image = PageObject::Elements::Image.new(image_element, :platform => :selenium)
56
+ image_element.should_receive(:size).and_return(dim)
57
+ dim.should_receive(:height).and_return(120)
58
+ image.height.should == 120
59
+ end
60
+ end
61
+ end
62
+ end
@@ -31,4 +31,15 @@ describe PageObject::Elements::Link do
31
31
  key.should == :link_text
32
32
  end
33
33
  end
34
+
35
+ describe "interface" do
36
+ let(:link_element) { double('link_element') }
37
+
38
+ context "for selenium" do
39
+ it "should return error when asked for its' value" do
40
+ link = PageObject::Elements::Link.new(link_element, :platform => :selenium)
41
+ lambda {link.value}.should raise_error
42
+ end
43
+ end
44
+ end
34
45
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'page-object/elements'
3
+
4
+ describe PageObject::Elements::Span do
5
+ let(:span) { PageObject::Elements::Span }
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 = span.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 = span.selenium_identifier_for t => 'value'
18
+ key.should == t
19
+ end
20
+ end
21
+ end
22
+ 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.2
5
+ version: 0.0.3
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-30 00:00:00 -04:00
13
+ date: 2011-06-02 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 0.2.3
24
+ version: 0.2.4
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 0.2.0
35
+ version: 0.2.1
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -90,12 +90,16 @@ files:
90
90
  - features/button.feature
91
91
  - features/check_box.feature
92
92
  - features/div.feature
93
+ - features/element.feature
94
+ - features/html/images/circle.png
93
95
  - features/html/static_elements.html
94
96
  - features/html/success.html
97
+ - features/image.feature
95
98
  - features/link.feature
96
99
  - features/page_level_actions.feature
97
100
  - features/radio_button.feature
98
101
  - features/select_list.feature
102
+ - features/span.feature
99
103
  - features/step_definitions/accessor_steps.rb
100
104
  - features/step_definitions/element_steps.rb
101
105
  - features/step_definitions/page_level_actions_steps.rb
@@ -114,17 +118,23 @@ files:
114
118
  - lib/page-object/elements/check_box.rb
115
119
  - lib/page-object/elements/div.rb
116
120
  - lib/page-object/elements/element.rb
121
+ - lib/page-object/elements/image.rb
117
122
  - lib/page-object/elements/link.rb
118
123
  - lib/page-object/elements/radio_button.rb
119
124
  - lib/page-object/elements/select_list.rb
125
+ - lib/page-object/elements/span.rb
120
126
  - lib/page-object/elements/table.rb
121
127
  - lib/page-object/elements/table_cell.rb
122
128
  - lib/page-object/elements/table_row.rb
123
129
  - lib/page-object/elements/text_field.rb
130
+ - lib/page-object/platforms/selenium_button.rb
124
131
  - lib/page-object/platforms/selenium_element.rb
132
+ - lib/page-object/platforms/selenium_image.rb
133
+ - lib/page-object/platforms/selenium_link.rb
125
134
  - lib/page-object/platforms/selenium_table.rb
126
135
  - lib/page-object/platforms/selenium_table_row.rb
127
136
  - lib/page-object/platforms/watir_element.rb
137
+ - lib/page-object/platforms/watir_image.rb
128
138
  - lib/page-object/platforms/watir_table.rb
129
139
  - lib/page-object/platforms/watir_table_row.rb
130
140
  - lib/page-object/selenium_page_object.rb
@@ -136,9 +146,11 @@ files:
136
146
  - spec/page-object/elements/check_box_spec.rb
137
147
  - spec/page-object/elements/div_spec.rb
138
148
  - spec/page-object/elements/element_spec.rb
149
+ - spec/page-object/elements/image_spec.rb
139
150
  - spec/page-object/elements/link_spec.rb
140
151
  - spec/page-object/elements/radio_button_spec.rb
141
152
  - spec/page-object/elements/select_list_spec.rb
153
+ - spec/page-object/elements/span_spec.rb
142
154
  - spec/page-object/elements/table_row_spec.rb
143
155
  - spec/page-object/elements/table_spec.rb
144
156
  - spec/page-object/elements/text_field_spec.rb
@@ -176,12 +188,16 @@ test_files:
176
188
  - features/button.feature
177
189
  - features/check_box.feature
178
190
  - features/div.feature
191
+ - features/element.feature
192
+ - features/html/images/circle.png
179
193
  - features/html/static_elements.html
180
194
  - features/html/success.html
195
+ - features/image.feature
181
196
  - features/link.feature
182
197
  - features/page_level_actions.feature
183
198
  - features/radio_button.feature
184
199
  - features/select_list.feature
200
+ - features/span.feature
185
201
  - features/step_definitions/accessor_steps.rb
186
202
  - features/step_definitions/element_steps.rb
187
203
  - features/step_definitions/page_level_actions_steps.rb
@@ -198,9 +214,11 @@ test_files:
198
214
  - spec/page-object/elements/check_box_spec.rb
199
215
  - spec/page-object/elements/div_spec.rb
200
216
  - spec/page-object/elements/element_spec.rb
217
+ - spec/page-object/elements/image_spec.rb
201
218
  - spec/page-object/elements/link_spec.rb
202
219
  - spec/page-object/elements/radio_button_spec.rb
203
220
  - spec/page-object/elements/select_list_spec.rb
221
+ - spec/page-object/elements/span_spec.rb
204
222
  - spec/page-object/elements/table_row_spec.rb
205
223
  - spec/page-object/elements/table_spec.rb
206
224
  - spec/page-object/elements/text_field_spec.rb