webrat 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.gitignore +15 -0
- data/History.txt +44 -8
- data/Rakefile +80 -66
- data/VERSION +1 -0
- data/lib/webrat.rb +7 -12
- data/lib/webrat/core/configuration.rb +7 -3
- data/lib/webrat/core/elements/area.rb +7 -7
- data/lib/webrat/core/elements/element.rb +11 -11
- data/lib/webrat/core/elements/field.rb +63 -55
- data/lib/webrat/core/elements/form.rb +17 -17
- data/lib/webrat/core/elements/label.rb +6 -6
- data/lib/webrat/core/elements/link.rb +13 -12
- data/lib/webrat/core/elements/select_option.rb +9 -9
- data/lib/webrat/core/locators.rb +2 -2
- data/lib/webrat/core/locators/area_locator.rb +10 -10
- data/lib/webrat/core/locators/button_locator.rb +13 -13
- data/lib/webrat/core/locators/field_by_id_locator.rb +8 -8
- data/lib/webrat/core/locators/field_labeled_locator.rb +11 -11
- data/lib/webrat/core/locators/field_locator.rb +7 -7
- data/lib/webrat/core/locators/field_named_locator.rb +10 -10
- data/lib/webrat/core/locators/form_locator.rb +6 -6
- data/lib/webrat/core/locators/label_locator.rb +9 -9
- data/lib/webrat/core/locators/link_locator.rb +21 -13
- data/lib/webrat/core/locators/locator.rb +5 -5
- data/lib/webrat/core/locators/select_option_locator.rb +11 -11
- data/lib/webrat/core/logging.rb +7 -4
- data/lib/webrat/core/matchers/have_content.rb +12 -12
- data/lib/webrat/core/matchers/have_selector.rb +9 -9
- data/lib/webrat/core/matchers/have_tag.rb +4 -4
- data/lib/webrat/core/matchers/have_xpath.rb +26 -26
- data/lib/webrat/core/methods.rb +13 -11
- data/lib/webrat/core/mime.rb +3 -3
- data/lib/webrat/core/save_and_open_page.rb +14 -16
- data/lib/webrat/core/scope.rb +53 -53
- data/lib/webrat/core/session.rb +23 -14
- data/lib/webrat/core/xml.rb +16 -16
- data/lib/webrat/core/xml/hpricot.rb +3 -3
- data/lib/webrat/core/xml/nokogiri.rb +11 -11
- data/lib/webrat/core/xml/rexml.rb +3 -3
- data/lib/webrat/core_extensions/blank.rb +1 -1
- data/lib/webrat/core_extensions/deprecate.rb +1 -1
- data/lib/webrat/core_extensions/detect_mapped.rb +4 -4
- data/lib/webrat/core_extensions/meta_class.rb +1 -1
- data/lib/webrat/core_extensions/tcp_socket.rb +8 -8
- data/lib/webrat/mechanize.rb +9 -9
- data/lib/webrat/merb.rb +1 -1
- data/lib/webrat/merb_multipart_support.rb +27 -0
- data/lib/webrat/merb_session.rb +39 -24
- data/lib/webrat/rack_test.rb +32 -0
- data/lib/webrat/rails.rb +2 -2
- data/lib/webrat/rspec-rails.rb +3 -6
- data/lib/webrat/selenium.rb +2 -1
- data/lib/webrat/selenium/application_server_factory.rb +40 -0
- data/lib/webrat/selenium/application_servers.rb +5 -0
- data/lib/webrat/selenium/application_servers/base.rb +46 -0
- data/lib/webrat/selenium/application_servers/external.rb +26 -0
- data/lib/webrat/selenium/application_servers/merb.rb +50 -0
- data/lib/webrat/selenium/application_servers/rails.rb +44 -0
- data/lib/webrat/selenium/application_servers/sinatra.rb +37 -0
- data/lib/webrat/selenium/location_strategy_javascript/button.js +14 -7
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +4 -1
- data/lib/webrat/selenium/matchers.rb +1 -1
- data/lib/webrat/selenium/matchers/have_content.rb +4 -4
- data/lib/webrat/selenium/matchers/have_selector.rb +4 -4
- data/lib/webrat/selenium/matchers/have_tag.rb +16 -16
- data/lib/webrat/selenium/matchers/have_xpath.rb +4 -4
- data/lib/webrat/selenium/selenium_rc_server.rb +25 -19
- data/lib/webrat/selenium/selenium_session.rb +24 -17
- data/lib/webrat/selenium/silence_stream.rb +18 -0
- data/spec/fakes/test_session.rb +34 -0
- data/spec/integration/merb/.gitignore +21 -0
- data/spec/integration/merb/Rakefile +35 -0
- data/spec/integration/merb/app/controllers/application.rb +2 -0
- data/spec/integration/merb/app/controllers/exceptions.rb +13 -0
- data/spec/integration/merb/app/controllers/testing.rb +27 -0
- data/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
- data/spec/integration/merb/app/views/exceptions/not_found.html.erb +47 -0
- data/spec/integration/merb/app/views/layout/application.html.erb +12 -0
- data/spec/integration/merb/app/views/testing/show_form.html.erb +27 -0
- data/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
- data/spec/integration/merb/config/environments/development.rb +15 -0
- data/spec/integration/merb/config/environments/rake.rb +11 -0
- data/spec/integration/merb/config/environments/test.rb +14 -0
- data/spec/integration/merb/config/init.rb +25 -0
- data/spec/integration/merb/config/rack.rb +11 -0
- data/spec/integration/merb/config/router.rb +34 -0
- data/spec/integration/merb/spec/spec.opts +1 -0
- data/spec/integration/merb/spec/spec_helper.rb +24 -0
- data/spec/integration/merb/spec/webrat_spec.rb +39 -0
- data/spec/integration/merb/tasks/merb.thor/app_script.rb +31 -0
- data/spec/integration/merb/tasks/merb.thor/common.rb +64 -0
- data/spec/integration/merb/tasks/merb.thor/gem_ext.rb +124 -0
- data/spec/integration/merb/tasks/merb.thor/main.thor +150 -0
- data/spec/integration/merb/tasks/merb.thor/ops.rb +93 -0
- data/spec/integration/merb/tasks/merb.thor/utils.rb +40 -0
- data/spec/integration/rack/Rakefile +5 -0
- data/spec/integration/rack/rack_app.rb +16 -0
- data/spec/integration/rack/test/test_helper.rb +20 -0
- data/spec/integration/rack/test/webrat_rack_test.rb +67 -0
- data/spec/integration/rails/.gitignore +3 -0
- data/spec/integration/rails/Rakefile +30 -0
- data/spec/integration/rails/app/controllers/application.rb +15 -0
- data/spec/integration/rails/app/controllers/buttons_controller.rb +7 -0
- data/spec/integration/rails/app/controllers/fields_controller.rb +4 -0
- data/spec/integration/rails/app/controllers/links_controller.rb +7 -0
- data/spec/integration/rails/app/controllers/webrat_controller.rb +43 -0
- data/spec/integration/rails/app/helpers/buttons_helper.rb +2 -0
- data/spec/integration/rails/app/helpers/fields_helper.rb +2 -0
- data/spec/integration/rails/app/helpers/links_helper.rb +2 -0
- data/spec/integration/rails/app/views/buttons/show.html.erb +11 -0
- data/spec/integration/rails/app/views/fields/show.html.erb +9 -0
- data/spec/integration/rails/app/views/links/show.html.erb +5 -0
- data/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb +4 -0
- data/spec/integration/rails/app/views/webrat/buttons.html.erb +11 -0
- data/spec/integration/rails/app/views/webrat/form.html.erb +28 -0
- data/spec/integration/rails/config/boot.rb +109 -0
- data/spec/integration/rails/config/environment.rb +12 -0
- data/spec/integration/rails/config/environments/development.rb +17 -0
- data/spec/integration/rails/config/environments/selenium.rb +22 -0
- data/spec/integration/rails/config/environments/test.rb +22 -0
- data/spec/integration/rails/config/initializers/inflections.rb +10 -0
- data/spec/integration/rails/config/initializers/mime_types.rb +5 -0
- data/spec/integration/rails/config/initializers/new_rails_defaults.rb +17 -0
- data/spec/integration/rails/config/locales/en.yml +5 -0
- data/spec/integration/rails/config/routes.rb +18 -0
- data/spec/integration/rails/public/404.html +30 -0
- data/spec/integration/rails/public/422.html +30 -0
- data/spec/integration/rails/public/500.html +33 -0
- data/spec/integration/rails/script/about +4 -0
- data/spec/integration/rails/script/console +3 -0
- data/spec/integration/rails/script/dbconsole +3 -0
- data/spec/integration/rails/script/destroy +3 -0
- data/spec/integration/rails/script/generate +3 -0
- data/spec/integration/rails/script/performance/benchmarker +3 -0
- data/spec/integration/rails/script/performance/profiler +3 -0
- data/spec/integration/rails/script/performance/request +3 -0
- data/spec/integration/rails/script/plugin +3 -0
- data/spec/integration/rails/script/process/inspector +3 -0
- data/spec/integration/rails/script/process/reaper +3 -0
- data/spec/integration/rails/script/process/spawner +3 -0
- data/spec/integration/rails/script/runner +3 -0
- data/spec/integration/rails/script/server +3 -0
- data/spec/integration/rails/test/integration/button_click_test.rb +80 -0
- data/spec/integration/rails/test/integration/fill_in_test.rb +24 -0
- data/spec/integration/rails/test/integration/link_click_test.rb +27 -0
- data/spec/integration/rails/test/integration/webrat_test.rb +97 -0
- data/spec/integration/rails/test/test_helper.rb +25 -0
- data/spec/integration/sinatra/Rakefile +5 -0
- data/spec/integration/sinatra/classic_app.rb +64 -0
- data/spec/integration/sinatra/modular_app.rb +16 -0
- data/spec/integration/sinatra/test/classic_app_test.rb +37 -0
- data/spec/integration/sinatra/test/modular_app_test.rb +18 -0
- data/spec/integration/sinatra/test/test_helper.rb +16 -0
- data/spec/private/core/configuration_spec.rb +116 -0
- data/spec/private/core/field_spec.rb +85 -0
- data/spec/private/core/link_spec.rb +24 -0
- data/spec/private/core/logging_spec.rb +10 -0
- data/spec/private/core/session_spec.rb +195 -0
- data/spec/private/mechanize/mechanize_session_spec.rb +81 -0
- data/spec/private/merb/attaches_file_spec.rb +93 -0
- data/spec/private/merb/merb_session_spec.rb +61 -0
- data/spec/private/nokogiri_spec.rb +77 -0
- data/spec/private/rails/attaches_file_spec.rb +81 -0
- data/spec/private/rails/rails_session_spec.rb +110 -0
- data/spec/private/selenium/application_servers/rails_spec.rb +26 -0
- data/spec/public/basic_auth_spec.rb +24 -0
- data/spec/public/check_spec.rb +191 -0
- data/spec/public/choose_spec.rb +118 -0
- data/spec/public/click_area_spec.rb +106 -0
- data/spec/public/click_button_spec.rb +496 -0
- data/spec/public/click_link_spec.rb +511 -0
- data/spec/public/fill_in_spec.rb +209 -0
- data/spec/public/locators/field_by_xpath_spec.rb +19 -0
- data/spec/public/locators/field_labeled_spec.rb +172 -0
- data/spec/public/locators/field_with_id_spec.rb +16 -0
- data/spec/public/matchers/contain_spec.rb +114 -0
- data/spec/public/matchers/have_selector_spec.rb +142 -0
- data/spec/public/matchers/have_tag_spec.rb +39 -0
- data/spec/public/matchers/have_xpath_spec.rb +136 -0
- data/spec/public/reload_spec.rb +10 -0
- data/spec/public/save_and_open_spec.rb +70 -0
- data/spec/public/select_date_spec.rb +112 -0
- data/spec/public/select_datetime_spec.rb +137 -0
- data/spec/public/select_spec.rb +249 -0
- data/spec/public/select_time_spec.rb +100 -0
- data/spec/public/selenium/application_server_factory_spec.rb +49 -0
- data/spec/public/selenium/application_servers/external_spec.rb +12 -0
- data/spec/public/selenium/selenium_session_spec.rb +37 -0
- data/spec/public/set_hidden_field_spec.rb +5 -0
- data/spec/public/submit_form_spec.rb +5 -0
- data/spec/public/visit_spec.rb +58 -0
- data/spec/public/within_spec.rb +177 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +50 -0
- data/vendor/selenium-server.jar +0 -0
- data/webrat.gemspec +340 -0
- metadata +248 -33
- data/lib/webrat/selenium/application_server.rb +0 -71
- data/lib/webrat/selenium/merb_application_server.rb +0 -48
- data/lib/webrat/selenium/rails_application_server.rb +0 -42
- data/lib/webrat/selenium/sinatra_application_server.rb +0 -35
@@ -8,10 +8,10 @@ module Webrat
|
|
8
8
|
# Raised when Webrat is asked to manipulate a disabled form field
|
9
9
|
class DisabledFieldError < WebratError
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
class Field < Element #:nodoc:
|
13
13
|
attr_reader :value
|
14
|
-
|
14
|
+
|
15
15
|
def self.xpath_search
|
16
16
|
[".//button", ".//input", ".//textarea", ".//select"]
|
17
17
|
end
|
@@ -19,22 +19,22 @@ module Webrat
|
|
19
19
|
def self.xpath_search_excluding_hidden
|
20
20
|
[".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.field_classes
|
24
24
|
@field_classes || []
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def self.inherited(klass)
|
28
28
|
@field_classes ||= []
|
29
29
|
@field_classes << klass
|
30
30
|
# raise args.inspect
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def self.load(session, element)
|
34
34
|
return nil if element.nil?
|
35
35
|
session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def self.field_class(element)
|
39
39
|
case element.name
|
40
40
|
when "button" then ButtonField
|
@@ -55,7 +55,7 @@ module Webrat
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def initialize(*args)
|
60
60
|
super
|
61
61
|
@value = default_value
|
@@ -65,7 +65,7 @@ module Webrat
|
|
65
65
|
return nil if labels.empty?
|
66
66
|
labels.first.text
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def id
|
70
70
|
Webrat::XML.attribute(@element, "id")
|
71
71
|
end
|
@@ -73,35 +73,37 @@ module Webrat
|
|
73
73
|
def disabled?
|
74
74
|
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def raise_error_if_disabled
|
78
78
|
return unless disabled?
|
79
79
|
raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def to_param
|
83
83
|
return nil if disabled?
|
84
|
-
|
84
|
+
|
85
85
|
case Webrat.configuration.mode
|
86
86
|
when :rails
|
87
87
|
parse_rails_request_params("#{name}=#{escaped_value}")
|
88
88
|
when :merb
|
89
89
|
::Merb::Parse.query("#{name}=#{escaped_value}")
|
90
|
+
when :mechanize
|
91
|
+
{ name => value }
|
90
92
|
else
|
91
93
|
{ name => escaped_value }
|
92
94
|
end
|
93
95
|
end
|
94
|
-
|
96
|
+
|
95
97
|
def set(value)
|
96
98
|
@value = value
|
97
99
|
end
|
98
|
-
|
100
|
+
|
99
101
|
def unset
|
100
102
|
@value = default_value
|
101
103
|
end
|
102
|
-
|
104
|
+
|
103
105
|
protected
|
104
|
-
|
106
|
+
|
105
107
|
def parse_rails_request_params(params)
|
106
108
|
if defined?(ActionController::AbstractRequest)
|
107
109
|
ActionController::AbstractRequest.parse_query_parameters(params)
|
@@ -113,38 +115,38 @@ module Webrat
|
|
113
115
|
Rack::Utils.parse_nested_query(params)
|
114
116
|
end
|
115
117
|
end
|
116
|
-
|
118
|
+
|
117
119
|
def form
|
118
120
|
Form.load(@session, form_element)
|
119
121
|
end
|
120
|
-
|
122
|
+
|
121
123
|
def form_element
|
122
124
|
parent = @element.parent
|
123
|
-
|
125
|
+
|
124
126
|
while parent.respond_to?(:parent)
|
125
127
|
return parent if parent.name == 'form'
|
126
128
|
parent = parent.parent
|
127
129
|
end
|
128
130
|
end
|
129
|
-
|
131
|
+
|
130
132
|
def name
|
131
133
|
Webrat::XML.attribute(@element, "name")
|
132
134
|
end
|
133
|
-
|
135
|
+
|
134
136
|
def escaped_value
|
135
|
-
CGI.escape(
|
137
|
+
CGI.escape([*@value].first.to_s)
|
136
138
|
end
|
137
|
-
|
139
|
+
|
138
140
|
def labels
|
139
141
|
@labels ||= label_elements.map do |element|
|
140
142
|
Label.load(@session, element)
|
141
143
|
end
|
142
144
|
end
|
143
|
-
|
145
|
+
|
144
146
|
def label_elements
|
145
147
|
return @label_elements unless @label_elements.nil?
|
146
148
|
@label_elements = []
|
147
|
-
|
149
|
+
|
148
150
|
parent = @element.parent
|
149
151
|
while parent.respond_to?(:parent)
|
150
152
|
if parent.name == 'label'
|
@@ -153,18 +155,18 @@ module Webrat
|
|
153
155
|
end
|
154
156
|
parent = parent.parent
|
155
157
|
end
|
156
|
-
|
158
|
+
|
157
159
|
unless id.blank?
|
158
160
|
@label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']")
|
159
161
|
end
|
160
|
-
|
162
|
+
|
161
163
|
@label_elements
|
162
164
|
end
|
163
|
-
|
165
|
+
|
164
166
|
def default_value
|
165
167
|
Webrat::XML.attribute(@element, "value")
|
166
168
|
end
|
167
|
-
|
169
|
+
|
168
170
|
def replace_param_value(params, oval, nval)
|
169
171
|
output = Hash.new
|
170
172
|
params.each do |key, value|
|
@@ -181,13 +183,13 @@ module Webrat
|
|
181
183
|
output
|
182
184
|
end
|
183
185
|
end
|
184
|
-
|
186
|
+
|
185
187
|
class ButtonField < Field #:nodoc:
|
186
188
|
|
187
189
|
def self.xpath_search
|
188
190
|
[".//button", ".//input[@type = 'submit']", ".//input[@type = 'button']", ".//input[@type = 'image']"]
|
189
191
|
end
|
190
|
-
|
192
|
+
|
191
193
|
def to_param
|
192
194
|
return nil if @value.nil?
|
193
195
|
super
|
@@ -210,7 +212,7 @@ module Webrat
|
|
210
212
|
def self.xpath_search
|
211
213
|
".//input[@type = 'hidden']"
|
212
214
|
end
|
213
|
-
|
215
|
+
|
214
216
|
def to_param
|
215
217
|
if collection_name?
|
216
218
|
super
|
@@ -238,7 +240,7 @@ module Webrat
|
|
238
240
|
def self.xpath_search
|
239
241
|
".//input[@type = 'checkbox']"
|
240
242
|
end
|
241
|
-
|
243
|
+
|
242
244
|
def to_param
|
243
245
|
return nil if @value.nil?
|
244
246
|
super
|
@@ -248,7 +250,7 @@ module Webrat
|
|
248
250
|
raise_error_if_disabled
|
249
251
|
set(Webrat::XML.attribute(@element, "value") || "on")
|
250
252
|
end
|
251
|
-
|
253
|
+
|
252
254
|
def checked?
|
253
255
|
Webrat::XML.attribute(@element, "checked") == "checked"
|
254
256
|
end
|
@@ -271,11 +273,11 @@ module Webrat
|
|
271
273
|
end
|
272
274
|
|
273
275
|
class PasswordField < Field #:nodoc:
|
274
|
-
|
276
|
+
|
275
277
|
def self.xpath_search
|
276
278
|
".//input[@type = 'password']"
|
277
279
|
end
|
278
|
-
|
280
|
+
|
279
281
|
end
|
280
282
|
|
281
283
|
class RadioField < Field #:nodoc:
|
@@ -283,31 +285,31 @@ module Webrat
|
|
283
285
|
def self.xpath_search
|
284
286
|
".//input[@type = 'radio']"
|
285
287
|
end
|
286
|
-
|
288
|
+
|
287
289
|
def to_param
|
288
290
|
return nil if @value.nil?
|
289
291
|
super
|
290
292
|
end
|
291
|
-
|
293
|
+
|
292
294
|
def choose
|
293
295
|
raise_error_if_disabled
|
294
296
|
other_options.each do |option|
|
295
297
|
option.set(nil)
|
296
298
|
end
|
297
|
-
|
299
|
+
|
298
300
|
set(Webrat::XML.attribute(@element, "value") || "on")
|
299
301
|
end
|
300
|
-
|
302
|
+
|
301
303
|
def checked?
|
302
304
|
Webrat::XML.attribute(@element, "checked") == "checked"
|
303
305
|
end
|
304
|
-
|
306
|
+
|
305
307
|
protected
|
306
308
|
|
307
309
|
def other_options
|
308
310
|
form.fields.select { |f| f.name == name }
|
309
311
|
end
|
310
|
-
|
312
|
+
|
311
313
|
def default_value
|
312
314
|
if Webrat::XML.attribute(@element, "checked") == "checked"
|
313
315
|
Webrat::XML.attribute(@element, "value") || "on"
|
@@ -323,7 +325,7 @@ module Webrat
|
|
323
325
|
def self.xpath_search
|
324
326
|
".//textarea"
|
325
327
|
end
|
326
|
-
|
328
|
+
|
327
329
|
protected
|
328
330
|
|
329
331
|
def default_value
|
@@ -331,13 +333,13 @@ module Webrat
|
|
331
333
|
end
|
332
334
|
|
333
335
|
end
|
334
|
-
|
336
|
+
|
335
337
|
class FileField < Field #:nodoc:
|
336
|
-
|
338
|
+
|
337
339
|
def self.xpath_search
|
338
340
|
".//input[@type = 'file']"
|
339
341
|
end
|
340
|
-
|
342
|
+
|
341
343
|
attr_accessor :content_type
|
342
344
|
|
343
345
|
def set(value, content_type = nil)
|
@@ -352,14 +354,20 @@ module Webrat
|
|
352
354
|
replace_param_value(super, @value, test_uploaded_file)
|
353
355
|
end
|
354
356
|
end
|
355
|
-
|
357
|
+
|
356
358
|
protected
|
357
|
-
|
359
|
+
|
358
360
|
def test_uploaded_file
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
361
|
+
case Webrat.configuration.mode
|
362
|
+
when :rails
|
363
|
+
if content_type
|
364
|
+
ActionController::TestUploadedFile.new(@value, content_type)
|
365
|
+
else
|
366
|
+
ActionController::TestUploadedFile.new(@value)
|
367
|
+
end
|
368
|
+
when :merb
|
369
|
+
# TODO: support content_type
|
370
|
+
File.new(@value)
|
363
371
|
end
|
364
372
|
end
|
365
373
|
|
@@ -386,17 +394,17 @@ module Webrat
|
|
386
394
|
def options
|
387
395
|
@options ||= SelectOption.load_all(@session, @element)
|
388
396
|
end
|
389
|
-
|
397
|
+
|
390
398
|
protected
|
391
399
|
|
392
400
|
def default_value
|
393
401
|
selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
|
394
|
-
selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
|
395
|
-
|
402
|
+
selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
|
403
|
+
|
396
404
|
selected_options.map do |option|
|
397
405
|
return "" if option.nil?
|
398
406
|
Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
|
399
|
-
end
|
407
|
+
end.uniq
|
400
408
|
end
|
401
409
|
|
402
410
|
end
|
@@ -7,7 +7,7 @@ require "webrat/core/locators/field_named_locator"
|
|
7
7
|
module Webrat
|
8
8
|
class Form < Element #:nodoc:
|
9
9
|
attr_reader :element
|
10
|
-
|
10
|
+
|
11
11
|
def self.xpath_search
|
12
12
|
".//form"
|
13
13
|
end
|
@@ -15,21 +15,21 @@ module Webrat
|
|
15
15
|
def fields
|
16
16
|
@fields ||= Field.load_all(@session, @element)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def submit
|
20
20
|
@session.request_page(form_action, form_method, params)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def field_named(name, *field_types)
|
24
24
|
Webrat::Locators::FieldNamedLocator.new(@session, dom, name, *field_types).locate
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
protected
|
28
|
-
|
28
|
+
|
29
29
|
def dom
|
30
30
|
Webrat::XML.xpath_at(@session.dom, path)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def fields_by_type(field_types)
|
34
34
|
if field_types.any?
|
35
35
|
fields.select { |f| field_types.include?(f.class) }
|
@@ -37,26 +37,26 @@ module Webrat
|
|
37
37
|
fields
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def params
|
42
42
|
all_params = {}
|
43
|
-
|
43
|
+
|
44
44
|
fields.each do |field|
|
45
45
|
next if field.to_param.nil?
|
46
46
|
merge(all_params, field.to_param)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
all_params
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def form_method
|
53
53
|
Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def form_action
|
57
57
|
Webrat::XML.attribute(@element, "action").blank? ? @session.current_url : Webrat::XML.attribute(@element, "action")
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def merge(all_params, new_param)
|
61
61
|
new_param.each do |key, value|
|
62
62
|
case all_params[key]
|
@@ -69,7 +69,7 @@ module Webrat
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def merge_hash_values(a, b) # :nodoc:
|
74
74
|
a.keys.each do |k|
|
75
75
|
if b.has_key?(k)
|
@@ -85,19 +85,19 @@ module Webrat
|
|
85
85
|
end
|
86
86
|
a.merge!(b)
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def hash_classes
|
90
90
|
klasses = [Hash]
|
91
|
-
|
91
|
+
|
92
92
|
case Webrat.configuration.mode
|
93
93
|
when :rails
|
94
94
|
klasses << HashWithIndifferentAccess
|
95
95
|
when :merb
|
96
96
|
klasses << Mash
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
klasses
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
end
|
103
103
|
end
|
@@ -2,9 +2,9 @@ require "webrat/core/elements/element"
|
|
2
2
|
|
3
3
|
module Webrat
|
4
4
|
class Label < Element #:nodoc:
|
5
|
-
|
5
|
+
|
6
6
|
attr_reader :element
|
7
|
-
|
7
|
+
|
8
8
|
def self.xpath_search
|
9
9
|
".//label"
|
10
10
|
end
|
@@ -12,13 +12,13 @@ module Webrat
|
|
12
12
|
def for_id
|
13
13
|
Webrat::XML.attribute(@element, "for")
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def field
|
17
17
|
Field.load(@session, field_element)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
protected
|
21
|
-
|
21
|
+
|
22
22
|
def field_element
|
23
23
|
if for_id.blank?
|
24
24
|
Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
|
@@ -26,6 +26,6 @@ module Webrat
|
|
26
26
|
Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
end
|
31
31
|
end
|