page-object 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/ChangeLog +13 -1
  2. data/features/element.feature +10 -0
  3. data/features/headings.feature +54 -0
  4. data/features/html/nested_elements.html +6 -2
  5. data/features/html/static_elements.html +11 -26
  6. data/features/nested_elements.feature +14 -1
  7. data/features/step_definitions/element_steps.rb +4 -0
  8. data/features/step_definitions/headings_steps.rb +12 -0
  9. data/features/step_definitions/nested_elements_steps.rb +27 -0
  10. data/features/step_definitions/text_area_steps.rb +4 -0
  11. data/features/support/page.rb +24 -0
  12. data/features/text_area.feature +6 -0
  13. data/lib/page-object/accessors.rb +87 -0
  14. data/lib/page-object/element_locators.rb +45 -0
  15. data/lib/page-object/elements.rb +1 -0
  16. data/lib/page-object/elements/element.rb +1 -1
  17. data/lib/page-object/elements/heading.rb +7 -0
  18. data/lib/page-object/nested_elements.rb +12 -0
  19. data/lib/page-object/platforms/selenium_webdriver/element.rb +3 -12
  20. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +72 -0
  21. data/lib/page-object/platforms/watir_webdriver/element.rb +3 -0
  22. data/lib/page-object/platforms/watir_webdriver/page_object.rb +57 -0
  23. data/lib/page-object/platforms/watir_webdriver/text_area.rb +7 -0
  24. data/lib/page-object/version.rb +1 -1
  25. data/page-object.gemspec +1 -1
  26. data/spec/page-object/accessors_spec.rb +135 -0
  27. data/spec/page-object/element_locators_spec.rb +18 -0
  28. data/spec/page-object/elements/element_spec.rb +42 -0
  29. data/spec/page-object/elements/heading_spec.rb +22 -0
  30. data/spec/page-object/elements/nested_element_spec.rb +33 -3
  31. metadata +11 -6
  32. data/features/element_attributes.feature +0 -233
@@ -110,4 +110,22 @@ describe PageObject::ElementLocators do
110
110
  element = watir_page_object.ordered_list_element(:id => 'blah')
111
111
  element.should be_instance_of PageObject::Elements::OrderedList
112
112
  end
113
+
114
+ it "should find a h1 element" do
115
+ watir_browser.should_receive(:h1).with(:id => 'blah').and_return(watir_browser)
116
+ element = watir_page_object.h1_element(:id => 'blah')
117
+ element.should be_instance_of PageObject::Elements::Heading
118
+ end
119
+
120
+ it "should find a h2 element" do
121
+ watir_browser.should_receive(:h2).with(:id => 'blah').and_return(watir_browser)
122
+ element = watir_page_object.h2_element(:id => 'blah')
123
+ element.should be_instance_of PageObject::Elements::Heading
124
+ end
125
+
126
+ it "should find a h3 element" do
127
+ watir_browser.should_receive(:h3).with(:id => 'blah').and_return(watir_browser)
128
+ element = watir_page_object.h3_element(:id => 'blah')
129
+ element.should be_instance_of PageObject::Elements::Heading
130
+ end
113
131
  end
@@ -155,16 +155,34 @@ describe PageObject::Elements::Element do
155
155
  watir_driver.should_receive(:wait_until_present).with(10)
156
156
  watir_element.when_present(10)
157
157
  end
158
+
159
+ it "should return the element when it is present" do
160
+ watir_driver.should_receive(:wait_until_present).with(10)
161
+ element = watir_element.when_present(10)
162
+ element.should === watir_element
163
+ end
158
164
 
159
165
  it "should be able to block until it is visible" do
160
166
  Watir::Wait.should_receive(:until).with(10, "Element was not visible in 10 seconds")
161
167
  watir_element.when_visible(10)
162
168
  end
169
+
170
+ it "should return the element when it is visible" do
171
+ Watir::Wait.should_receive(:until).with(10, "Element was not visible in 10 seconds")
172
+ element = watir_element.when_visible(10)
173
+ element.should === watir_element
174
+ end
163
175
 
164
176
  it "should be able to block until it is not visible" do
165
177
  Watir::Wait.should_receive(:while).with(10, "Element still visible after 10 seconds")
166
178
  watir_element.when_not_visible(10)
167
179
  end
180
+
181
+ it "should return the element when it is not visible" do
182
+ Watir::Wait.should_receive(:while).with(10, "Element still visible after 10 seconds")
183
+ element = watir_element.when_not_visible(10)
184
+ element.should === watir_element
185
+ end
168
186
 
169
187
  it "should be able to block until a user define event fires true" do
170
188
  Watir::Wait.should_receive(:until).with(10, "Element blah")
@@ -252,6 +270,14 @@ describe PageObject::Elements::Element do
252
270
  wait.should_receive(:until)
253
271
  selenium_element.when_present(10)
254
272
  end
273
+
274
+ it "should return the element when it is present" do
275
+ wait = double('wait')
276
+ Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
277
+ wait.should_receive(:until)
278
+ element = selenium_element.when_present(10)
279
+ element.should === selenium_element
280
+ end
255
281
 
256
282
  it "should be able to block until it is visible" do
257
283
  wait = double('wait')
@@ -259,6 +285,14 @@ describe PageObject::Elements::Element do
259
285
  wait.should_receive(:until)
260
286
  selenium_element.when_visible(10)
261
287
  end
288
+
289
+ it "should return the element when it is visible" do
290
+ wait = double('wait')
291
+ Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
292
+ wait.should_receive(:until)
293
+ element = selenium_element.when_visible(10)
294
+ element.should === selenium_element
295
+ end
262
296
 
263
297
  it "should be able to block until it is not visible" do
264
298
  wait = double('wait')
@@ -267,6 +301,14 @@ describe PageObject::Elements::Element do
267
301
  selenium_element.when_not_visible(10)
268
302
  end
269
303
 
304
+ it "should return the element when it is not visible" do
305
+ wait = double('wait')
306
+ Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
307
+ wait.should_receive(:until)
308
+ element = selenium_element.when_not_visible(10)
309
+ element.should === selenium_element
310
+ end
311
+
270
312
  it "should be able to block until a user define event fires true" do
271
313
  wait = double('wait')
272
314
  Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'page-object/elements'
3
+
4
+ describe PageObject::Elements::Heading do
5
+ let(:heading) { PageObject::Elements::Heading }
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 = heading.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, :index, :name, :xpath].each do |t|
17
+ key, value = heading.selenium_identifier_for t => 'value'
18
+ key.should == t
19
+ end
20
+ end
21
+ end
22
+ end
@@ -80,20 +80,35 @@ describe "Element with nested elements" do
80
80
  watir_element.form_element
81
81
  end
82
82
 
83
- it "should find an ordered list" do
83
+ it "should find a nested ordered list" do
84
84
  watir_driver.should_receive(:ol).and_return(watir_driver)
85
85
  watir_element.ordered_list_element
86
86
  end
87
87
 
88
- it "should find an unordered list" do
88
+ it "should find a nested unordered list" do
89
89
  watir_driver.should_receive(:ul).and_return(watir_driver)
90
90
  watir_element.unordered_list_element
91
91
  end
92
92
 
93
- it "should find a list item" do
93
+ it "should find a nested list item" do
94
94
  watir_driver.should_receive(:li).and_return(watir_driver)
95
95
  watir_element.list_item_element
96
96
  end
97
+
98
+ it "should find a nested h1" do
99
+ watir_driver.should_receive(:h1).and_return(watir_driver)
100
+ watir_element.h1_element
101
+ end
102
+
103
+ it "should find a nested h2" do
104
+ watir_driver.should_receive(:h2).and_return(watir_driver)
105
+ watir_element.h2_element
106
+ end
107
+
108
+ it "should find a nested h3" do
109
+ watir_driver.should_receive(:h3).and_return(watir_driver)
110
+ watir_element.h3_element
111
+ end
97
112
  end
98
113
 
99
114
  context "in Selenium" do
@@ -181,5 +196,20 @@ describe "Element with nested elements" do
181
196
  selenium_driver.should_receive(:find_element).and_return(selenium_driver)
182
197
  selenium_element.list_item_element
183
198
  end
199
+
200
+ it "should find a nested h1" do
201
+ selenium_driver.should_receive(:find_element).and_return(selenium_driver)
202
+ selenium_element.h1_element
203
+ end
204
+
205
+ it "should find a nested h2" do
206
+ selenium_driver.should_receive(:find_element).and_return(selenium_driver)
207
+ selenium_element.h2_element
208
+ end
209
+
210
+ it "should find a nested h3" do
211
+ selenium_driver.should_receive(:find_element).and_return(selenium_driver)
212
+ selenium_element.h3_element
213
+ end
184
214
  end
185
215
  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.3.1
5
+ version: 0.3.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-09-08 00:00:00 Z
13
+ date: 2011-09-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: watir-webdriver
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.5.0
34
+ version: 2.6.0
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
@@ -92,9 +92,9 @@ files:
92
92
  - features/check_box.feature
93
93
  - features/div.feature
94
94
  - features/element.feature
95
- - features/element_attributes.feature
96
95
  - features/form.feature
97
96
  - features/frames.feature
97
+ - features/headings.feature
98
98
  - features/hidden_field.feature
99
99
  - features/html/frame_1.html
100
100
  - features/html/frame_2.html
@@ -129,6 +129,7 @@ files:
129
129
  - features/step_definitions/element_steps.rb
130
130
  - features/step_definitions/form_steps.rb
131
131
  - features/step_definitions/frames_steps.rb
132
+ - features/step_definitions/headings_steps.rb
132
133
  - features/step_definitions/hidden_field_steps.rb
133
134
  - features/step_definitions/image_steps.rb
134
135
  - features/step_definitions/link_steps.rb
@@ -164,6 +165,7 @@ files:
164
165
  - lib/page-object/elements/div.rb
165
166
  - lib/page-object/elements/element.rb
166
167
  - lib/page-object/elements/form.rb
168
+ - lib/page-object/elements/heading.rb
167
169
  - lib/page-object/elements/hidden_field.rb
168
170
  - lib/page-object/elements/image.rb
169
171
  - lib/page-object/elements/link.rb
@@ -222,6 +224,7 @@ files:
222
224
  - spec/page-object/elements/div_spec.rb
223
225
  - spec/page-object/elements/element_spec.rb
224
226
  - spec/page-object/elements/form_spec.rb
227
+ - spec/page-object/elements/heading_spec.rb
225
228
  - spec/page-object/elements/hidden_field_spec.rb
226
229
  - spec/page-object/elements/image_spec.rb
227
230
  - spec/page-object/elements/link_spec.rb
@@ -266,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
269
  requirements: []
267
270
 
268
271
  rubyforge_project: page-object
269
- rubygems_version: 1.8.8
272
+ rubygems_version: 1.8.10
270
273
  signing_key:
271
274
  specification_version: 3
272
275
  summary: Page Object DSL for browser testing
@@ -276,9 +279,9 @@ test_files:
276
279
  - features/check_box.feature
277
280
  - features/div.feature
278
281
  - features/element.feature
279
- - features/element_attributes.feature
280
282
  - features/form.feature
281
283
  - features/frames.feature
284
+ - features/headings.feature
282
285
  - features/hidden_field.feature
283
286
  - features/html/frame_1.html
284
287
  - features/html/frame_2.html
@@ -313,6 +316,7 @@ test_files:
313
316
  - features/step_definitions/element_steps.rb
314
317
  - features/step_definitions/form_steps.rb
315
318
  - features/step_definitions/frames_steps.rb
319
+ - features/step_definitions/headings_steps.rb
316
320
  - features/step_definitions/hidden_field_steps.rb
317
321
  - features/step_definitions/image_steps.rb
318
322
  - features/step_definitions/link_steps.rb
@@ -345,6 +349,7 @@ test_files:
345
349
  - spec/page-object/elements/div_spec.rb
346
350
  - spec/page-object/elements/element_spec.rb
347
351
  - spec/page-object/elements/form_spec.rb
352
+ - spec/page-object/elements/heading_spec.rb
348
353
  - spec/page-object/elements/hidden_field_spec.rb
349
354
  - spec/page-object/elements/image_spec.rb
350
355
  - spec/page-object/elements/link_spec.rb
@@ -1,233 +0,0 @@
1
- Feature: Attributes on Elements
2
-
3
- Background:
4
- Given I am on the static elements page
5
-
6
- Scenario: Link element methods
7
- When I retrieve a link element
8
- Then I should know it exists
9
- And I should know it is visible
10
- And I should know its' text is "Google Search"
11
- And I should know it is equal to itself
12
- And I should know its' tag name is "a"
13
- And I should know the attribute "readonly" is false
14
- And I should be able to click it
15
-
16
- @watir_only
17
- Scenario: Link element methods for watir
18
- When I retrieve a link element
19
- Then I should know its' value is ""
20
-
21
-
22
- Scenario: Button element methods
23
- When I retrieve a button element
24
- Then I should know it exists
25
- And I should know it is visible
26
- And I should know its' value is "Click Me"
27
- And I should know it is equal to itself
28
- And I should know its' tag name is "input"
29
- And I should know the attribute "readonly" is false
30
- And I should be able to click it
31
-
32
- @watir_only
33
- Scenario: Button element methods for watir
34
- When I retrieve a button element
35
- Then I should know its' text is "Click Me"
36
-
37
- Scenario: Check Box element methods
38
- When I retrieve a check box element
39
- Then I should know it exists
40
- And I should know it is visible
41
- And I should know its' text is ""
42
- And I should know its' value is "1"
43
- And I should know it is equal to itself
44
- And I should know its' tag name is "input"
45
- And I should know the attribute "readonly" is false
46
- And I should be able to click it
47
-
48
- Scenario: Div element methods
49
- When I retrieve the div element
50
- Then I should know it exists
51
- And I should know it is visible
52
- And I should know its' text is "page-object rocks!"
53
- And I should know it is equal to itself
54
- And I should know its' tag name is "div"
55
- And I should know the attribute "readonly" is false
56
- And I should be able to click it
57
-
58
- @watir_only
59
- Scenario: Div element methods for watir
60
- When I retrieve the div element
61
- Then I should know its' value is ""
62
-
63
- @selenium_only
64
- Scenario: Div element methods for selenium
65
- When I retrieve the div element
66
- Then I should know its' value is nil
67
-
68
- Scenario: Radio Button element methods
69
- When I retrieve a radio button
70
- Then I should know it exists
71
- And I should know it is visible
72
- And I should know its' text is ""
73
- And I should know its' value is "Milk"
74
- And I should know it is equal to itself
75
- And I should know its' tag name is "input"
76
- And I should know the attribute "readonly" is false
77
- And I should be able to click it
78
-
79
- Scenario: Select List element methods
80
- When I retrieve a select list
81
- Then I should know it exists
82
- And I should know it is visible
83
- And I should know its' text includes "Test 1"
84
- And I should know its' value is "option1"
85
- And I should know it is equal to itself
86
- And I should know its' tag name is "select"
87
- And I should know the attribute "readonly" is false
88
- And I should be able to click it
89
-
90
- Scenario: Table element methods
91
- When I retrieve a table element
92
- Then I should know it is visible
93
- And I should know its' text includes "Data1"
94
- And I should know it is equal to itself
95
- And I should know its' tag name is "table"
96
- And I should know the attribute "readonly" is false
97
- And I should be able to click it
98
-
99
- @watir_only
100
- Scenario: Table element methods in watir
101
- When I retrieve a table element
102
- Then I should know it exists
103
- And I should know its' value is ""
104
-
105
- @selenium_only
106
- Scenario: Table element methods in selenium
107
- When I retrieve a table element
108
- Then I should know its' value is nil
109
-
110
- Scenario: Table Cell element methods
111
- When I retrieve table cell
112
- Then I should know it exists
113
- And I should know it is visible
114
- And I should know its' text includes "Data4"
115
- And I should know it is equal to itself
116
- And I should know its' tag name is "td"
117
- And I should know the attribute "readonly" is false
118
- And I should be able to click it
119
-
120
- @watir_only
121
- Scenario: Table Cell element methods in watir
122
- When I retrieve table cell
123
- Then I should know its' value is ""
124
-
125
- @selenium_only
126
- Scenario: Table Cell element methods in selenium
127
- When I retrieve table cell
128
- Then I should know its' value is nil
129
-
130
- Scenario: Text Field element methods
131
- When I retrieve a text field
132
- Then I should know it exists
133
- And I should know it is visible
134
- And I should know its' text includes ""
135
- And I should know its' value is ""
136
- And I should know it is equal to itself
137
- And I should know its' tag name is "input"
138
- And I should know the attribute "readonly" is false
139
- And I should be able to click it
140
-
141
- Scenario: Text Area element methods
142
- When I retrieve the text area
143
- Then I should know it exists
144
- And I should know it is visible
145
- And I should know its' text includes ""
146
- And I should know its' value is ""
147
- And I should know it is equal to itself
148
- And I should know its' tag name is "textarea"
149
- And I should know the attribute "readonly" is false
150
- And I should be able to click it
151
-
152
- Scenario: Image element methods
153
- When I get the image element
154
- Then I should know it exists
155
- And I should know it is visible
156
- And I should know its' text includes ""
157
- And I should know it is equal to itself
158
- And I should know its' tag name is "img"
159
- And I should know the attribute "readonly" is false
160
- And I should be able to click it
161
-
162
- @watir_only
163
- Scenario: Image element methods in watir
164
- When I get the image element
165
- Then I should know its' value is ""
166
-
167
- @selenium_only
168
- Scenario: Image element methods in selenium
169
- When I get the image element
170
- Then I should know its' value is nil
171
-
172
- Scenario: Hidden Field element methods
173
- When I retrieve the hidden field element
174
- Then I should know it exists
175
- And I should know it is not visible
176
- And I should know its' text includes ""
177
- And I should know its' value is "12345"
178
- And I should know it is equal to itself
179
- And I should know its' tag name is "input"
180
- And I should know the attribute "readonly" is false
181
-
182
- Scenario: Form element methods
183
- When I locate the form
184
- Then I should know it exists
185
- And I should know it is visible
186
- And I should know its' text includes ""
187
- And I should know it is equal to itself
188
- And I should know its' tag name is "form"
189
- And I should know the attribute "readonly" is false
190
-
191
- @watir_only
192
- Scenario: Form element methods in watir
193
- When I locate the form
194
- Then I should know its' value is ""
195
-
196
- @selenium_only
197
- Scenario: Form element methods in selenium
198
- When I locate the form
199
- Then I should know its' value is nil
200
-
201
- Scenario: List item element methods
202
- When I retrieve a list item element
203
- Then I should know it exists
204
- And I should know it is visible
205
- And I should know its' text is "Item One"
206
- And I should know it is equal to itself
207
- And I should know its' tag name is "li"
208
- And I should know the attribute "readonly" is false
209
- And I should be able to click it
210
-
211
- Scenario: Unordered list element methods
212
- When I retrieve an unordered list element
213
- Then I should know it exists
214
- And I should know it is visible
215
- And I should know its' text includes "Item One"
216
- And I should know its' text includes "Item Two"
217
- And I should know its' text includes "Item Three"
218
- And I should know it is equal to itself
219
- And I should know its' tag name is "ul"
220
- And I should know the attribute "readonly" is false
221
- And I should be able to click it
222
-
223
- Scenario: Ordered list element methods
224
- When I retrieve an ordered list element
225
- Then I should know it exists
226
- And I should know it is visible
227
- And I should know its' text includes "Number One"
228
- And I should know its' text includes "Number Two"
229
- And I should know its' text includes "Number Three"
230
- And I should know it is equal to itself
231
- And I should know its' tag name is "ol"
232
- And I should know the attribute "readonly" is false
233
- And I should be able to click it