watir-page-helper 1.0.3

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 (43) hide show
  1. data/.gitignore +24 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +2 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile.lock +55 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +88 -0
  9. data/Rakefile +6 -0
  10. data/features/README.md +47 -0
  11. data/features/simple_elements/README.md +13 -0
  12. data/features/simple_elements/div.feature +27 -0
  13. data/features/simple_elements/h1.feature +27 -0
  14. data/features/simple_elements/h2.feature +27 -0
  15. data/features/simple_elements/h3.feature +27 -0
  16. data/features/simple_elements/h4.feature +27 -0
  17. data/features/simple_elements/h5.feature +27 -0
  18. data/features/simple_elements/h6.feature +27 -0
  19. data/features/simple_elements/p.feature +27 -0
  20. data/features/simple_elements/span.feature +27 -0
  21. data/features/step_definitions/steps.rb +11 -0
  22. data/features/support/env.rb +32 -0
  23. data/history.md +10 -0
  24. data/lib/watir-page-helper.rb +231 -0
  25. data/lib/watir-page-helper/commands.rb +64 -0
  26. data/lib/watir-page-helper/generated.rb +388 -0
  27. data/script/generate +39 -0
  28. data/script/templates/generated.rb.erb +90 -0
  29. data/script/templates/simple_element.feature.erb +27 -0
  30. data/script/templates/test.html.erb +10 -0
  31. data/spec/example1.rb +19 -0
  32. data/spec/example2.rb +12 -0
  33. data/spec/helper.rb +12 -0
  34. data/spec/iframe.html +9 -0
  35. data/spec/image.png +0 -0
  36. data/spec/pages.rb +118 -0
  37. data/spec/test.html +103 -0
  38. data/spec/test.png +0 -0
  39. data/spec/watir-page-helper/pages/my_page.rb +9 -0
  40. data/spec/watir-page-helper/pages/nested_table_page.rb +8 -0
  41. data/spec/watir-page-helper_spec.rb +235 -0
  42. data/watir-page-helper.gemspec +35 -0
  43. metadata +189 -0
@@ -0,0 +1,27 @@
1
+ Feature: h6
2
+ As a web developer
3
+ I want to locate h6 elements
4
+ So that I can write tests that make assertions about their content
5
+
6
+ Background:
7
+ When I define a page class as:
8
+ """
9
+ class PageWithH6 < BasePageClass
10
+ include WatirPageHelper
11
+ h6 :element, :id => 'h6_identifier'
12
+ end
13
+ """
14
+
15
+ Scenario: h6 element is located
16
+ Then I should be able to locate the element with the following code:
17
+ """
18
+ page = PageWithH6.new true
19
+ page.element_h6.exists?.should be_true
20
+ """
21
+
22
+ Scenario: h6 text is extracted
23
+ Then I should be able to execute the following assertion:
24
+ """
25
+ page = PageWithH6.new true
26
+ page.element.should == 'h6 expected content'
27
+ """
@@ -0,0 +1,27 @@
1
+ Feature: p
2
+ As a web developer
3
+ I want to locate p elements
4
+ So that I can write tests that make assertions about their content
5
+
6
+ Background:
7
+ When I define a page class as:
8
+ """
9
+ class PageWithP < BasePageClass
10
+ include WatirPageHelper
11
+ p :element, :id => 'p_identifier'
12
+ end
13
+ """
14
+
15
+ Scenario: p element is located
16
+ Then I should be able to locate the element with the following code:
17
+ """
18
+ page = PageWithP.new true
19
+ page.element_p.exists?.should be_true
20
+ """
21
+
22
+ Scenario: p text is extracted
23
+ Then I should be able to execute the following assertion:
24
+ """
25
+ page = PageWithP.new true
26
+ page.element.should == 'p expected content'
27
+ """
@@ -0,0 +1,27 @@
1
+ Feature: span
2
+ As a web developer
3
+ I want to locate span elements
4
+ So that I can write tests that make assertions about their content
5
+
6
+ Background:
7
+ When I define a page class as:
8
+ """
9
+ class PageWithSPAN < BasePageClass
10
+ include WatirPageHelper
11
+ span :element, :id => 'span_identifier'
12
+ end
13
+ """
14
+
15
+ Scenario: span element is located
16
+ Then I should be able to locate the element with the following code:
17
+ """
18
+ page = PageWithSPAN.new true
19
+ page.element_span.exists?.should be_true
20
+ """
21
+
22
+ Scenario: span text is extracted
23
+ Then I should be able to execute the following assertion:
24
+ """
25
+ page = PageWithSPAN.new true
26
+ page.element.should == 'span expected content'
27
+ """
@@ -0,0 +1,11 @@
1
+ When /^I define a page class as:$/ do |string|
2
+ eval string
3
+ end
4
+
5
+ Then /^I should be able to locate the element with the following code:$/ do |string|
6
+ eval string
7
+ end
8
+
9
+ Then /^I should be able to execute the following assertion:$/ do |string|
10
+ eval string
11
+ end
@@ -0,0 +1,32 @@
1
+ $: << File.join(Dir.pwd, 'lib')
2
+
3
+ require 'watir-page-helper'
4
+ require 'watir-webdriver'
5
+
6
+ module Browser
7
+ BROWSER = Watir::Browser.new
8
+ end
9
+
10
+ World Browser
11
+
12
+ class BasePageClass
13
+ include WatirPageHelper
14
+
15
+ direct_url "file://#{File.expand_path(File.dirname(__FILE__))}/test.html"
16
+
17
+ def initialize visit = false
18
+ @browser = Browser::BROWSER
19
+ goto if visit
20
+
21
+ expected_element if respond_to? :expected_element
22
+ has_expected_title? if respond_to? :has_expected_title?
23
+ end
24
+
25
+ def method_missing sym, *args, &block
26
+ @browser.send sym, *args, &block
27
+ end
28
+ end
29
+
30
+ at_exit do
31
+ Browser::BROWSER.close
32
+ end
@@ -0,0 +1,10 @@
1
+ # Gem History
2
+
3
+ ## 1.0.1 - 14 Mar 2012
4
+
5
+ * Removed support for ripl as causing dependency conflicts on certain plaforms. See ripl-watir for this: http://rubygems.org/gems/ripl-watir
6
+
7
+ ## 1.0.0 - 28 Feb 2012
8
+
9
+ * Added ability to extend WatirPageHelper::Page class and not have to write own 'on' and 'visit' methods
10
+ * Added support for ripl: see http://bit.ly/ripl-watir
@@ -0,0 +1,231 @@
1
+ require 'watir-page-helper/generated.rb'
2
+
3
+ # A helper mixin to make accessing web elements via Watir-WebDriver easier.
4
+ ## This module assumes there is a @browser variable available.
5
+ module WatirPageHelper
6
+
7
+ # A method that is called when this Module is included into a class
8
+ # @param [Class] cls The class that this module is being included in the literal expected title for the page
9
+ # @return [Nil]
10
+ def self.included(cls)
11
+ cls.extend ClassMethods
12
+ end
13
+
14
+ # A collection of class methods that generate helper methods that are mixed into a calling class.
15
+ module ClassMethods
16
+
17
+ # Creates a method that compares the expected_title of a page against the actual.
18
+ # @param [String] expected_title the literal expected title for the page
19
+ # @param [Regexp] expected_title the expected title pattern for the page
20
+ # @return [Nil]
21
+ # @raise An exception if expected_title does not match actual title
22
+ #
23
+ # @example Specify 'Google' as the expected title of a page
24
+ # expected_title "Google"
25
+ # page.has_expected_title?
26
+ def expected_title expected_title
27
+ define_method("has_expected_title?") do
28
+ has_expected_title = expected_title.kind_of?(Regexp) ? expected_title =~ @browser.title : expected_title == @browser.title
29
+ raise "Expected title '#{expected_title}' instead of '#{@browser.title}'" unless has_expected_title
30
+ end
31
+ end
32
+
33
+ # Creates a method that provides a way to initialize a page based upon an expected element.
34
+ # This is useful for pages that load dynamic content.
35
+ # @param [Symbol] type the type of element you are expecting
36
+ # @param [Hash] identifier the name, value pair used to identify the object
37
+ # @param [optional, Integer] timeout default value is 30 seconds
38
+ # @return [Nil]
39
+ #
40
+ # @example Specify a text box as expected on the page within 10 seconds
41
+ # expected_element(:text_field, :name => "firstname", 10)
42
+ # page.expected_element
43
+ def expected_element type, identifier, timeout=30
44
+ define_method("expected_element") do
45
+ @browser.send("#{type.to_s}", identifier).wait_until_present timeout
46
+ end
47
+ end
48
+
49
+ # Provides a way to define a direct URL for a page, and creates a method for the page to go to that URL.
50
+ # @param [String] url the URL to directly access the page
51
+ # @return [Nil]
52
+ #
53
+ # @example Set the direct URL for the Google Home Page
54
+ # direct_url "http://www.google.com"
55
+ # page.goto # navigates to the Google URL
56
+ def direct_url url
57
+ define_method("goto") do
58
+ @browser.goto url
59
+ end
60
+ end
61
+
62
+ # Generates four select_list methods to:
63
+ # * get the value specified in a select_list
64
+ # * select a value in a select list;
65
+ # * see whether a value is selected; and
66
+ # * return the select_list element.
67
+ #
68
+ # @param [Symbol] name The name of the select_list element (used to generate the methods)
69
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
70
+ # @param block
71
+ # @return [Nil]
72
+ #
73
+ # @example Specify a select list to generate methods
74
+ # select_list :cars, :name => "cars"
75
+ # page.cars = "Mazda" #select
76
+ # page.cars.should == "Mazda" #check
77
+ # page.cars_selected?("Mazda").should be_true #selected?
78
+ # page.cars_select_list.exists?.should be_true #object
79
+ def select_list name, identifier=nil, &block
80
+ define_method(name) do
81
+ self.send("#{name}_select_list").value
82
+ end
83
+ define_method("#{name}=") do |value|
84
+ self.send("#{name}_select_list").select(value)
85
+ end
86
+ define_method("#{name}_selected?") do |value|
87
+ self.send("#{name}_select_list").selected?(value)
88
+ end
89
+ create_element_getter "#{name}_select_list", identifier, __method__, block
90
+ end
91
+
92
+ # Generates four checkbox methods to:
93
+ # * check the checkbox;
94
+ # * uncheck the checkbox;
95
+ # * see whether a the checkbox is checked; and
96
+ # * return the checkbox element.
97
+ #
98
+ # @param [Symbol] name The name of the checkbox element (used to generate the methods)
99
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
100
+ # @param block
101
+ # @return [Nil]
102
+ #
103
+ # @example Specify a checkbox to generate methods
104
+ # checkbox :agree, :name => "agree"
105
+ # page.check_agree
106
+ # page.agree?.should be_true
107
+ # page.uncheck_agree
108
+ # page.agree?.should be_false
109
+ # page.agree_checkbox.exist?.should be_true
110
+ def checkbox name, identifier=nil, &block
111
+ define_method("check_#{name}") do
112
+ self.send("#{name}_checkbox").set
113
+ end
114
+ define_method("uncheck_#{name}") do
115
+ self.send("#{name}_checkbox").clear
116
+ end
117
+ define_method("#{name}?") do
118
+ self.send("#{name}_checkbox").set?
119
+ end
120
+ create_element_getter "#{name}_checkbox", identifier, __method__, block
121
+ end
122
+
123
+ # Generates three radio methods to:
124
+ # * select a radio;
125
+ # * see whether a radio is selected; and
126
+ # * return the radio element.
127
+ #
128
+ # @param [Symbol] name The name of the radio element (used to generate the methods)
129
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
130
+ # @param block
131
+ # @return [Nil]
132
+ #
133
+ # @example Specify a radio button to generate methods
134
+ # radio :medium, :value => "Medium"
135
+ # page.select_medium
136
+ # page.medium_set?.should be_true
137
+ # page.medium_radio.exist?.should be_true
138
+ def radio name, identifier=nil, &block
139
+ define_method("select_#{name}") do
140
+ self.send("#{name}_radio").set
141
+ end
142
+ define_method("#{name}_set?") do
143
+ self.send("#{name}_radio").set?
144
+ end
145
+ create_element_getter "#{name}_radio", identifier, __method__, block
146
+ create_element_getter "#{name}_radio_button", identifier, __method__, block
147
+ end
148
+
149
+ def radio_button name, identifier=nil, &block
150
+ warn 'radio_button is a deprecated method in the watir-page-helper gem, and will be removed in future versions.'
151
+ radio name, identifier, &block
152
+ end
153
+
154
+ # Generates two row methods to:
155
+ # * return the text from a table row;
156
+ # * return the row element.
157
+ #
158
+ # @param [Symbol] name The name of the row element (used to generate the methods)
159
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
160
+ # @param block
161
+ # @return [Nil]
162
+ #
163
+ # @example Specify a row to generate methods
164
+ # row(:test_table_row_1) { | test_table | test_table.tr }
165
+ # page.test_table_row_1.should == "Test Table Col 1 Test Table Col 2"
166
+ # page.test_table_row_1_row.cells.length.should == 2
167
+ def row name, identifier=nil, &block
168
+ define_method(name) do
169
+ self.send("#{name}_row").text
170
+ end
171
+ create_element_getter "#{name}_row", identifier, 'tr', block
172
+ end
173
+
174
+ # Generates two row methods to:
175
+ # * return the text from a table cell;
176
+ # * return the cell element.
177
+ #
178
+ # @param [Symbol] name The name of the cell element (used to generate the methods)
179
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
180
+ # @param block
181
+ # @return [Nil]
182
+ #
183
+ # @example Specify a cell to generate methods
184
+ # cell(:test_table_row_1_cell_1) { |test_table_row_1 | test_table_row_1.td }
185
+ # page.test_table_row_1_cell_1.should == "Test Table Col 1"
186
+ # page.test_table_row_1_cell_1_cell.exist?.should be_true
187
+ def cell name, identifier=nil, &block
188
+ define_method(name) do
189
+ self.send("#{name}_cell").text
190
+ end
191
+ create_element_getter "#{name}_cell", identifier, 'td', block
192
+ end
193
+
194
+
195
+ # Generates two file_field methods to:
196
+ # * return the text from a file field;
197
+ # * set a file field
198
+ #
199
+ # @param [Symbol] name The name of the file field element (used to generate the methods)
200
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
201
+ # @param block
202
+ # @return [Nil]
203
+ #
204
+ # @example Specify a file_field to generate methods
205
+ # file_field :upload, :id => 'upload'
206
+ # page.upload = image_path #set
207
+ # page.upload.should == image_path #check
208
+ def file_field name, identifier=nil, &block
209
+ define_method(name) do
210
+ self.send("#{name}_file_field").value
211
+ end
212
+ define_method("#{name}=") do |value|
213
+ self.send("#{name}_file_field").set value
214
+ end
215
+ create_element_getter "#{name}_file_field", identifier, __method__, block
216
+ end
217
+
218
+ private
219
+
220
+ def create_element_getter name, identifier, type, block
221
+ define_method name do
222
+ if block
223
+ block.arity == 1 ? block.call(self) : self.instance_eval(&block)
224
+ else
225
+ identifier.nil? ? @browser.send(type) : @browser.send(type, identifier)
226
+ end
227
+ end
228
+ end
229
+
230
+ end
231
+ end
@@ -0,0 +1,64 @@
1
+ require 'watir-page-helper'
2
+ require 'watir-webdriver'
3
+ require 'forwardable'
4
+
5
+ module WatirPageHelper
6
+ class Page
7
+ include WatirPageHelper
8
+ extend Forwardable
9
+ attr_reader :browser
10
+
11
+ def_delegators :@browser, :title, :url, :html, :status, :refresh, :back
12
+
13
+ def initialize browser
14
+ @browser = browser
15
+ end
16
+ end
17
+
18
+ class << self
19
+ attr_accessor :browser
20
+
21
+ def create
22
+ @browser = ::Watir::Browser.new ENV['WEBDRIVER'] || :firefox
23
+ end
24
+
25
+ def close
26
+ @browser.close
27
+ end
28
+ end
29
+
30
+ module Commands
31
+ def classify s
32
+ s.to_s.split('_').map(&:capitalize).join
33
+ end
34
+
35
+ def page_class *args
36
+ return args.first.new WatirPageHelper.browser if args.first.is_a? Class
37
+ page = WatirPageHelper::Page.new WatirPageHelper.browser
38
+ require "watir-page-helper/pages/#{args.join '/'}"
39
+ mod = WatirPageHelper
40
+ args.each do |name|
41
+ mod = mod.const_get classify name
42
+ end
43
+ page.extend mod
44
+ page
45
+ end
46
+
47
+ def on *args
48
+ page_class(*args).tap do |p|
49
+ p.expected_element if p.respond_to? :expected_element
50
+ p.has_expected_title? if p.respond_to? :has_expected_title?
51
+ yield p if block_given?
52
+ end
53
+ end
54
+
55
+ def visit *args
56
+ page_class(*args).tap do |p|
57
+ p.goto
58
+ p.expected_element if p.respond_to? :expected_element
59
+ p.has_expected_title? if p.respond_to? :has_expected_title?
60
+ yield p if block_given?
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,388 @@
1
+ module WatirPageHelper
2
+ module ClassMethods
3
+
4
+ # Generates two h1 methods to:
5
+ # * return the text from a h1;
6
+ # * return the h1 element.
7
+ #
8
+ # @param [Symbol] name The name of the h1 element (used to generate the methods)
9
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
10
+ # @param block
11
+ # @return [Nil]
12
+ #
13
+ # @example Specify a h1 to generate methods
14
+ # h1 :my_element, :id => "my_element"
15
+ # page.my_element.should == "My Element Text"
16
+ # page.my_element_h1.exist?.should be_true
17
+ def h1 name, identifier=nil, &block
18
+ define_method(name) do
19
+ self.send("#{name}_h1").text
20
+ end
21
+ create_element_getter "#{name}_h1", identifier, __method__, block
22
+ end
23
+
24
+ # Generates two h2 methods to:
25
+ # * return the text from a h2;
26
+ # * return the h2 element.
27
+ #
28
+ # @param [Symbol] name The name of the h2 element (used to generate the methods)
29
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
30
+ # @param block
31
+ # @return [Nil]
32
+ #
33
+ # @example Specify a h2 to generate methods
34
+ # h2 :my_element, :id => "my_element"
35
+ # page.my_element.should == "My Element Text"
36
+ # page.my_element_h2.exist?.should be_true
37
+ def h2 name, identifier=nil, &block
38
+ define_method(name) do
39
+ self.send("#{name}_h2").text
40
+ end
41
+ create_element_getter "#{name}_h2", identifier, __method__, block
42
+ end
43
+
44
+ # Generates two h3 methods to:
45
+ # * return the text from a h3;
46
+ # * return the h3 element.
47
+ #
48
+ # @param [Symbol] name The name of the h3 element (used to generate the methods)
49
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
50
+ # @param block
51
+ # @return [Nil]
52
+ #
53
+ # @example Specify a h3 to generate methods
54
+ # h3 :my_element, :id => "my_element"
55
+ # page.my_element.should == "My Element Text"
56
+ # page.my_element_h3.exist?.should be_true
57
+ def h3 name, identifier=nil, &block
58
+ define_method(name) do
59
+ self.send("#{name}_h3").text
60
+ end
61
+ create_element_getter "#{name}_h3", identifier, __method__, block
62
+ end
63
+
64
+ # Generates two h4 methods to:
65
+ # * return the text from a h4;
66
+ # * return the h4 element.
67
+ #
68
+ # @param [Symbol] name The name of the h4 element (used to generate the methods)
69
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
70
+ # @param block
71
+ # @return [Nil]
72
+ #
73
+ # @example Specify a h4 to generate methods
74
+ # h4 :my_element, :id => "my_element"
75
+ # page.my_element.should == "My Element Text"
76
+ # page.my_element_h4.exist?.should be_true
77
+ def h4 name, identifier=nil, &block
78
+ define_method(name) do
79
+ self.send("#{name}_h4").text
80
+ end
81
+ create_element_getter "#{name}_h4", identifier, __method__, block
82
+ end
83
+
84
+ # Generates two h5 methods to:
85
+ # * return the text from a h5;
86
+ # * return the h5 element.
87
+ #
88
+ # @param [Symbol] name The name of the h5 element (used to generate the methods)
89
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
90
+ # @param block
91
+ # @return [Nil]
92
+ #
93
+ # @example Specify a h5 to generate methods
94
+ # h5 :my_element, :id => "my_element"
95
+ # page.my_element.should == "My Element Text"
96
+ # page.my_element_h5.exist?.should be_true
97
+ def h5 name, identifier=nil, &block
98
+ define_method(name) do
99
+ self.send("#{name}_h5").text
100
+ end
101
+ create_element_getter "#{name}_h5", identifier, __method__, block
102
+ end
103
+
104
+ # Generates two h6 methods to:
105
+ # * return the text from a h6;
106
+ # * return the h6 element.
107
+ #
108
+ # @param [Symbol] name The name of the h6 element (used to generate the methods)
109
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
110
+ # @param block
111
+ # @return [Nil]
112
+ #
113
+ # @example Specify a h6 to generate methods
114
+ # h6 :my_element, :id => "my_element"
115
+ # page.my_element.should == "My Element Text"
116
+ # page.my_element_h6.exist?.should be_true
117
+ def h6 name, identifier=nil, &block
118
+ define_method(name) do
119
+ self.send("#{name}_h6").text
120
+ end
121
+ create_element_getter "#{name}_h6", identifier, __method__, block
122
+ end
123
+
124
+ # Generates two div methods to:
125
+ # * return the text from a div;
126
+ # * return the div element.
127
+ #
128
+ # @param [Symbol] name The name of the div element (used to generate the methods)
129
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
130
+ # @param block
131
+ # @return [Nil]
132
+ #
133
+ # @example Specify a div to generate methods
134
+ # div :my_element, :id => "my_element"
135
+ # page.my_element.should == "My Element Text"
136
+ # page.my_element_div.exist?.should be_true
137
+ def div name, identifier=nil, &block
138
+ define_method(name) do
139
+ self.send("#{name}_div").text
140
+ end
141
+ create_element_getter "#{name}_div", identifier, __method__, block
142
+ end
143
+
144
+ # Generates two span methods to:
145
+ # * return the text from a span;
146
+ # * return the span element.
147
+ #
148
+ # @param [Symbol] name The name of the span element (used to generate the methods)
149
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
150
+ # @param block
151
+ # @return [Nil]
152
+ #
153
+ # @example Specify a span to generate methods
154
+ # span :my_element, :id => "my_element"
155
+ # page.my_element.should == "My Element Text"
156
+ # page.my_element_span.exist?.should be_true
157
+ def span name, identifier=nil, &block
158
+ define_method(name) do
159
+ self.send("#{name}_span").text
160
+ end
161
+ create_element_getter "#{name}_span", identifier, __method__, block
162
+ end
163
+
164
+ # Generates two p methods to:
165
+ # * return the text from a p;
166
+ # * return the p element.
167
+ #
168
+ # @param [Symbol] name The name of the p element (used to generate the methods)
169
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
170
+ # @param block
171
+ # @return [Nil]
172
+ #
173
+ # @example Specify a p to generate methods
174
+ # p :my_element, :id => "my_element"
175
+ # page.my_element.should == "My Element Text"
176
+ # page.my_element_p.exist?.should be_true
177
+ def p name, identifier=nil, &block
178
+ define_method(name) do
179
+ self.send("#{name}_p").text
180
+ end
181
+ create_element_getter "#{name}_p", identifier, __method__, block
182
+ end
183
+
184
+ # Generates two dl methods to:
185
+ # * return the text from a dl;
186
+ # * return the dl element.
187
+ #
188
+ # @param [Symbol] name The name of the dl element (used to generate the methods)
189
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
190
+ # @param block
191
+ # @return [Nil]
192
+ #
193
+ # @example Specify a dl to generate methods
194
+ # dl :my_element, :id => "my_element"
195
+ # page.my_element.should == "My Element Text"
196
+ # page.my_element_dl.exist?.should be_true
197
+ def dl name, identifier=nil, &block
198
+ define_method(name) do
199
+ self.send("#{name}_dl").text
200
+ end
201
+ create_element_getter "#{name}_dl", identifier, __method__, block
202
+ end
203
+
204
+ # Generates two dd methods to:
205
+ # * return the text from a dd;
206
+ # * return the dd element.
207
+ #
208
+ # @param [Symbol] name The name of the dd element (used to generate the methods)
209
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
210
+ # @param block
211
+ # @return [Nil]
212
+ #
213
+ # @example Specify a dd to generate methods
214
+ # dd :my_element, :id => "my_element"
215
+ # page.my_element.should == "My Element Text"
216
+ # page.my_element_dd.exist?.should be_true
217
+ def dd name, identifier=nil, &block
218
+ define_method(name) do
219
+ self.send("#{name}_dd").text
220
+ end
221
+ create_element_getter "#{name}_dd", identifier, __method__, block
222
+ end
223
+
224
+ # Generates two dt methods to:
225
+ # * return the text from a dt;
226
+ # * return the dt element.
227
+ #
228
+ # @param [Symbol] name The name of the dt element (used to generate the methods)
229
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
230
+ # @param block
231
+ # @return [Nil]
232
+ #
233
+ # @example Specify a dt to generate methods
234
+ # dt :my_element, :id => "my_element"
235
+ # page.my_element.should == "My Element Text"
236
+ # page.my_element_dt.exist?.should be_true
237
+ def dt name, identifier=nil, &block
238
+ define_method(name) do
239
+ self.send("#{name}_dt").text
240
+ end
241
+ create_element_getter "#{name}_dt", identifier, __method__, block
242
+ end
243
+
244
+ # Generates two form methods to:
245
+ # * return the text from a form;
246
+ # * return the form element.
247
+ #
248
+ # @param [Symbol] name The name of the form element (used to generate the methods)
249
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
250
+ # @param block
251
+ # @return [Nil]
252
+ #
253
+ # @example Specify a form to generate methods
254
+ # form :my_element, :id => "my_element"
255
+ # page.my_element.should == "My Element Text"
256
+ # page.my_element_form.exist?.should be_true
257
+ def form name, identifier=nil, &block
258
+ define_method(name) do
259
+ self.send("#{name}_form").text
260
+ end
261
+ create_element_getter "#{name}_form", identifier, __method__, block
262
+ end
263
+
264
+ # Generates two li methods to:
265
+ # * return the text from a li;
266
+ # * return the li element.
267
+ #
268
+ # @param [Symbol] name The name of the li element (used to generate the methods)
269
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
270
+ # @param block
271
+ # @return [Nil]
272
+ #
273
+ # @example Specify a li to generate methods
274
+ # li :my_element, :id => "my_element"
275
+ # page.my_element.should == "My Element Text"
276
+ # page.my_element_li.exist?.should be_true
277
+ def li name, identifier=nil, &block
278
+ define_method(name) do
279
+ self.send("#{name}_li").text
280
+ end
281
+ create_element_getter "#{name}_li", identifier, __method__, block
282
+ end
283
+
284
+ # Generates two link methods to:
285
+ # * click a link;
286
+ # * return the link element.
287
+ #
288
+ # @param [Symbol] name The name of the link element (used to generate the methods)
289
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
290
+ # @param block
291
+ # @return [Nil]
292
+ #
293
+ # @example Specify a link to generate methods
294
+ # link :info, :text => "Information"
295
+ # page.info
296
+ # page.info_link.exist?.should be_true
297
+ def link name, identifier=nil, &block
298
+ define_method(name) do
299
+ self.send("#{name}_link").click
300
+ end
301
+ create_element_getter "#{name}_link", identifier, __method__, block
302
+ end
303
+
304
+ # Generates two button methods to:
305
+ # * click a button;
306
+ # * return the button element.
307
+ #
308
+ # @param [Symbol] name The name of the button element (used to generate the methods)
309
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
310
+ # @param block
311
+ # @return [Nil]
312
+ #
313
+ # @example Specify a button to generate methods
314
+ # button :info, :text => "Information"
315
+ # page.info
316
+ # page.info_button.exist?.should be_true
317
+ def button name, identifier=nil, &block
318
+ define_method(name) do
319
+ self.send("#{name}_button").click
320
+ end
321
+ create_element_getter "#{name}_button", identifier, __method__, block
322
+ end
323
+
324
+ # Generates three text_field methods to:
325
+ # * set a text_field;
326
+ # * get a text_field's value; and
327
+ # * return the text_field element.
328
+ #
329
+ # @param [Symbol] name The name of the text_field element (used to generate the methods)
330
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
331
+ # @param block
332
+ # @return [Nil]
333
+ #
334
+ # @example Specify a text_field to generate methods
335
+ # text_field first_name, :name => "firstname"
336
+ # page.first_name = "Finley" #set
337
+ # page.first_name.should == "Finley" #check
338
+ # page.first_name_text_field.exists?.should be_true #object
339
+ def text_field name, identifier=nil, &block
340
+ define_method(name) do
341
+ self.send("#{name}_text_field").value
342
+ end
343
+ define_method("#{name}=") do |value|
344
+ self.send("#{name}_text_field").set value
345
+ end
346
+ create_element_getter "#{name}_text_field", identifier, __method__, block
347
+ end
348
+
349
+ # Generates a table method to return a table element.
350
+ # @param [Symbol] name The name of the table element (used to generate the method)
351
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
352
+ # @param block
353
+ # @return [Nil]
354
+ #
355
+ # @example Specify a table to generate a method
356
+ # table :my_element, :id => 'my_element'
357
+ # page.my_element.exists?.should be_true
358
+ def table name, identifier=nil, &block
359
+ create_element_getter "#{name}", identifier, __method__, block
360
+ end
361
+
362
+ # Generates a image method to return a image element.
363
+ # @param [Symbol] name The name of the image element (used to generate the method)
364
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
365
+ # @param block
366
+ # @return [Nil]
367
+ #
368
+ # @example Specify a image to generate a method
369
+ # table :my_element, :id => 'my_element'
370
+ # page.my_element.exists?.should be_true
371
+ def image name, identifier=nil, &block
372
+ create_element_getter "#{name}", identifier, __method__, block
373
+ end
374
+
375
+ # Generates a frame method to return a frame element.
376
+ # @param [Symbol] name The name of the frame element (used to generate the method)
377
+ # @param [optional, Hash] identifier A set of key, value pairs to identify the element
378
+ # @param block
379
+ # @return [Nil]
380
+ #
381
+ # @example Specify a frame to generate a method
382
+ # table :my_element, :id => 'my_element'
383
+ # page.my_element.exists?.should be_true
384
+ def frame name, identifier=nil, &block
385
+ create_element_getter "#{name}", identifier, __method__, block
386
+ end
387
+ end
388
+ end