page-object 0.0.1 → 0.0.2

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.
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
data/.gitignore CHANGED
@@ -1,6 +1,4 @@
1
1
  Gemfile.lock
2
2
  .bundle
3
- .rspec
4
- .rvmrc
5
3
  .idea/
6
4
  pkg
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format doc
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2
data/ChangeLog ADDED
@@ -0,0 +1,23 @@
1
+ === Version 0.0.2
2
+ * Enhancements
3
+ * Added support for the following elements
4
+ * div
5
+ * button
6
+ * table
7
+ * table row
8
+ * table cell
9
+ * added #text to element
10
+
11
+ === Version 0.0.1 / 2011-05-22
12
+ * Enhancements
13
+ * Support for the following elements
14
+ * check box
15
+ * link
16
+ * radio button
17
+ * select list
18
+ * text field
19
+
20
+ * Support for the following page level functions
21
+ * text
22
+ * html
23
+ * title
data/README.md CHANGED
@@ -68,6 +68,8 @@ The rdocs for this project can be found at [rubydoc.info](http://rubydoc.info/gi
68
68
 
69
69
  If you wish to view the current tracker board you can view it on [Pivotal Tracker](https://www.pivotaltracker.com/projects/289099)
70
70
 
71
+ To read about the motivation for this gem please read this [blog entry](http://www.cheezyworld.com/2010/11/19/ui-tests-introducing-a-simple-dsl/)
72
+
71
73
  ## Known Issues
72
74
 
73
75
  See [http://github.com/cheezy/page-object/issues](http://github.com/cheezy/page-object/issues)
@@ -0,0 +1,37 @@
1
+ Feature: Button
2
+ In order to interact with buttons
3
+ Testers will need access and interrogation ability
4
+
5
+
6
+ Background:
7
+ Given I am on the static elements page
8
+
9
+ Scenario: Getting the text from a div
10
+ When I click the button
11
+ Then I should be on the success page
12
+
13
+ Scenario: Retrieve a button element
14
+ When I retrieve a button element
15
+ Then I should know it exists
16
+ And I should know it is visible
17
+
18
+ Scenario Outline: Locating buttons on the page
19
+ When I search for the button by "<search_by>"
20
+ Then I should be able to click the button
21
+
22
+ Scenarios:
23
+ | search_by |
24
+ | id |
25
+ | class |
26
+ | name |
27
+ | xpath |
28
+
29
+ @watir_only
30
+ Scenario Outline: Locating check boxes on Watir only
31
+ When I search for the button by "<search_by>"
32
+ Then I should be able to click the button
33
+
34
+ Scenarios:
35
+ | search_by |
36
+ | index |
37
+ | text |
@@ -0,0 +1,45 @@
1
+ Feature: Div
2
+ In order to interact with divs
3
+ Testers will need access and interrogation ability
4
+
5
+
6
+ Background:
7
+ Given I am on the static elements page
8
+
9
+ Scenario: Getting the text from a div
10
+ When I get the text from the div
11
+ Then the text should be "page-object rocks!"
12
+
13
+ Scenario: Getting the div element
14
+ When I retrieve the div element
15
+ Then I should know it exists
16
+ And I should know it is visible
17
+
18
+ Scenario Outline: Locating divs on the page
19
+ When I search for the div by "<search_by>"
20
+ Then the text should be "page-object rocks!"
21
+
22
+ Scenarios:
23
+ | search_by |
24
+ | id |
25
+ | class |
26
+ | xpath |
27
+
28
+ @watir_only
29
+ Scenario Outline: Locating divs on Watir only
30
+ When I search for the div by "<search_by>"
31
+ Then the text should be "page-object rocks!"
32
+
33
+ Scenarios:
34
+ | search_by |
35
+ | index |
36
+
37
+
38
+ @selenium_only
39
+ Scenario Outline: Locating divs on Watir only
40
+ When I search for the div by "<search_by>"
41
+ Then the text should be "page-object rocks!"
42
+
43
+ Scenarios:
44
+ | search_by |
45
+ | name |
@@ -16,11 +16,9 @@
16
16
  <option value="option2">Test 2</option>
17
17
  </select>
18
18
 
19
- <h3>Button</h3>
20
- <button id="test_button" onclick="javascript:window.location='http://www.google.com'">Click Me!!</button>
21
19
 
22
20
  <h3>Link</h3>
23
- <a href="http://www.google.com" id="link_id" name="link_name" class="link_class" >Google Search</a>
21
+ <a href="success.html" id="link_id" name="link_name" class="link_class" >Google Search</a>
24
22
 
25
23
  <h3>Check Boxes</h3>
26
24
  <input id="cb_id" name="cb_name" class="cb_class" type="checkbox" value="1" />
@@ -28,6 +26,26 @@
28
26
  <h3>Radio Buttons</h3>
29
27
  <input type="radio" id="milk_id" name="milk_name" class="milk_class" value="Milk"> Milk <br />
30
28
  <input type="radio" id="butter_id" name="butter_name" class="butter_class" value="Butter">Butter
29
+
30
+ <h3>Div</h3>
31
+ <div id="div_id" name="div_name" class="div_class">
32
+ page-object rocks!
33
+ </div>
34
+
35
+ <h3>Table</h3>
36
+ <table id='table_id' name='table_name' class='table_class' border='1'>
37
+ <tr>
38
+ <td>Data1</td><td>Data2</td>
39
+ </tr>
40
+ <tr>
41
+ <td>Data3</td><td id='cell_id', name='cell_name' class='cell_class'>Data4</td>
42
+ </tr>
43
+ </table>
44
+
45
+ <h3>Button</h3>
46
+ <form method="get" action="success.html">
47
+ <input id='button_id' name='button_name' class='button_class' type="submit" value="Click Me">
48
+ </form>
31
49
  </body>
32
50
  </html>
33
51
 
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>Success</title>
4
+ </head>
5
+ <body>
6
+ <h1>Success</h1>
7
+ </body>
8
+ </html>
@@ -2,15 +2,12 @@ Feature: Links
2
2
  In order to interact with links
3
3
  Testers will need access and interrogation ability
4
4
 
5
- Note:
6
- Watir supports href
7
-
8
5
  Background:
9
6
  Given I am on the static elements page
10
7
 
11
8
  Scenario: Selecting a link
12
9
  When I select the link labeled "Google Search"
13
- Then the page should contain the text "Google"
10
+ Then the page should contain the text "Success"
14
11
 
15
12
  Scenario Outline: Locating links on the Page
16
13
  When I search for the link by "<search_by>"
@@ -86,3 +86,40 @@ end
86
86
  When /^I select the radio button$/ do
87
87
  @page.send "select_milk_#{@how}".to_sym
88
88
  end
89
+
90
+ When /^I get the text from the div$/ do
91
+ @div_text = @page.div_id
92
+ end
93
+
94
+ Then /^the text should be "([^"]*)"$/ do |expected_text|
95
+ @div_text.should == expected_text
96
+ end
97
+
98
+ When /^I search for the div by "([^"]*)"$/ do |how|
99
+ @div_text = @page.send "div_#{how}".to_sym
100
+ end
101
+
102
+ When /^I click the button$/ do
103
+ @page.button_id
104
+ end
105
+
106
+ Then /^I should be on the success page$/ do
107
+ @page.text.should include 'Success'
108
+ @page.title.should == 'Success'
109
+ end
110
+
111
+ When /^I search for the button by "([^"]*)"$/ do |how|
112
+ @how = how
113
+ end
114
+
115
+ Then /^I should be able to click the button$/ do
116
+ @page.send "button_#{@how}"
117
+ end
118
+
119
+ When /^I search for the table cell by "([^"]*)"$/ do |how|
120
+ @cell_data = @page.send "cell_#{how}"
121
+ end
122
+
123
+ When /^I retrieve a table element by "([^"]*)"$/ do |how|
124
+ @element = @page.send "table_#{how}_table"
125
+ end
@@ -18,6 +18,24 @@ 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 div element$/ do
22
+ @element = @page.div_id_div
23
+ end
24
+
25
+ When /^I retrieve a table element$/ do
26
+ @element = @page.table_id_table
27
+ end
28
+
29
+ When /^I retrieve a button element$/ do
30
+ @element = @page.button_id_button
31
+ end
32
+
33
+ When /^I retrieve table cell$/ do
34
+ @element = @page.cell_id_cell
35
+ end
36
+
37
+
38
+
21
39
  Then /^I should know it exists$/ do
22
40
  @element.should exist
23
41
  end
@@ -0,0 +1,14 @@
1
+ Then /^the data for row "([^"]*)" should be "([^"]*)" and "([^"]*)"$/ do |row, col1, col2|
2
+ table_row = @element[row.to_i - 1]
3
+ table_row[0].text.should == col1
4
+ table_row[1].text.should == col2
5
+ end
6
+
7
+
8
+ When /^I retrieve the data from the table cell$/ do
9
+ @cell_data = @page.cell_id
10
+ end
11
+
12
+ Then /^the cell data should be '([^"]*)'$/ do |expected|
13
+ @cell_data.should == expected
14
+ end
@@ -17,7 +17,7 @@ class Page
17
17
  link(:google_search_xpath, :xpath => "//a[text()='Google Search']")
18
18
  link(:google_search_link, :link => "Google Search")
19
19
  link(:google_search_link_text, :link_text => "Google Search")
20
- link(:google_search_href, :href => "http://www.google.com")
20
+ link(:google_search_href, :href => "success.html")
21
21
  link(:google_search_text, :text => "Google Search")
22
22
  link(:google_search_index, :index => 0)
23
23
 
@@ -42,4 +42,29 @@ class Page
42
42
  radio_button(:milk_xpath, :xpath => "//input[@type='radio']")
43
43
 
44
44
  radio_button(:butter_id, :id => 'butter_id')
45
+
46
+ div(:div_id, :id => 'div_id')
47
+ div(:div_name, :name => 'div_name')
48
+ div(:div_class, :class => 'div_class')
49
+ div(:div_index, :index => 0)
50
+ div(:div_xpath, :xpath => '//div')
51
+
52
+ table(:table_id, :id => 'table_id')
53
+ table(:table_name, :name => 'table_name')
54
+ table(:table_class, :class => 'table_class')
55
+ table(:table_index, :index => 0)
56
+ table(:table_xpath, :xpath => '//table')
57
+
58
+ cell(:cell_id, :id => 'cell_id')
59
+ cell(:cell_name, :name => 'cell_name')
60
+ cell(:cell_class, :class => 'cell_class')
61
+ cell(:cell_index, :index => 3)
62
+ cell(:cell_xpath, :xpath => '//table//tr[2]//td[2]')
63
+
64
+ button(:button_id, :id => 'button_id')
65
+ button(:button_name, :name => 'button_name')
66
+ button(:button_class, :class => 'button_class')
67
+ button(:button_index, :index => 0)
68
+ button(:button_xpath, :xpath=> "//input[@type='submit']")
69
+ button(:button_text, :text => 'Click Me')
45
70
  end
@@ -0,0 +1,52 @@
1
+ Feature: Table
2
+ In order to interact with tables
3
+ Testers will need access and interrogation ability
4
+
5
+
6
+ Background:
7
+ Given I am on the static elements page
8
+
9
+ Scenario: Retrieve a table
10
+ When I retrieve a table element
11
+ Then I should know it is visible
12
+
13
+ @watir_only
14
+ Scenario: Determine if a table exists
15
+ When I retrieve a table element
16
+ Then I should know it exists
17
+
18
+ Scenario: Retrieve the data from a table
19
+ When I retrieve a table element
20
+ Then the data for row "1" should be "Data1" and "Data2"
21
+ And the data for row "2" should be "Data3" and "Data4"
22
+
23
+
24
+ Scenario Outline: Locating table cells on the Page
25
+ When I retrieve a table element by "<search_by>"
26
+ Then the data for row "1" should be "Data1" and "Data2"
27
+
28
+ Scenarios:
29
+ | search_by |
30
+ | id |
31
+ | class |
32
+ | xpath |
33
+
34
+
35
+ @watir_only
36
+ Scenario Outline: Locating table cells on the Page with watir
37
+ When I retrieve a table element by "<search_by>"
38
+ Then the data for row "1" should be "Data1" and "Data2"
39
+
40
+ Scenarios:
41
+ | search_by |
42
+ | index |
43
+
44
+
45
+ @selenium_only
46
+ Scenario Outline: Locating table cells on the Page with selenium
47
+ When I retrieve a table element by "<search_by>"
48
+ Then the data for row "1" should be "Data1" and "Data2"
49
+
50
+ Scenarios:
51
+ | search_by |
52
+ | name |
@@ -0,0 +1,45 @@
1
+ Feature: Table Cell
2
+
3
+
4
+ Background:
5
+ Given I am on the static elements page
6
+
7
+ Scenario: Retrieving the text from a table cell
8
+ When I retrieve the data from the table cell
9
+ Then the cell data should be 'Data4'
10
+
11
+ Scenario Outline: Locating table cells on the Page
12
+ When I search for the table cell by "<search_by>"
13
+ Then the cell data should be 'Data4'
14
+
15
+ Scenarios:
16
+ | search_by |
17
+ | id |
18
+ | class |
19
+ | xpath |
20
+
21
+
22
+ @watir_only
23
+ Scenario Outline: Locating table cells on the Page with watir
24
+ When I search for the table cell by "<search_by>"
25
+ Then the cell data should be 'Data4'
26
+
27
+ Scenarios:
28
+ | search_by |
29
+ | index |
30
+
31
+ @selenium_only
32
+ Scenario Outline: Locating table cells on the Page with watir
33
+ When I search for the table cell by "<search_by>"
34
+ Then the cell data should be 'Data4'
35
+
36
+ Scenarios:
37
+ | search_by |
38
+ | name |
39
+
40
+ Scenario: Retrieve a cell from a table by id
41
+ When I retrieve table cell
42
+ Then I should know it exists
43
+ And I should know it is visible
44
+
45
+
@@ -163,8 +163,96 @@ module PageObject
163
163
  end
164
164
  end
165
165
 
166
+ #
167
+ # adds two methods - one to click a button and another to
168
+ # return the button element.
169
+ #
170
+ # Example: button(:purchase, :id => 'purchase')
171
+ # will generate a 'purchase' and 'purchase_button' methods.
172
+ #
173
+ # @param the name used for the generated methods
174
+ # @param identifier how we find a checkbox. The valid values are:
175
+ # :class => Watir and Selenium
176
+ # :id => Watir and Selenium
177
+ # :index => Watir only
178
+ # :name => Watir and Selenium
179
+ # :text => Watir only
180
+ # :xpath => Watir and Selenium
181
+ #
166
182
  def button(name, identifier)
167
183
  define_method(name) do
184
+ platform.click_button_for identifier
185
+ end
186
+ define_method("#{name}_button") do
187
+ platform.button_for identifier
188
+ end
189
+ end
190
+
191
+ #
192
+ # adds two methods - one to retrieve the text from a div
193
+ # and another to return the div element
194
+ #
195
+ # Example: div(:message, {:id => 'message'})
196
+ # will generate a 'message' and 'message_div' methods
197
+ #
198
+ # @param the name used for the generated methods
199
+ # @param identifier how we find a checkbox. The valid values are:
200
+ # :class => Watir and Selenium
201
+ # :id => Watir and Selenium
202
+ # :index => Watir only
203
+ # :name => Selenium only
204
+ # :xpath => Watir and Selenium
205
+ #
206
+ def div(name, identifier)
207
+ define_method("#{name}") do
208
+ platform.div_text_for identifier
209
+ end
210
+ define_method("#{name}_div") do
211
+ platform.div_for identifier
212
+ end
213
+ end
214
+
215
+ #
216
+ # adds a method to retrieve the table element
217
+ #
218
+ # Example: table(:cart, :id => 'shopping_cart')
219
+ # will generate a 'cart_table' method.
220
+ #
221
+ # @param the name used for the generated methods
222
+ # @param identifier how we find a checkbox. The valid values are:
223
+ # :class => Watir and Selenium
224
+ # :id => Watir and Selenium
225
+ # :index => Watir only
226
+ # :name => Selenium only
227
+ # :xpath => Watir and Selenium
228
+ #
229
+ def table(name, identifier)
230
+ define_method("#{name}_table") do
231
+ platform.table_for identifier
232
+ end
233
+ end
234
+
235
+ #
236
+ # adds two methods one to retrieve the text from a table cell
237
+ # and another to return the table cell element
238
+ #
239
+ # Example: cell(:total, :id => 'total_cell')
240
+ # will generate a 'total' and 'total_cell' methods
241
+ #
242
+ # @param the name used for the generated methods
243
+ # @param identifier how we find a checkbox. The valid values are:
244
+ # :class => Watir and Selenium
245
+ # :id => Watir and Selenium
246
+ # :index => Watir only
247
+ # :name => Selenium only
248
+ # :xpath => Watir and Selenium
249
+ #
250
+ def cell(name, identifier)
251
+ define_method("#{name}") do
252
+ platform.cell_text_for identifier
253
+ end
254
+ define_method("#{name}_cell") do
255
+ platform.cell_for identifier
168
256
  end
169
257
  end
170
258
  end