page-object 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/ChangeLog +10 -1
  2. data/Gemfile +3 -0
  3. data/README.md +2 -2
  4. data/cucumber.yml +2 -0
  5. data/features/element.feature +81 -8
  6. data/features/form.feature +28 -0
  7. data/features/hidden_field.feature +32 -0
  8. data/features/html/static_elements.html +26 -0
  9. data/features/list_item.feature +36 -0
  10. data/features/ordered_list.feature +39 -0
  11. data/features/step_definitions/accessor_steps.rb +71 -0
  12. data/features/step_definitions/element_steps.rb +23 -0
  13. data/features/support/page.rb +43 -0
  14. data/features/text_area.feature +32 -0
  15. data/features/text_field.feature +1 -2
  16. data/features/unordered_list.feature +39 -0
  17. data/lib/page-object.rb +48 -3
  18. data/lib/page-object/accessors.rb +282 -111
  19. data/lib/page-object/elements.rb +6 -0
  20. data/lib/page-object/elements/element.rb +5 -1
  21. data/lib/page-object/elements/form.rb +25 -0
  22. data/lib/page-object/elements/hidden_field.rb +28 -0
  23. data/lib/page-object/elements/list_item.rb +7 -0
  24. data/lib/page-object/elements/ordered_list.rb +31 -0
  25. data/lib/page-object/elements/text_area.rb +24 -0
  26. data/lib/page-object/elements/text_field.rb +1 -1
  27. data/lib/page-object/elements/unordered_list.rb +31 -0
  28. data/lib/page-object/platforms/selenium_button.rb +1 -1
  29. data/lib/page-object/platforms/selenium_element.rb +3 -0
  30. data/lib/page-object/platforms/selenium_form.rb +14 -0
  31. data/lib/page-object/platforms/selenium_image.rb +6 -2
  32. data/lib/page-object/platforms/selenium_ordered_list.rb +18 -0
  33. data/lib/page-object/platforms/selenium_unordered_list.rb +18 -0
  34. data/lib/page-object/platforms/watir_element.rb +3 -0
  35. data/lib/page-object/platforms/watir_form.rb +14 -0
  36. data/lib/page-object/platforms/watir_ordered_list.rb +18 -0
  37. data/lib/page-object/platforms/watir_unordered_list.rb +18 -0
  38. data/lib/page-object/selenium_page_object.rb +101 -0
  39. data/lib/page-object/version.rb +2 -1
  40. data/lib/page-object/watir_page_object.rb +103 -2
  41. data/spec/page-object/accessors_spec.rb +203 -2
  42. data/spec/page-object/elements/form_spec.rb +24 -0
  43. data/spec/page-object/elements/hidden_field_spec.rb +32 -0
  44. data/spec/page-object/elements/list_item_spec.rb +22 -0
  45. data/spec/page-object/elements/ordered_list_spec.rb +43 -0
  46. data/spec/page-object/elements/text_area_spec.rb +32 -0
  47. data/spec/page-object/elements/text_field_spec.rb +1 -1
  48. data/spec/page-object/elements/unordered_list_spec.rb +43 -0
  49. metadata +39 -5
data/ChangeLog CHANGED
@@ -1,4 +1,13 @@
1
- == Version 0.0.3 / 2011-06-02
1
+ === Version 0.0.4 / 2011-06-13
2
+ * Enhancements
3
+ * Added support for the following elements
4
+ * hidden field
5
+ * form
6
+ * list item
7
+ * unordered list
8
+ * ordered list
9
+
10
+ === Version 0.0.3 / 2011-06-02
2
11
  * Enhancements
3
12
  * Added support for the following elements
4
13
  * span
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ # adding rake so travis-ci will build properly
4
+ gem 'rake'
5
+
3
6
  gemspec
data/README.md CHANGED
@@ -16,7 +16,7 @@ You define a new page object by including the PageObject module:
16
16
  When you include this module numerous methods are added to your class that allow you to easily define your page. For the login page you might add the following:
17
17
 
18
18
  class LoginPage
19
- include Page Object
19
+ include PageObject
20
20
 
21
21
  text_field(:username, :id => 'username')
22
22
  text_field(:password, :id => 'password')
@@ -32,7 +32,7 @@ Calling the _text_field_ and _button_ methods adds several methods to our page o
32
32
  Another approach might be to create higher level methods on our page object that hide the implementation details even further. Our page object might look like this:
33
33
 
34
34
  class LoginPage
35
- include Page Object
35
+ include PageObject
36
36
 
37
37
  text_field(:username, :id => 'username')
38
38
  text_field(:password, :id => 'password')
@@ -1,5 +1,7 @@
1
1
  default: DRIVER=WATIR --no-source --color --format pretty --tags ~@selenium_only
2
2
  watir: DRIVER=WATIR --no-source --color --format pretty --tags ~@selenium_only
3
3
  selenium: DRIVER=SELENIUM --no-source --color --format pretty --tags ~@watir_only
4
+ watir_focus: DRIVER=WATIR --no-source --color --format pretty --tags @focus
5
+ selenium_focus: DRIVER=SELENIUM --no-source --color --format pretty --tags @focus
4
6
  autotest: DRIVER=WATIR --no-source --color --format pretty --tags ~@selenium_only
5
7
 
@@ -138,6 +138,17 @@ Feature: Elements
138
138
  And I should know the attribute "readonly" is false
139
139
  And I should be able to click it
140
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
+
141
152
  Scenario: Image element methods
142
153
  When I get the image element
143
154
  Then I should know it exists
@@ -148,13 +159,75 @@ Feature: Elements
148
159
  And I should know the attribute "readonly" is false
149
160
  And I should be able to click it
150
161
 
151
- @watir_only
152
- Scenario: Image element methods in watir
153
- When I get the image element
154
- Then I should know its' value is ""
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 ""
155
166
 
156
- @selenium_only
157
- Scenario: Image element methods in selenium
158
- When I get the image element
159
- Then I should know its' value is nil
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
160
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
@@ -0,0 +1,28 @@
1
+ Feature: Form
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Submitting a form
7
+ When I locate the form by "id"
8
+ Then I should be able to submit the form
9
+
10
+ Scenario Outline: Locating a form on the page
11
+ When I locate the form by "<search_by>"
12
+ Then I should be able to submit the form
13
+
14
+ Scenarios:
15
+ | search_by |
16
+ | id |
17
+ | class |
18
+ | xpath |
19
+
20
+ @watir_only
21
+ Scenario Outline: Locating a form on the page watir only
22
+ When I locate the form by "<search_by>"
23
+ Then I should be able to submit the form
24
+
25
+ Scenarios:
26
+ | search_by |
27
+ | index |
28
+
@@ -0,0 +1,32 @@
1
+ Feature: Hidden Fields
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Setting and getting a value from a hidden field
7
+ When I retrieve the hidden field element
8
+ Then I should see the hidden field contains "12345"
9
+
10
+ Scenario Outline: Locating hidden fields on the Page
11
+ When I search for the hidden field by "<search_by>"
12
+ Then hidden field element should contains "12345"
13
+
14
+ Scenarios:
15
+ | search_by |
16
+ | id |
17
+ | class |
18
+ | name |
19
+ | xpath |
20
+ | css |
21
+ | tag_name |
22
+
23
+ @watir_only
24
+ Scenario Outline: Locating hidden fields on Watir only
25
+ When I search for the hidden field by "<search_by>"
26
+ Then hidden field element should contains "12345"
27
+
28
+ Scenarios:
29
+ | search_by |
30
+ | index |
31
+ | text |
32
+
@@ -10,6 +10,13 @@
10
10
  <input id="text_field_id" name="text_field_name" class="text_field_class"
11
11
  size="40" type="text" />
12
12
 
13
+ <h3>Hidden Field</h3>
14
+ <input id="hidden_field_id" name="hidden_field_name" class="hidden_field_class"
15
+ size="40" type="hidden" value="12345" />
16
+
17
+ <h3>Text Area</h3>
18
+ <textarea rows="2" cols="20" id="text_area_id" class="text_area_class" name="text_area_name"></textarea>
19
+
13
20
  <h3>Select List</h3>
14
21
  <select name="sel_list_name" id="sel_list_id", class="sel_list_class">
15
22
  <option value="option1">Test 1</option>
@@ -54,6 +61,25 @@
54
61
 
55
62
  <h3>Image</h3>
56
63
  <img src="images/circle.png" id="image_id" name="image_name" class="image_class">
64
+
65
+ <h3>Form</h3>
66
+ <form id="form_id" class="form_class" name="form_name" action="/">
67
+ </form>
68
+
69
+ <h3>Unordered List</h3>
70
+ <ul id="ul_id" name="ul_name" class="ul_class">
71
+ <li id="li_id" name="li_name" class="li_class">Item One</li>
72
+ <li>Item Two</li>
73
+ <li>Item Three</li>
74
+ </ul>
75
+
76
+ <h3>Ordered List</h3>
77
+ <ol id="ol_id" name="ol_name" class="ol_class">
78
+ <li>Number One</li>
79
+ <li>Number Two</li>
80
+ <li>Number Three</li>
81
+ </ol>
82
+
57
83
  </body>
58
84
  </html>
59
85
 
@@ -0,0 +1,36 @@
1
+ Feature: List item
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Getting the text from a list item
7
+ When I get the text from the list item
8
+ Then the text should be "Item One"
9
+
10
+ Scenario Outline: Locating list items on the page
11
+ When I search for the list item by "<search_by>"
12
+ Then the text should be "Item One"
13
+
14
+ Scenarios:
15
+ | search_by |
16
+ | id |
17
+ | class |
18
+ | xpath |
19
+
20
+ @watir_only
21
+ Scenario Outline: Locating list items on Watir only
22
+ When I search for the list item by "<search_by>"
23
+ Then the text should be "Item One"
24
+
25
+ Scenarios:
26
+ | search_by |
27
+ | index |
28
+
29
+ @selenium_only
30
+ Scenario Outline: Locating list items on Watir only
31
+ When I search for the list item by "<search_by>"
32
+ Then the text should be "Item One"
33
+
34
+ Scenarios:
35
+ | search_by |
36
+ | name |
@@ -0,0 +1,39 @@
1
+ Feature: Ordered list
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Getting the first element from the ordered list
7
+ When I get the first item from the ordered list
8
+ Then the list item's text should be "Number One"
9
+
10
+ Scenario Outline: Locating ordered lists on the page
11
+ When I search for the ordered list by "<search_by>"
12
+ And I get the first item from the list
13
+ Then the list item's text should be "Number One"
14
+
15
+ Scenarios:
16
+ | search_by |
17
+ | id |
18
+ | class |
19
+ | xpath |
20
+
21
+ @watir_only
22
+ Scenario Outline: Locating ordered lists in Watir only
23
+ When I search for the ordered list by "<search_by>"
24
+ And I get the first item from the list
25
+ Then the list item's text should be "Number One"
26
+
27
+ Scenarios:
28
+ | search_by |
29
+ | index |
30
+
31
+ @selenium_only
32
+ Scenario Outline: Locating ordered lists in Selenium only
33
+ When I search for the ordered list by "<search_by>"
34
+ And I get the first item from the list
35
+ Then the list item's text should be "Number One"
36
+
37
+ Scenarios:
38
+ | search_by |
39
+ | name |
@@ -14,6 +14,22 @@ Then /^I should be able to type "([^\"]*)" into the field$/ do |value|
14
14
  @page.send "text_field_#{@how}=".to_sym, value
15
15
  end
16
16
 
17
+ When /^I type "([^"]*)" into the text area$/ do |text|
18
+ @page.text_area_id = text
19
+ end
20
+
21
+ Then /^the text area should contain "([^"]*)"$/ do |expected_text|
22
+ @page.text_area_id.should == expected_text
23
+ end
24
+
25
+ When /^I search for the text area by "([^"]*)"$/ do |how|
26
+ @how = how
27
+ end
28
+
29
+ Then /^I should be able to type "([^"]*)" into the area$/ do |value|
30
+ @page.send "text_area_#{@how}=".to_sym, value
31
+ end
32
+
17
33
  When /^I select the link labeled "([^\"]*)"$/ do |text|
18
34
  @page.google_search_id
19
35
  end
@@ -149,3 +165,58 @@ When /^I get the image element by "([^"]*)"$/ do |how|
149
165
  @element = @page.send "image_#{how}_image"
150
166
  end
151
167
 
168
+ When /^I retrieve the hidden field element$/ do
169
+ @element = @page.hidden_field_id_hidden_field
170
+ end
171
+
172
+ Then /^I should see the hidden field contains "([^"]*)"$/ do |text|
173
+ @page.hidden_field_id.should == text
174
+ end
175
+
176
+ When /^I search for the hidden field by "([^"]*)"$/ do |how|
177
+ @element = @page.send "hidden_field_#{how}_hidden_field"
178
+ end
179
+
180
+ Then /^hidden field element should contains "([^"]*)"$/ do |text|
181
+ @element.value.should == text
182
+ end
183
+
184
+ Then /^I should be able to submit the form$/ do
185
+ @element.submit
186
+ end
187
+
188
+ When /^I locate the form by "([^"]*)"$/ do |how|
189
+ @element = @page.send "form_#{how}_form"
190
+ end
191
+
192
+ When /^I get the text from the list item$/ do
193
+ @text = @page.li_id
194
+ end
195
+
196
+ When /^I search for the list item by "([^"]*)"$/ do |how|
197
+ @text = @page.send "li_#{how}"
198
+ end
199
+
200
+ When /^I get the first item from the unordered list$/ do
201
+ @element = @page.ul_id_unordered_list[0]
202
+ end
203
+
204
+ Then /^the list item's text should be "([^"]*)"$/ do |expected_text|
205
+ @element.text.should == expected_text
206
+ end
207
+
208
+ When /^I search for the unordered list by "([^"]*)"$/ do |how|
209
+ @list = @page.send "ul_#{how}_unordered_list"
210
+ end
211
+
212
+ When /^I get the first item from the list$/ do
213
+ @element = @list[0]
214
+ end
215
+
216
+ When /^I get the first item from the ordered list$/ do
217
+ @element = @page.ol_id_ordered_list[0]
218
+ end
219
+
220
+ When /^I search for the ordered list by "([^"]*)"$/ do |how|
221
+ @list = @page.send "ol_#{how}_ordered_list"
222
+ end
@@ -18,6 +18,10 @@ When /^I retrieve a text field$/ do
18
18
  @element = @page.text_field_id_text_field
19
19
  end
20
20
 
21
+ When /^I retrieve the text area$/ do
22
+ @element = @page.text_area_id_text_area
23
+ end
24
+
21
25
  When /^I retrieve the div element$/ do
22
26
  @element = @page.div_id_div
23
27
  end
@@ -34,6 +38,9 @@ When /^I retrieve table cell$/ do
34
38
  @element = @page.cell_id_cell
35
39
  end
36
40
 
41
+ When /^I locate the form$/ do
42
+ @element = @page.form_id_form
43
+ end
37
44
 
38
45
 
39
46
  Then /^I should know it exists$/ do
@@ -44,6 +51,10 @@ Then /^I should know it is visible$/ do
44
51
  @element.should be_visible
45
52
  end
46
53
 
54
+ Then /^I should know it is not visible$/ do
55
+ @element.should_not be_visible
56
+ end
57
+
47
58
  Then /^I should know its' text is "([^"]*)"$/ do |text|
48
59
  @element.text.should == text
49
60
  end
@@ -77,3 +88,15 @@ end
77
88
  Then /^I should be able to click it$/ do
78
89
  @element.click
79
90
  end
91
+
92
+ When /^I retrieve a list item element$/ do
93
+ @element = @page.li_id_list_item
94
+ end
95
+
96
+ When /^I retrieve an unordered list element$/ do
97
+ @element = @page.ul_id_unordered_list
98
+ end
99
+
100
+ When /^I retrieve an ordered list element$/ do
101
+ @element = @page.ol_id_ordered_list
102
+ end