druid-ts 0.0.1

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 (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +7 -0
  5. data/README.md +11 -0
  6. data/Rakefile +33 -0
  7. data/cucumber.yml +2 -0
  8. data/features/button.feature +38 -0
  9. data/features/checkbox.feature +39 -0
  10. data/features/div.feature +38 -0
  11. data/features/element.feature +114 -0
  12. data/features/form.feature +29 -0
  13. data/features/hidden_field.feature +33 -0
  14. data/features/html/images/circle.png +0 -0
  15. data/features/html/static_elements.html +89 -0
  16. data/features/html/success.html +8 -0
  17. data/features/image.feature +33 -0
  18. data/features/link.feature +39 -0
  19. data/features/list_item.feature +31 -0
  20. data/features/ordered_list.feature +35 -0
  21. data/features/page_level_actions.feature +31 -0
  22. data/features/radio_button.feature +42 -0
  23. data/features/select_list.feature +48 -0
  24. data/features/span.feature +36 -0
  25. data/features/step_definations/button_steps.rb +24 -0
  26. data/features/step_definations/checkbox_steps.rb +31 -0
  27. data/features/step_definations/div_steps.rb +19 -0
  28. data/features/step_definations/element_steps.rb +29 -0
  29. data/features/step_definations/form_steps.rb +11 -0
  30. data/features/step_definations/hidden_field_steps.rb +19 -0
  31. data/features/step_definations/image_steps.rb +19 -0
  32. data/features/step_definations/link_steps.rb +29 -0
  33. data/features/step_definations/list_item_steps.rb +12 -0
  34. data/features/step_definations/ordered_list_steps.rb +33 -0
  35. data/features/step_definations/page_level_actions_steps.rb +48 -0
  36. data/features/step_definations/page_traversal_steps.rb +4 -0
  37. data/features/step_definations/radio_button_steps.rb +23 -0
  38. data/features/step_definations/select_list_steps.rb +42 -0
  39. data/features/step_definations/span_steps.rb +15 -0
  40. data/features/step_definations/table_cell_steps.rb +19 -0
  41. data/features/step_definations/table_steps.rb +38 -0
  42. data/features/step_definations/text_area_steps.rb +19 -0
  43. data/features/step_definations/text_field_steps.rb +23 -0
  44. data/features/step_definations/unordered_list_steps.rb +11 -0
  45. data/features/support/env.rb +17 -0
  46. data/features/support/page.rb +163 -0
  47. data/features/support/url_helper.rb +16 -0
  48. data/features/table.feature +43 -0
  49. data/features/table_cell.feature +36 -0
  50. data/features/text_area.feature +32 -0
  51. data/features/text_field.feature +42 -0
  52. data/features/unordered_list.feature +36 -0
  53. data/lib/druid.rb +80 -0
  54. data/lib/druid/accessors.rb +506 -0
  55. data/lib/druid/elements.rb +19 -0
  56. data/lib/druid/elements/button.rb +11 -0
  57. data/lib/druid/elements/check_box.rb +7 -0
  58. data/lib/druid/elements/div.rb +10 -0
  59. data/lib/druid/elements/element.rb +129 -0
  60. data/lib/druid/elements/form.rb +7 -0
  61. data/lib/druid/elements/hidden_field.rb +11 -0
  62. data/lib/druid/elements/image.rb +7 -0
  63. data/lib/druid/elements/link.rb +16 -0
  64. data/lib/druid/elements/list_item.rb +7 -0
  65. data/lib/druid/elements/ordered_list.rb +30 -0
  66. data/lib/druid/elements/radio_button.rb +7 -0
  67. data/lib/druid/elements/select_list.rb +18 -0
  68. data/lib/druid/elements/span.rb +11 -0
  69. data/lib/druid/elements/table.rb +30 -0
  70. data/lib/druid/elements/table_cell.rb +7 -0
  71. data/lib/druid/elements/table_row.rb +22 -0
  72. data/lib/druid/elements/text_area.rb +11 -0
  73. data/lib/druid/elements/text_field.rb +11 -0
  74. data/lib/druid/elements/unordered_list.rb +28 -0
  75. data/lib/druid/page_factory.rb +58 -0
  76. data/spec/druid/druid_spec.rb +38 -0
  77. data/spec/spec_helper.rb +7 -0
  78. metadata +224 -0
@@ -0,0 +1,16 @@
1
+ module UrlHelper
2
+ class << self
3
+ def html
4
+ File.expand_path("#{File.dirname(__FILE__)}/../html")
5
+ end
6
+
7
+ def files
8
+ "file://#{html}"
9
+ end
10
+
11
+
12
+ def static_elements
13
+ "#{files}/static_elements.html"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,43 @@
1
+ Feature: Table
2
+ In order to interact with tables
3
+ Testers will need access and interrogation ability
4
+
5
+ Background:
6
+ Given I am on the static elements page
7
+
8
+ Scenario: Retrieve a table
9
+ When I retrieve a table element
10
+ Then I should know it is visible
11
+ Then I should know it exists
12
+
13
+ @name
14
+ Scenario Outline: Locating table cells on the Page
15
+ When I retrieve a table element by "<locate_by>"
16
+ Then the data for row "1" should be "Data1" and "Data2"
17
+
18
+ Examples:
19
+ | locate_by |
20
+ | id |
21
+ | class |
22
+ | xpath |
23
+ | index |
24
+ | name |
25
+
26
+ Scenario: Retrieve the data from a table
27
+ When I retrieve a table element
28
+ Then the data for row "1" should be "Data1" and "Data2"
29
+ And the data for row "2" should be "Data3" and "Data4"
30
+ And the table should have "2" rows
31
+ And each row should contain "Data"
32
+ And row "1" should have "2" columns
33
+ And each column should contain "Data"
34
+
35
+ @multi
36
+ Scenario Outline: Locating table using multiple parameters
37
+ When I retrieve a table element bys "<param1>" and "<param2>"
38
+ Then the data for row "1" should be "Data1" and "Data2"
39
+
40
+ Examples:
41
+ | param1 | param2 |
42
+ | class | index |
43
+ | name | index |
@@ -0,0 +1,36 @@
1
+ Feature: Table Cell
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Retrieving the text from a table cell
7
+ When I retrieve the data from the table cell
8
+ Then the cell data should be 'Data4'
9
+
10
+ @name
11
+ Scenario Outline: Locating table cells on the Page
12
+ When I locate the table cell by "<locate_by>"
13
+ Then the cell data should be 'Data4'
14
+
15
+ Examples:
16
+ | locate_by |
17
+ | id |
18
+ | class |
19
+ | xpath |
20
+ | index |
21
+ | name |
22
+
23
+ Scenario: Retrieve a cell from a table by id
24
+ When I retrieve table cell
25
+ Then I should know it exists
26
+ And I should know it is visible
27
+
28
+ @multi
29
+ Scenario Outline: Locating table cell using multiple parameters
30
+ When I retrieve a table cell element by "<param1>" and "<param2>"
31
+ Then the cell data should be 'Data4'
32
+
33
+ Examples:
34
+ | param1 | param2 |
35
+ | class | index |
36
+ | name | index |
@@ -0,0 +1,32 @@
1
+ Feature: Text Area
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Setting and getting a value from a text area
7
+ When I type "abcdefghijklmnop" into the text area
8
+ Then the text area should contain "abcdefghijklmnop"
9
+
10
+ Scenario Outline: Locating text area on the Page
11
+ When I locate the text area by "<locate_by>"
12
+ Then I should be able to type "I found it" into the area
13
+
14
+ Examples:
15
+ | locate_by |
16
+ | id |
17
+ | class |
18
+ | name |
19
+ | xpath |
20
+ | css |
21
+ | tag_name |
22
+ | index |
23
+
24
+ @multi
25
+ Scenario Outline: Locating a text area using multiple parameters
26
+ When I search for the text area by "<param1>" and "<param2>"
27
+ Then I should be able to type "I found it" into the area
28
+
29
+ Examples:
30
+ | param1 | param2 |
31
+ | class | index |
32
+ | name | index |
@@ -0,0 +1,42 @@
1
+ Feature: Text Fields
2
+ In order to interact with text fields
3
+ Testers will need access and interrogation ability
4
+
5
+ Background:
6
+ Given I am on the static elements page
7
+
8
+ Scenario: Setting and getting a value from a text field
9
+ When I type "abcDEF" into the text field
10
+ Then the text field should contain "abcDEF"
11
+
12
+ @dev
13
+ Scenario Outline: Locating text fields on the Page
14
+ When I locate the text field by "<locate_by>"
15
+ Then I should be able to type "I found it" into the field
16
+
17
+ Examples:
18
+ | locate_by |
19
+ | id |
20
+ | class |
21
+ | name |
22
+ | xpath |
23
+ | css |
24
+ | tag_name |
25
+ | index |
26
+ | text |
27
+ #| value |
28
+
29
+ Scenario: Retrieve a text field
30
+ When I retrieve a text field
31
+ Then I should know it exists
32
+ And I should know it is visible
33
+
34
+ @multi
35
+ Scenario Outline: Locating a text field using multiple parameters
36
+ When I search for the text field by "<param1>" and "<param2>"
37
+ Then I should be able to type "I found it" into the field
38
+
39
+ Examples:
40
+ | param1 | param2 |
41
+ | class | index |
42
+ | name | index |
@@ -0,0 +1,36 @@
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
+ @name
11
+ Scenario Outline: Locating unordered lists on the page
12
+ When I locate the unordered list by "<locate_by>"
13
+ And I get the first item from the list
14
+ Then the list item's text should be "Item One"
15
+ And the list should contain 3 items
16
+ And each item should contain "Item"
17
+
18
+ Examples:
19
+ | locate_by |
20
+ | id |
21
+ | class |
22
+ | xpath |
23
+ | index |
24
+ | name |
25
+
26
+ @multi
27
+ Scenario Outline: Locating unordered lists using multiple parameters
28
+ When I search for the unordered list by "<param1>" and "<param2>"
29
+ And I get the first item from the list
30
+ Then the list items text should be "Item One"
31
+
32
+ Examples:
33
+ | param1 | param2 |
34
+ | class | index |
35
+ | name | index |
36
+ | class | name |
@@ -0,0 +1,80 @@
1
+ require 'druid/accessors'
2
+ require 'druid/page_factory'
3
+
4
+ #
5
+ # Module that when included adds functionality to a page object. This module
6
+ # will add numerous class and instance methods that you use to define and
7
+ # interact with web pages.
8
+ #
9
+ # If we have a login page with a username and password textfield and a login
10
+ # button we might define our page like the one below. We can then interact with
11
+ # the object using the generated methods.
12
+ #
13
+ # @example Login page example
14
+ # class LoginPage
15
+ # include Druid
16
+ #
17
+ # text_field(:username, :id => 'user')
18
+ # text_field(:password, :id => 'pass')
19
+ # button(:login, :value => 'Login')
20
+ # end
21
+ #
22
+ # ...
23
+ #
24
+ # browser = Watir::Browser.new :firefox
25
+ # login_page = LoginPage.new(browser)
26
+ # login_page.username = 'tim'
27
+ # login_page.password = 'sheng'
28
+ # login_page.login
29
+ #
30
+ # @see Druid::Accessors to see what class level methods are added to this module at runtime.
31
+ #
32
+ module Druid
33
+ # @return [Watir::Browser] the drvier passed to the constructor
34
+ attr_reader :driver
35
+ #
36
+ # Construct a new druid.
37
+ #
38
+ # @param [Watir::Browser] the driver to use
39
+ #
40
+ def initialize(driver, visit=false)
41
+ @driver ||= driver
42
+ goto if visit && respond_to?(:goto)
43
+ end
44
+
45
+ # @private
46
+ def self.included(cls)
47
+ cls.extend Druid::Accessors
48
+ end
49
+
50
+ #
51
+ # navigate to the provided url
52
+ #
53
+ # @param [String] the full url to navigate to
54
+ #
55
+ def navigate_to url
56
+ driver.goto url
57
+ end
58
+
59
+ #
60
+ # Returns the text of the current page
61
+ #
62
+ def text
63
+ driver.text
64
+ end
65
+
66
+ #
67
+ # Returns the html of the current page
68
+ #
69
+ def html
70
+ driver.html
71
+ end
72
+
73
+ #
74
+ # Returns the title of the current page
75
+ #
76
+ def title
77
+ driver.title
78
+ end
79
+
80
+ end
@@ -0,0 +1,506 @@
1
+ require 'druid/elements'
2
+ #
3
+ # Contains the class level methods that are inserted into your page class
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
+ module Druid
8
+ module Accessors
9
+ #
10
+ # Specify the url for the page. A call to this method will generate a
11
+ # 'goto' method to take you to the page.
12
+ #
13
+ # @param [String] the url for the page.
14
+ #
15
+ def page_url(url)
16
+ define_method("goto") do
17
+ driver.goto url
18
+ end
19
+ end
20
+ #
21
+ # add two methods - one to select a link and another
22
+ # to return a link element
23
+ #
24
+ # Example: link(:add_to_cart, :text => "Add to Cart")
25
+ # will generate the 'add_to_cart' and 'add_to_cart_link'
26
+ # methods.
27
+ #
28
+ # @param the name used for the generated methods
29
+ # @param identifier how we find a link. The valid values are:
30
+ # :class
31
+ # :href
32
+ # :id
33
+ # :index
34
+ # :name
35
+ # :text
36
+ # :xpath
37
+ # :link
38
+ # :link_text
39
+ def link(name, identifier)
40
+ identifier = Elements::Link.identifier_for identifier
41
+ define_method(name) do
42
+ puts "#{name} method generated"
43
+ driver.link(identifier).click
44
+ end
45
+ define_method("#{name}_link") do
46
+ puts "#{name}_link method generated"
47
+ driver.link(identifier)
48
+ end
49
+ end
50
+ #
51
+ # adds three methods to the page object - one to set text in a text field,
52
+ # another to retrieve text from a text field and another to return the text
53
+ # field element.
54
+ #
55
+ # Example: text_field(:first_name, {:id => "first_name"})
56
+ # will generate the 'first_name', 'first_name=' and 'first_name_text_field methods.
57
+ #
58
+ # @param the name used for the generated methods
59
+ # @param identifier how we find a text_field. The valid values are:
60
+ # :class
61
+ # :css
62
+ # :id
63
+ # :index
64
+ # :name
65
+ # :tag_name
66
+ # :xpath
67
+ def text_field(name, identifier)
68
+ identifier = Elements::TextField.identifier_for identifier
69
+ define_method(name) do
70
+ puts "#{name} method generated"
71
+ driver.text_field(identifier).value
72
+ end
73
+ define_method("#{name}=") do |value|
74
+ puts "#{name}= method generated"
75
+ driver.text_field(identifier).set value
76
+ end
77
+ define_method("#{name}_text_field") do
78
+ puts "#{name}_element method generated"
79
+ driver.text_field(identifier)
80
+ end
81
+ end
82
+ #
83
+ # adds four methods - one to check, another to uncheck, another
84
+ # to return the state of a checkbox, and a final method to return
85
+ # a checkbox element.
86
+ #
87
+ # Example: checkbox(:active, {:name => "is_active"})
88
+ # will generate the 'check_active', 'uncheck_active',
89
+ # 'active_checked?' and 'active_checkbox' methods.
90
+ #
91
+ # @param the name used for the generated methods
92
+ # @param identifier how we find a checkbox. The valid values are:
93
+ # :class
94
+ # :id
95
+ # :index
96
+ # :name
97
+ # :xpath
98
+ #
99
+ def checkbox(name, identifier)
100
+ identifier = Elements::CheckBox.identifier_for identifier
101
+ define_method("check_#{name}") do
102
+ puts "check_#{name} method generated"
103
+ driver.checkbox(identifier).set
104
+ end
105
+ define_method("uncheck_#{name}") do
106
+ puts "uncheck_#{name} method generated"
107
+ driver.checkbox(identifier).clear
108
+ end
109
+ define_method("#{name}_checked?") do
110
+ puts "#{name}_checked? method generated"
111
+ driver.checkbox(identifier).set?
112
+ end
113
+ define_method("#{name}_checkbox") do
114
+ puts "#{name}_checkbox method generated"
115
+ driver.checkbox(identifier)
116
+ end
117
+ end
118
+ #
119
+ # adds three methods - one to select an item in a drop-down,
120
+ # another to fetch the currently selected item and another
121
+ # to retrieve the select list element.
122
+ #
123
+ # Example: select_list(:state, {:id => "state"})
124
+ # will generate the 'state', 'state=' and 'state_select_list' methods
125
+ #
126
+ # @param the name used for the generated methods
127
+ # @param identifier how we find a select_list. The valid values are:
128
+ # :class
129
+ # :id
130
+ # :index
131
+ # :name
132
+ # :xpath
133
+ #
134
+ def select_list(name, identifier)
135
+ identifier = Elements::SelectList.identifier_for identifier
136
+ define_method(name) do
137
+ puts "#{name} method generated"
138
+ driver.select_list(identifier).value
139
+ end
140
+ define_method("#{name}=") do |value|
141
+ puts "#{name}= method generated"
142
+ driver.select_list(identifier).select value
143
+ end
144
+ define_method("#{name}_select_list") do
145
+ puts "#{name}_select_list method generated"
146
+ element = driver.select_list(identifier)
147
+ Druid::Elements::SelectList.new(element)
148
+ end
149
+ end
150
+ #
151
+ # adds three methods - one to select
152
+ # another to return if a radio button is selected, and
153
+ # another method to return a radio_button element
154
+ #
155
+ # Example: radio_button(:north, {:id => "north"})
156
+ # will generate 'select_north'
157
+ # 'north_selected?' and 'north_radio_button' methods
158
+ #
159
+ # @param the name used for the generated methods
160
+ # @param identifier how we find a radio_button. The valid values are:
161
+ # :class
162
+ # :id
163
+ # :index
164
+ # :name
165
+ # :xpath
166
+ #
167
+ def radio_button(name, identifier)
168
+ identifier = Elements::RadioButton.identifier_for identifier
169
+ define_method("select_#{name}") do
170
+ puts "select_#{name} method generated"
171
+ driver.radio(identifier).set
172
+ end
173
+ define_method("#{name}_selected?") do
174
+ puts "#{name}_selected method generated"
175
+ driver.radio(identifier).set?
176
+ end
177
+ define_method("#{name}_radio_button") do
178
+ puts "#{name}_radio_button method generated"
179
+ driver.radio(identifier)
180
+ end
181
+ end
182
+ #
183
+ # adds two methods - one to click a button and another to
184
+ # return the button element.
185
+ #
186
+ # Example: button(:purchase, :id => 'purchase')
187
+ # will generate a 'purchase' and 'purchase_button' methods.
188
+ #
189
+ # @param the name used for the generated methods
190
+ # @param identifier how we find a button. The valid values are:
191
+ # :class
192
+ # :id
193
+ # :index
194
+ # :name
195
+ # :text
196
+ # :xpath
197
+ #
198
+ def button(name, identifier)
199
+ identifier = Elements::Button.identifier_for identifier
200
+ define_method(name) do
201
+ puts "#{name} method generated"
202
+ driver.button(identifier).click
203
+ end
204
+ define_method("#{name}_button") do
205
+ puts "#{name}_button method generated"
206
+ driver.button(identifier)
207
+ end
208
+ end
209
+ #
210
+ # adds two methods - one to retrieve the text from a div
211
+ # and another to return the div element
212
+ #
213
+ # Example: div(:message, {:id => 'message'})
214
+ # will generate a 'message' and 'message_div' methods
215
+ #
216
+ # @param the name used for the generated methods
217
+ # @param identifier how we find a div. The valid values are:
218
+ # :class
219
+ # :id
220
+ # :index
221
+ # :xpath
222
+ # :name
223
+ #
224
+ def div(name, identifier)
225
+ identifier = add_tagname_if_needed identifier, "div"
226
+ identifier = Elements::Div.identifier_for identifier
227
+ define_method(name) do
228
+ puts "#{name} method generated"
229
+ driver.div(identifier).text
230
+ end
231
+ define_method("#{name}_div") do
232
+ puts "#{name}_div method generated"
233
+ driver.div(identifier)
234
+ end
235
+ end
236
+ #
237
+ # adds a method to retrieve the table element
238
+ #
239
+ # Example: table(:cart, :id => 'shopping_cart')
240
+ # will generate a 'cart_table' method.
241
+ #
242
+ # @param the name used for the generated methods
243
+ # @param identifier how we find a table. The valid values are:
244
+ # :class
245
+ # :id
246
+ # :index
247
+ # :xpath
248
+ # :name
249
+ #
250
+ def table(name, identifier)
251
+ identifier = add_tagname_if_needed identifier, "table"
252
+ identifier = Elements::Table.identifier_for identifier
253
+ define_method("#{name}_table") do
254
+ puts "#{name}_table method generated"
255
+ element = driver.table(identifier)
256
+ Druid::Elements::Table.new(element)
257
+ end
258
+ end
259
+ #
260
+ # adds two methods one to retrieve the text from a table cell
261
+ # and another to return the table cell element
262
+ #
263
+ # Example: cell(:total, :id => 'total_cell')
264
+ # will generate a 'total' and 'total_cell' methods
265
+ #
266
+ # @param the name used for the generated methods
267
+ # @param identifier how we find a cell. The valid values are:
268
+ # :class
269
+ # :id
270
+ # :index
271
+ # :xpath
272
+ # :name
273
+ #
274
+ def cell(name, identifier)
275
+ identifier = add_tagname_if_needed identifier, "td"
276
+ identifier = Elements::TableCell.identifier_for identifier
277
+ define_method(name) do
278
+ puts "#{name} method generated"
279
+ driver.td(identifier).text
280
+ end
281
+ define_method("#{name}_cell") do
282
+ puts "#{name}_cell method generated"
283
+ driver.td(identifier)
284
+ end
285
+ end
286
+ #
287
+ # adds two methods - one to retrieve the text from a span
288
+ # and another to return the span element
289
+ #
290
+ # Example: span(:alert, {:id => 'alert'})
291
+ # will generate a 'alert' and 'alert_div' methods
292
+ #
293
+ # @param the name used for the generated methods
294
+ # @param identifier how we find a span. The valid values are:
295
+ # :class
296
+ # :id
297
+ # :index
298
+ # :xpath
299
+ # :name
300
+ #
301
+ def span(name, identifier)
302
+ identifier = add_tagname_if_needed identifier, "span"
303
+ identifier = Elements::Span.identifier_for identifier
304
+ define_method(name) do
305
+ puts "#{name} method generated"
306
+ driver.span(identifier).text
307
+ end
308
+ define_method("#{name}_span") do
309
+ puts "#{name}_span method generated"
310
+ driver.span(identifier)
311
+ end
312
+ end
313
+ #
314
+ # adds a method to retrieve the image element
315
+ #
316
+ # Example: image(:photo, :id => 'photo_id')
317
+ # will generate a 'photo_image' method.
318
+ #
319
+ # @param the name used for the generated methods
320
+ # @param identifier how we find a image. The valid values are:
321
+ # :class
322
+ # :id
323
+ # :index
324
+ # :name
325
+ # :xpath
326
+ #
327
+ def image(name, identifier)
328
+ identifier = Elements::Image.identifier_for identifier
329
+ define_method("#{name}_image") do
330
+ puts "#{name}_image method generated"
331
+ driver.image(identifier)
332
+ end
333
+ end
334
+ #
335
+ # adds a method to retrieve the form element
336
+ #
337
+ # @example
338
+ # form(:login, :id => 'login')
339
+ # # will generate a 'login_form' method
340
+ #
341
+ # @param [String] the name used for the generated methods
342
+ # @param [Hash] identifier how we find a form. The valid keys are:
343
+ # * :class
344
+ # * :id
345
+ # * :index
346
+ # * :xpath
347
+ # * :name
348
+ #
349
+ def form(name, identifier)
350
+ identifier = Elements::Form.identifier_for identifier
351
+ define_method("#{name}_form") do
352
+ puts "#{name}_form method generated"
353
+ driver.form(identifier)
354
+ end
355
+ end
356
+ #
357
+ # adds two methods to the page object - one to get the text from a hidden field
358
+ # and another to retrieve the hidden field element.
359
+ #
360
+ # @example
361
+ # hidden_field(:user_id, :id => "user_identity")
362
+ # # will generate 'user_id' and 'user_id_hidden_field' methods
363
+ #
364
+ # @param [String] the name used for the generated methods
365
+ # @param [Hash] identifier how we find a hidden field. The valid keys are:
366
+ # * :class
367
+ # * :css
368
+ # * :id
369
+ # * :index
370
+ # * :name
371
+ # * :tag_name
372
+ # * :text
373
+ # * :xpath
374
+ #
375
+ def hidden_field(name, identifier)
376
+ identifier = Elements::HiddenField.identifier_for identifier
377
+ define_method("#{name}_hidden_field") do
378
+ puts "#{name}_hidden_field method generated"
379
+ driver.hidden(identifier)
380
+ end
381
+ define_method(name) do
382
+ puts "#{name} method generated"
383
+ driver.hidden(identifier).value
384
+ end
385
+ end
386
+ #
387
+ # adds two methods - one to retrieve the text from a list item
388
+ # and another to return the list item element
389
+ #
390
+ # @example
391
+ # list_item(:item_one, :id => 'one')
392
+ # # will generate 'item_one' and 'item_one_list_item' methods
393
+ #
394
+ # @param [String] the name used for the generated methods
395
+ # @param [Hash] identifier how we find a list item. The valid keys are:
396
+ # * :class
397
+ # * :id
398
+ # * :index
399
+ # * :xpath
400
+ # * :name
401
+ #
402
+ def list_item(name, identifier)
403
+ identifier = add_tagname_if_needed identifier, "li"
404
+ identifier = Elements::ListItem.identifier_for identifier
405
+ define_method(name) do
406
+ puts "#{name} method generated"
407
+ driver.li(identifier).text
408
+ end
409
+ define_method("#{name}_list_item") do
410
+ puts "#{name}_list_item method generated"
411
+ driver.li(identifier)
412
+ end
413
+ end
414
+ #
415
+ # adds a method to retrieve the ordered list element
416
+ #
417
+ # @example
418
+ # ordered_list(:top_five, :id => 'top')
419
+ # # will generate a 'top_five_ordered_list' method
420
+ #
421
+ # @param [String] the name used for the generated methods
422
+ # @param [Hash] identifier how we find an ordered list. The valid keys are:
423
+ # * :class
424
+ # * :id
425
+ # * :index
426
+ # * :xpath
427
+ # * :name
428
+ #
429
+ def ordered_list(name, identifier)
430
+ identifier = add_tagname_if_needed identifier, "ol"
431
+ identifier = Elements::OrderedList.identifier_for identifier
432
+ define_method("#{name}_ordered_list") do
433
+ puts "#{name}_ordered_list method generated"
434
+ element = driver.ol(identifier)
435
+ Druid::Elements::OrderedList.new(element)
436
+ end
437
+ end
438
+ #
439
+ # adds three methods to the page object - one to set text in a text area,
440
+ # another to retrieve text from a text area and another to return the text
441
+ # area element.
442
+ #
443
+ # @example
444
+ # text_area(:address, :id => "address")
445
+ # # will generate 'address', 'address=' and 'address_text_area methods
446
+ #
447
+ # @param [String] the name used for the generated methods
448
+ # @param [Hash] identifier how we find a text area. The valid keys are:
449
+ # * :class
450
+ # * :css
451
+ # * :id
452
+ # * :index
453
+ # * :name
454
+ # * :tag_name
455
+ # * :xpath
456
+ #
457
+ def text_area(name, identifier)
458
+ identifier = Elements::TextArea.identifier_for identifier
459
+ define_method("#{name}=") do |value|
460
+ puts "#{name}= method generated"
461
+ driver.textarea(identifier).send_keys value
462
+ end
463
+ define_method("#{name}") do
464
+ puts "#{name} method generated"
465
+ driver.textarea(identifier).value
466
+ end
467
+ define_method("#{name}_text_area") do
468
+ puts "#{name}_text_area method generated"
469
+ driver.textarea(identifier)
470
+ end
471
+ end
472
+ #
473
+ # adds a method to retrieve the unordered list element
474
+ #
475
+ # @example
476
+ # unordered_list(:menu, :id => 'main_menu')
477
+ # # will generate a 'menu_unordered_list' method
478
+ #
479
+ # @param [String] the name used for the generated methods
480
+ # @param [Hash] identifier how we find an unordered list. The valid keys are:
481
+ # * :class
482
+ # * :id
483
+ # * :index
484
+ # * :xpath
485
+ # * :name
486
+ #
487
+ def unordered_list(name, identifier)
488
+ identifier = add_tagname_if_needed identifier, "ul"
489
+ identifier = Elements::UnOrderedList.identifier_for identifier
490
+ define_method("#{name}_unordered_list") do
491
+ puts "#{name}_unordered_list method generated"
492
+ element = driver.ul(identifier)
493
+ Druid::Elements::UnOrderedList.new(element)
494
+ end
495
+ end
496
+
497
+ private
498
+
499
+ def add_tagname_if_needed identifier, tag
500
+ return identifier if identifier.length < 2 and not identifier[:name]
501
+ identifier[:tag_name] = tag if identifier[:name]
502
+ identifier
503
+ end
504
+ end
505
+
506
+ end