page-object 0.0.3 → 0.0.4

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 (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
@@ -11,6 +11,26 @@ class Page
11
11
  text_field(:text_field_text, :text => "")
12
12
  text_field(:text_field_value, :value => "")
13
13
 
14
+ text_area(:text_area_id, :id => "text_area_id")
15
+ text_area(:text_area_class, :class => "text_area_class")
16
+ text_area(:text_area_name, :name => "text_area_name")
17
+ text_area(:text_area_xpath, :xpath => "//textarea")
18
+ text_area(:text_area_css, :css => "textarea")
19
+ text_area(:text_area_tag_name, :tag_name => "textarea")
20
+ text_area(:text_area_index, :index => 0)
21
+ text_area(:text_area_text, :text => "")
22
+ text_area(:text_area_value, :value => "")
23
+
24
+ hidden_field(:hidden_field_id, :id => "hidden_field_id")
25
+ hidden_field(:hidden_field_class, :class => "hidden_field_class")
26
+ hidden_field(:hidden_field_name, :name => "hidden_field_name")
27
+ hidden_field(:hidden_field_xpath, :xpath => "//input[@type='hidden']")
28
+ hidden_field(:hidden_field_css, :css => "input[type='hidden']")
29
+ hidden_field(:hidden_field_tag_name, :tag_name => "input[type='hidden']")
30
+ hidden_field(:hidden_field_index, :index => 0)
31
+ hidden_field(:hidden_field_text, :text => "")
32
+ hidden_field(:hidden_field_value, :value => "")
33
+
14
34
  link(:google_search_id, :id => "link_id")
15
35
  link(:google_search_name, :name => "link_name")
16
36
  link(:google_search_class, :class => "link_class")
@@ -80,4 +100,27 @@ class Page
80
100
  image(:image_index, :index => 0)
81
101
  image(:image_xpath, :xpath => '//img')
82
102
 
103
+ form(:form_id, :id => 'form_id')
104
+ form(:form_name, :id => 'form_name')
105
+ form(:form_class, :class => 'form_class')
106
+ form(:form_index, :index => 0)
107
+ form(:form_xpath, :xpath => '//form')
108
+
109
+ list_item(:li_id, :id => 'li_id')
110
+ list_item(:li_name, :name => 'li_name')
111
+ list_item(:li_class, :class => 'li_class')
112
+ list_item(:li_index, :index => 0)
113
+ list_item(:li_xpath, :xpath => '//li[1]')
114
+
115
+ unordered_list(:ul_id, :id => 'ul_id')
116
+ unordered_list(:ul_name, :name => 'ul_name')
117
+ unordered_list(:ul_class, :class => 'ul_class')
118
+ unordered_list(:ul_index, :index => 0)
119
+ unordered_list(:ul_xpath, :xpath => '//ul')
120
+
121
+ ordered_list(:ol_id, :id => 'ol_id')
122
+ ordered_list(:ol_name, :name => 'ol_name')
123
+ ordered_list(:ol_class, :class => 'ol_class')
124
+ ordered_list(:ol_index, :index => 0)
125
+ ordered_list(:ol_xpath, :xpath => '//ol')
83
126
  end
@@ -0,0 +1,32 @@
1
+ Feature: Text Area
2
+
3
+
4
+ Background:
5
+ Given I am on the static elements page
6
+
7
+ Scenario: Setting and getting a value from a text area
8
+ When I type "abcdefghijklmnop" into the text area
9
+ Then the text area should contain "abcdefghijklmnop"
10
+
11
+ Scenario Outline: Locating text area on the Page
12
+ When I search for the text area by "<search_by>"
13
+ Then I should be able to type "I found it" into the area
14
+
15
+ Scenarios:
16
+ | search_by |
17
+ | id |
18
+ | class |
19
+ | name |
20
+ | xpath |
21
+ | css |
22
+ | tag_name |
23
+
24
+ @watir_only
25
+ Scenario Outline: Locating text fields on Watir only
26
+ When I search for the text area by "<search_by>"
27
+ Then I should be able to type "I found it" into the area
28
+
29
+ Scenarios:
30
+ | search_by |
31
+ | index |
32
+
@@ -26,12 +26,11 @@ Feature: Text Fields
26
26
  @watir_only
27
27
  Scenario Outline: Locating text fields on Watir only
28
28
  When I search for the text field by "<search_by>"
29
+ Then I should be able to type "I found it" into the field
29
30
 
30
31
  Scenarios:
31
32
  | search_by |
32
33
  | index |
33
- | text |
34
- | value |
35
34
 
36
35
  Scenario: Retrieve a text field
37
36
  When I retrieve a text field
@@ -0,0 +1,39 @@
1
+ Feature: Unordered list
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Getting the first element from the unordered list
7
+ When I get the first item from the unordered list
8
+ Then the list item's text should be "Item One"
9
+
10
+ Scenario Outline: Locating unordered lists on the page
11
+ When I search for the unordered list by "<search_by>"
12
+ And I get the first item from the list
13
+ Then the list item's text should be "Item One"
14
+
15
+ Scenarios:
16
+ | search_by |
17
+ | id |
18
+ | class |
19
+ | xpath |
20
+
21
+ @watir_only
22
+ Scenario Outline: Locating unordered lists in Watir only
23
+ When I search for the unordered list by "<search_by>"
24
+ And I get the first item from the list
25
+ Then the list item's text should be "Item One"
26
+
27
+ Scenarios:
28
+ | search_by |
29
+ | index |
30
+
31
+ @selenium_only
32
+ Scenario Outline: Locating unordered lists in Selenium only
33
+ When I search for the unordered list by "<search_by>"
34
+ And I get the first item from the list
35
+ Then the list item's text should be "Item One"
36
+
37
+ Scenarios:
38
+ | search_by |
39
+ | name |
@@ -2,36 +2,81 @@
2
2
  require 'page-object/version'
3
3
  require 'page-object/accessors'
4
4
 
5
- # Module that when included adds core functionality to a page object.
5
+ #
6
+ # Module that when included adds functionality to a page object. This module
7
+ # will add numerous class and instance methods that you use to define and
8
+ # interact with web pages.
9
+ #
10
+ # If we have a login page with a username and password textfield and a login
11
+ # button we might define our page like the one below. We can then interact with
12
+ # the object using the generated methods.
13
+ #
14
+ # @example Login page example
15
+ # class LoginPage
16
+ # include PageObject
17
+ #
18
+ # text_field(:username, :id => 'user')
19
+ # text_field(:password, :id => 'pass')
20
+ # button(:login, :value => 'Login')
21
+ # end
22
+ #
23
+ # ...
24
+ #
25
+ # browser = Watir::Browser.new :firefox
26
+ # login_page = LoginPage.new(browser)
27
+ # login_page.username = 'cheezy'
28
+ # login_page.password = 'secret'
29
+ # login_page.login
30
+ #
31
+ # @see PageObject::Accessors to see what class level methods are added to this module at runtime.
32
+ #
6
33
  module PageObject
34
+ # @return [Watir::Browser or Selenium::WebDriver::Driver] the platform browser passed to the constructor
35
+ attr_reader :browser
36
+ # @return [PageObject::WatirPageObject or PageObject::SeleniumPageObject] the platform page object
7
37
  attr_reader :platform
8
38
 
9
- # Construct a new page object. The browser parameter must be either a
10
- # Watir::Browser or Selenium::WebDriver::Driver.
39
+ #
40
+ # Construct a new page object.
41
+ #
42
+ # @param [Watir::Browser or Selenium::WebDriver::Driver] the platform browser to use
43
+ #
11
44
  def initialize(browser)
45
+ @browser = browser
12
46
  include_platform_driver(browser)
13
47
  end
14
48
 
49
+ # @private
15
50
  def self.included(cls)
16
51
  cls.extend PageObject::Accessors
17
52
  end
18
53
 
54
+ #
19
55
  # navigate to the provided url
56
+ #
57
+ # @param [String] the full url to navigate to
58
+ #
20
59
  def navigate_to(url)
21
60
  platform.navigate_to(url)
22
61
  end
23
62
 
63
+ #
24
64
  # Returns the text of the current page
65
+ #
25
66
  def text
26
67
  platform.text
27
68
  end
28
69
 
70
+ #
29
71
  # Returns the html of the current page
72
+ #
30
73
  def html
31
74
  platform.html
32
75
  end
33
76
 
77
+ #
34
78
  # Returns the title of the current page
79
+ #
35
80
  def title
36
81
  platform.title
37
82
  end
@@ -1,30 +1,34 @@
1
1
 
2
- #
3
- # Contains the class level methods that are inserted into your page objects
4
- # when you include the PageObject module. These methods will generate another
5
- # set of methods that provide access to the elements on the web pages.
6
- #
7
2
  module PageObject
3
+ #
4
+ # Contains the class level methods that are inserted into your page objects
5
+ # when you include the PageObject module. These methods will generate another
6
+ # set of methods that provide access to the elements on the web pages.
7
+ #
8
+ # @see PageObject::WatirPageObject for the watir implementation of the platform delegate
9
+ # @see PageObject::SeleniumPageObject for the selenium implementation of the platform delegate
10
+ #
8
11
  module Accessors
9
12
  #
10
13
  # adds three methods to the page object - one to set text in a text field,
11
14
  # another to retrieve text from a text field and another to return the text
12
15
  # field element.
13
16
  #
14
- # Example: text_field(:first_name, {:id => "first_name"})
15
- # will generate the 'first_name', 'first_name=' and 'first_name_text_field methods.
16
- #
17
- # @param the name used for the generated methods
18
- # @param identifier how we find a text_field. The valid values are:
19
- # :class => Watir and Selenium
20
- # :css => Watir and Selenium
21
- # :id => Watir and Selenium
22
- # :index => Watir only
23
- # :name => Watir and Selenium
24
- # :tag_name => Watir and Selenium
25
- # :text => Watir only
26
- # :value => Watir only
27
- # :xpath => Watir and Selenium
17
+ # @example
18
+ # text_field(:first_name, :id => "first_name")
19
+ # # will generate 'first_name', 'first_name=' and 'first_name_text_field' methods
20
+ #
21
+ # @param [String] the name used for the generated methods
22
+ # @param [Hash] identifier how we find a text_field. The valid keys are:
23
+ # * :class => Watir and Selenium
24
+ # * :css => Watir and Selenium
25
+ # * :id => Watir and Selenium
26
+ # * :index => Watir only
27
+ # * :name => Watir and Selenium
28
+ # * :tag_name => Watir and Selenium
29
+ # * :text => Watir only
30
+ # * :value => Watir only
31
+ # * :xpath => Watir and Selenium
28
32
  #
29
33
  def text_field(name, identifier)
30
34
  define_method(name) do
@@ -37,24 +41,84 @@ module PageObject
37
41
  platform.text_field_for identifier
38
42
  end
39
43
  end
44
+
45
+ #
46
+ # adds two methods to the page object - one to get the text from a hidden field
47
+ # and another to retrieve the hidden field element.
48
+ #
49
+ # @example
50
+ # hidden_field(:user_id, :id => "user_identity")
51
+ # # will generate 'user_id' and 'user_id_hidden_field' methods
52
+ #
53
+ # @param [String] the name used for the generated methods
54
+ # @param [Hash] identifier how we find a hidden field. The valid keys are:
55
+ # * :class => Watir and Selenium
56
+ # * :css => Watir and Selenium
57
+ # * :id => Watir and Selenium
58
+ # * :index => Watir only
59
+ # * :name => Watir and Selenium
60
+ # * :tag_name => Watir and Selenium
61
+ # * :text => Watir only
62
+ # * :xpath => Watir and Selenium
63
+ #
64
+ def hidden_field(name, identifier)
65
+ define_method(name) do
66
+ platform.hidden_field_value_for identifier
67
+ end
68
+ define_method("#{name}_hidden_field") do
69
+ platform.hidden_field_for identifier
70
+ end
71
+ end
72
+
73
+ #
74
+ # adds three methods to the page object - one to set text in a text area,
75
+ # another to retrieve text from a text area and another to return the text
76
+ # area element.
77
+ #
78
+ # @example
79
+ # text_area(:address, :id => "address")
80
+ # # will generate 'address', 'address=' and 'address_text_area methods
81
+ #
82
+ # @param [String] the name used for the generated methods
83
+ # @param [Hash] identifier how we find a text area. The valid keys are:
84
+ # * :class => Watir and Selenium
85
+ # * :css => Watir and Selenium
86
+ # * :id => Watir and Selenium
87
+ # * :index => Watir only
88
+ # * :name => Watir and Selenium
89
+ # * :tag_name => Watir and Selenium
90
+ # * :xpath => Watir and Selenium
91
+ #
92
+ def text_area(name, identifier)
93
+ define_method(name) do
94
+ platform.text_area_value_for identifier
95
+ end
96
+ define_method("#{name}=") do |value|
97
+ platform.text_area_value_set(identifier, value)
98
+ end
99
+ define_method("#{name}_text_area") do
100
+ platform.text_area_for identifier
101
+ end
102
+ end
40
103
 
41
104
  #
42
105
  # adds three methods - one to select an item in a drop-down,
43
106
  # another to fetch the currently selected item and another
44
107
  # to retrieve the select list element.
45
108
  #
46
- # Example: select_list(:state, {:id => "state"})
47
- # will generate the 'state', 'state=' and 'state_select_list' methods
109
+ # @example
110
+ # select_list(:state, :id => "state")
111
+ # # will generate 'state', 'state=' and 'state_select_list' methods
48
112
  #
49
- # @param the name used for the generated methods
50
- # @param identifier how we find a select_list. The valid values are:
51
- # :class => Watir and Selenium
52
- # :id => Watir and Selenium
53
- # :index => Watir only
54
- # :name => Watir and Selenium
55
- # :text => Watir only
56
- # :value => Watir only
57
- # :xpath => Watir and Selenium
113
+ # @param [String] the name used for the generated methods
114
+ # @param [Hash] identifier how we find a select_list. The valid keys are:
115
+ # * :class => Watir and Selenium
116
+ # * :id => Watir and Selenium
117
+ # * :index => Watir only
118
+ # * :name => Watir and Selenium
119
+ # * :text => Watir only
120
+ # * :value => Watir only
121
+ # * :xpath => Watir and Selenium
58
122
  #
59
123
  def select_list(name, identifier)
60
124
  define_method(name) do
@@ -73,21 +137,21 @@ module PageObject
73
137
  # to return a PageObject::Elements::Link object representing
74
138
  # the link.
75
139
  #
76
- # Example: link(:add_to_cart, {:text => "Add to Cart"})
77
- # will generate the 'add_to_cart' and 'add_to_cart_link'
78
- # method.
79
- #
80
- # @param the name used for the generated methods
81
- # @param identifier how we find a link. The valid values are:
82
- # :class => Watir and Selenium
83
- # :href => Watir only
84
- # :id => Watir and Selenium
85
- # :index => Watir only
86
- # :link => Watir and Selenium
87
- # :link_text => Watir and Selenium
88
- # :name => Watir and Selenium
89
- # :text => Watir and Selenium
90
- # :xpath => Watir and Selenium
140
+ # @example
141
+ # link(:add_to_cart, :text => "Add to Cart")
142
+ # # will generate 'add_to_cart' and 'add_to_cart_link' methods
143
+ #
144
+ # @param [String] the name used for the generated methods
145
+ # @param [Hash] identifier how we find a link. The valid keys are:
146
+ # * :class => Watir and Selenium
147
+ # * :href => Watir only
148
+ # * :id => Watir and Selenium
149
+ # * :index => Watir only
150
+ # * :link => Watir and Selenium
151
+ # * :link_text => Watir and Selenium
152
+ # * :name => Watir and Selenium
153
+ # * :text => Watir and Selenium
154
+ # * :xpath => Watir and Selenium
91
155
  #
92
156
  def link(name, identifier)
93
157
  define_method(name) do
@@ -103,17 +167,17 @@ module PageObject
103
167
  # to return the state of a checkbox, and a final method to return
104
168
  # a PageObject::Elements::CheckBox object representing the checkbox.
105
169
  #
106
- # Example: checkbox(:active, {:name => "is_active"})
107
- # will generate the 'check_active', 'uncheck_active',
108
- # 'active_checked?' and 'active_checkbox' methods.
170
+ # @example
171
+ # checkbox(:active, :name => "is_active")
172
+ # # will generate 'check_active', 'uncheck_active', 'active_checked?' and 'active_checkbox' methods
109
173
  #
110
- # @param the name used for the generated methods
111
- # @param identifier how we find a checkbox. The valid values are:
112
- # :class => Watir and Selenium
113
- # :id => Watir and Selenium
114
- # :index => Watir only
115
- # :name => Watir and Selenium
116
- # :xpath => Watir and Selenium
174
+ # @param [String] the name used for the generated methods
175
+ # @param [Hash] identifier how we find a checkbox. The valid keys are:
176
+ # * :class => Watir and Selenium
177
+ # * :id => Watir and Selenium
178
+ # * :index => Watir only
179
+ # * :name => Watir and Selenium
180
+ # * :xpath => Watir and Selenium
117
181
  #
118
182
  def checkbox(name, identifier)
119
183
  define_method("check_#{name}") do
@@ -136,17 +200,17 @@ module PageObject
136
200
  # another method to return a PageObject::Elements::RadioButton
137
201
  # object representing the radio button element
138
202
  #
139
- # Example: radio_button(:north, {:id => "north"})
140
- # will generate 'select_north', 'clear_north',
141
- # 'north_selected?' and 'north_radio_button' methods
203
+ # @example
204
+ # radio_button(:north, :id => "north")
205
+ # # will generate 'select_north', 'clear_north', 'north_selected?' and 'north_radio_button' methods
142
206
  #
143
- # @param the name used for the generated methods
144
- # @param identifier how we find a checkbox. The valid values are:
145
- # :class => Watir and Selenium
146
- # :id => Watir and Selenium
147
- # :index => Watir only
148
- # :name => Watir and Selenium
149
- # :xpath => Watir and Selenium
207
+ # @param [String] the name used for the generated methods
208
+ # @param [Hash] identifier how we find a radio button. The valid keys are:
209
+ # * :class => Watir and Selenium
210
+ # * :id => Watir and Selenium
211
+ # * :index => Watir only
212
+ # * :name => Watir and Selenium
213
+ # * :xpath => Watir and Selenium
150
214
  #
151
215
  def radio_button(name, identifier)
152
216
  define_method("select_#{name}") do
@@ -167,17 +231,18 @@ module PageObject
167
231
  # adds two methods - one to click a button and another to
168
232
  # return the button element.
169
233
  #
170
- # Example: button(:purchase, :id => 'purchase')
171
- # will generate a 'purchase' and 'purchase_button' methods.
234
+ # @example
235
+ # button(:purchase, :id => 'purchase')
236
+ # # will generate 'purchase' and 'purchase_button' methods
172
237
  #
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
238
+ # @param [String] the name used for the generated methods
239
+ # @param [Hash] identifier how we find a button. The valid keys are:
240
+ # * :class => Watir and Selenium
241
+ # * :id => Watir and Selenium
242
+ # * :index => Watir only
243
+ # * :name => Watir and Selenium
244
+ # * :text => Watir only
245
+ # * :xpath => Watir and Selenium
181
246
  #
182
247
  def button(name, identifier)
183
248
  define_method(name) do
@@ -192,16 +257,17 @@ module PageObject
192
257
  # adds two methods - one to retrieve the text from a div
193
258
  # and another to return the div element
194
259
  #
195
- # Example: div(:message, {:id => 'message'})
196
- # will generate a 'message' and 'message_div' methods
260
+ # @example
261
+ # div(:message, :id => 'message')
262
+ # # will generate 'message' and 'message_div' methods
197
263
  #
198
- # @param the name used for the generated methods
199
- # @param identifier how we find a div. 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
264
+ # @param [String] the name used for the generated methods
265
+ # @param [Hash] identifier how we find a div. The valid keys are:
266
+ # * :class => Watir and Selenium
267
+ # * :id => Watir and Selenium
268
+ # * :index => Watir only
269
+ # * :name => Selenium only
270
+ # * :xpath => Watir and Selenium
205
271
  #
206
272
  def div(name, identifier)
207
273
  define_method(name) do
@@ -216,16 +282,17 @@ module PageObject
216
282
  # adds two methods - one to retrieve the text from a span
217
283
  # and another to return the span element
218
284
  #
219
- # Example: span(:alert, {:id => 'alert'})
220
- # will generate a 'alert' and 'alert_div' methods
285
+ # @example
286
+ # span(:alert, :id => 'alert')
287
+ # # will generate 'alert' and 'alert_span' methods
221
288
  #
222
- # @param the name used for the generated methods
223
- # @param identifier how we find a span. The valid values are:
224
- # :class => Watir and Selenium
225
- # :id => Watir and Selenium
226
- # :index => Watir only
227
- # :name => Selenium only
228
- # :xpath => Watir and Selenium
289
+ # @param [String] the name used for the generated methods
290
+ # @param [Hash] identifier how we find a span. The valid keys are:
291
+ # * :class => Watir and Selenium
292
+ # * :id => Watir and Selenium
293
+ # * :index => Watir only
294
+ # * :name => Selenium only
295
+ # * :xpath => Watir and Selenium
229
296
  #
230
297
  def span(name, identifier)
231
298
  define_method(name) do
@@ -239,16 +306,17 @@ module PageObject
239
306
  #
240
307
  # adds a method to retrieve the table element
241
308
  #
242
- # Example: table(:cart, :id => 'shopping_cart')
243
- # will generate a 'cart_table' method.
309
+ # @example
310
+ # table(:cart, :id => 'shopping_cart')
311
+ # # will generate a 'cart_table' method
244
312
  #
245
- # @param the name used for the generated methods
246
- # @param identifier how we find a checkbox. The valid values are:
247
- # :class => Watir and Selenium
248
- # :id => Watir and Selenium
249
- # :index => Watir only
250
- # :name => Selenium only
251
- # :xpath => Watir and Selenium
313
+ # @param [String] the name used for the generated methods
314
+ # @param [Hash] identifier how we find a table. The valid keys are:
315
+ # * :class => Watir and Selenium
316
+ # * :id => Watir and Selenium
317
+ # * :index => Watir only
318
+ # * :name => Selenium only
319
+ # * :xpath => Watir and Selenium
252
320
  #
253
321
  def table(name, identifier)
254
322
  define_method("#{name}_table") do
@@ -260,16 +328,17 @@ module PageObject
260
328
  # adds two methods one to retrieve the text from a table cell
261
329
  # and another to return the table cell element
262
330
  #
263
- # Example: cell(:total, :id => 'total_cell')
264
- # will generate a 'total' and 'total_cell' methods
331
+ # @example
332
+ # cell(:total, :id => 'total_cell')
333
+ # # will generate 'total' and 'total_cell' methods
265
334
  #
266
- # @param the name used for the generated methods
267
- # @param identifier how we find a checkbox. The valid values are:
268
- # :class => Watir and Selenium
269
- # :id => Watir and Selenium
270
- # :index => Watir only
271
- # :name => Selenium only
272
- # :xpath => Watir and Selenium
335
+ # @param [String] the name used for the generated methods
336
+ # @param [Hash] identifier how we find a cell. The valid keys are:
337
+ # * :class => Watir and Selenium
338
+ # * :id => Watir and Selenium
339
+ # * :index => Watir only
340
+ # * :name => Selenium only
341
+ # * :xpath => Watir and Selenium
273
342
  #
274
343
  def cell(name, identifier)
275
344
  define_method("#{name}") do
@@ -280,10 +349,112 @@ module PageObject
280
349
  end
281
350
  end
282
351
 
352
+ #
353
+ # adds a method to retrieve the image element
354
+ #
355
+ # @example
356
+ # image(:logo, :id => 'logo')
357
+ # # will generate a 'logo_image' method
358
+ #
359
+ # @param [String] the name used for the generated methods
360
+ # @param [Hash] identifier how we find an image. The valid keys are:
361
+ # * :class => Watir and Selenium
362
+ # * :id => Watir and Selenium
363
+ # * :index => Watir only
364
+ # * :name => Watir and Selenium
365
+ # * :xpath => Watir and Selenium
366
+ #
283
367
  def image(name, identifier)
284
368
  define_method("#{name}_image") do
285
369
  platform.image_for identifier
286
370
  end
287
371
  end
372
+
373
+ #
374
+ # adds a method to retrieve the form element
375
+ #
376
+ # @example
377
+ # form(:login, :id => 'login')
378
+ # # will generate a 'login_form' method
379
+ #
380
+ # @param [String] the name used for the generated methods
381
+ # @param [Hash] identifier how we find a form. The valid keys are:
382
+ # * :class => Watir and Selenium
383
+ # * :id => Watir and Selenium
384
+ # * :index => Watir only
385
+ # * :xpath => Watir and Selenium
386
+ #
387
+ def form(name, identifier)
388
+ define_method("#{name}_form") do
389
+ platform.form_for identifier
390
+ end
391
+ end
392
+
393
+ #
394
+ # adds two methods - one to retrieve the text from a list item
395
+ # and another to return the list item element
396
+ #
397
+ # @example
398
+ # list_item(:item_one, :id => 'one')
399
+ # # will generate 'item_one' and 'item_one_list_item' methods
400
+ #
401
+ # @param [String] the name used for the generated methods
402
+ # @param [Hash] identifier how we find a list item. The valid keys are:
403
+ # * :class => Watir and Selenium
404
+ # * :id => Watir and Selenium
405
+ # * :index => Watir only
406
+ # * :name => Selenium only
407
+ # * :xpath => Watir and Selenium
408
+ #
409
+ def list_item(name, identifier)
410
+ define_method(name) do
411
+ platform.list_item_text_for identifier
412
+ end
413
+ define_method("#{name}_list_item") do
414
+ platform.list_item_for identifier
415
+ end
416
+ end
417
+
418
+ #
419
+ # adds a method to retrieve the unordered list element
420
+ #
421
+ # @example
422
+ # unordered_list(:menu, :id => 'main_menu')
423
+ # # will generate a 'menu_unordered_list' method
424
+ #
425
+ # @param [String] the name used for the generated methods
426
+ # @param [Hash] identifier how we find an unordered list. The valid keys are:
427
+ # * :class => Watir and Selenium
428
+ # * :id => Watir and Selenium
429
+ # * :index => Watir only
430
+ # * :name => Selenium only
431
+ # * :xpath => Watir and Selenium
432
+ #
433
+ def unordered_list(name, identifier)
434
+ define_method("#{name}_unordered_list") do
435
+ platform.unordered_list_for identifier
436
+ end
437
+ end
438
+
439
+ #
440
+ # adds a method to retrieve the ordered list element
441
+ #
442
+ # @example
443
+ # ordered_list(:top_five, :id => 'top')
444
+ # # will generate a 'top_five_ordered_list' method
445
+ #
446
+ # @param [String] the name used for the generated methods
447
+ # @param [Hash] identifier how we find an unordered list. The valid keys are:
448
+ # * :class => Watir and Selenium
449
+ # * :id => Watir and Selenium
450
+ # * :index => Watir only
451
+ # * :name => Selenium only
452
+ # * :xpath => Watir and Selenium
453
+ #
454
+ def ordered_list(name, identifier)
455
+ define_method("#{name}_ordered_list") do
456
+ platform.ordered_list_for identifier
457
+ end
458
+ end
288
459
  end
289
460
  end