aslakhellesoy-webrat 0.3.2.2 → 0.4.4.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.
- data/History.txt +158 -19
- data/Rakefile +36 -11
- data/lib/webrat.rb +8 -11
- data/lib/webrat/core/configuration.rb +67 -25
- 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 +70 -51
- data/lib/webrat/core/elements/form.rb +17 -17
- data/lib/webrat/core/elements/label.rb +8 -8
- data/lib/webrat/core/elements/link.rb +13 -11
- 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 +19 -13
- 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 +12 -12
- 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 +19 -15
- data/lib/webrat/core/matchers/have_selector.rb +44 -22
- data/lib/webrat/core/matchers/have_tag.rb +11 -61
- data/lib/webrat/core/matchers/have_xpath.rb +89 -35
- 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 +9 -9
- data/lib/webrat/core/scope.rb +82 -62
- data/lib/webrat/core/session.rb +61 -18
- data/lib/webrat/core/xml.rb +16 -16
- data/lib/webrat/core/xml/hpricot.rb +3 -3
- data/lib/webrat/core/xml/nokogiri.rb +14 -14
- 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 +27 -0
- data/lib/webrat/mechanize.rb +9 -9
- data/lib/webrat/merb.rb +5 -61
- data/lib/webrat/merb_session.rb +67 -0
- data/lib/webrat/rack.rb +45 -14
- data/lib/webrat/rails.rb +31 -11
- data/lib/webrat/rspec-rails.rb +2 -2
- data/lib/webrat/selenium.rb +27 -39
- 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 +44 -0
- data/lib/webrat/selenium/application_servers/external.rb +24 -0
- data/lib/webrat/selenium/application_servers/merb.rb +48 -0
- data/lib/webrat/selenium/application_servers/rails.rb +42 -0
- data/lib/webrat/selenium/application_servers/sinatra.rb +35 -0
- data/lib/webrat/selenium/location_strategy_javascript/button.js +14 -7
- data/lib/webrat/selenium/location_strategy_javascript/label.js +1 -2
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +4 -1
- data/lib/webrat/selenium/matchers.rb +4 -108
- data/lib/webrat/selenium/matchers/have_content.rb +66 -0
- data/lib/webrat/selenium/matchers/have_selector.rb +49 -0
- data/lib/webrat/selenium/matchers/have_tag.rb +72 -0
- data/lib/webrat/selenium/matchers/have_xpath.rb +45 -0
- data/lib/webrat/selenium/selenium_rc_server.rb +84 -0
- data/lib/webrat/selenium/selenium_session.rb +86 -68
- data/lib/webrat/selenium/silence_stream.rb +18 -0
- metadata +21 -16
- data/lib/webrat/core_extensions/hash_with_indifferent_access.rb +0 -131
- data/lib/webrat/sinatra.rb +0 -29
@@ -2,21 +2,21 @@ require "webrat/core/elements/element"
|
|
2
2
|
|
3
3
|
module Webrat
|
4
4
|
class Area < Element #:nodoc:
|
5
|
-
|
5
|
+
|
6
6
|
def self.xpath_search
|
7
7
|
".//area"
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def click(method = nil, options = {})
|
11
11
|
@session.request_page(absolute_href, :get, {})
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
protected
|
15
|
-
|
15
|
+
|
16
16
|
def href
|
17
17
|
Webrat::XML.attribute(@element, "href")
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def absolute_href
|
21
21
|
if href =~ /^\?/
|
22
22
|
"#{@session.current_url}#{href}"
|
@@ -26,6 +26,6 @@ module Webrat
|
|
26
26
|
href
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
@@ -1,33 +1,33 @@
|
|
1
1
|
module Webrat
|
2
|
-
|
2
|
+
|
3
3
|
class Element # :nodoc:
|
4
|
-
|
4
|
+
|
5
5
|
def self.load_all(session, dom)
|
6
|
-
Webrat::XML.xpath_search(dom, xpath_search).map do |element|
|
6
|
+
Webrat::XML.xpath_search(dom, xpath_search).map do |element|
|
7
7
|
load(session, element)
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.load(session, element)
|
12
12
|
return nil if element.nil?
|
13
13
|
session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
attr_reader :element
|
17
|
-
|
17
|
+
|
18
18
|
def initialize(session, element)
|
19
19
|
@session = session
|
20
20
|
@element = element
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def path
|
24
24
|
Webrat::XML.xpath_to(@element)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def inspect
|
28
28
|
"#<#{self.class} @element=#{element.inspect}>"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
end
|
32
|
-
|
33
|
-
end
|
32
|
+
|
33
|
+
end
|
@@ -8,29 +8,33 @@ 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
|
18
|
-
|
18
|
+
|
19
|
+
def self.xpath_search_excluding_hidden
|
20
|
+
[".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
|
21
|
+
end
|
22
|
+
|
19
23
|
def self.field_classes
|
20
24
|
@field_classes || []
|
21
25
|
end
|
22
|
-
|
26
|
+
|
23
27
|
def self.inherited(klass)
|
24
28
|
@field_classes ||= []
|
25
29
|
@field_classes << klass
|
26
30
|
# raise args.inspect
|
27
31
|
end
|
28
|
-
|
32
|
+
|
29
33
|
def self.load(session, element)
|
30
34
|
return nil if element.nil?
|
31
35
|
session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
|
32
36
|
end
|
33
|
-
|
37
|
+
|
34
38
|
def self.field_class(element)
|
35
39
|
case element.name
|
36
40
|
when "button" then ButtonField
|
@@ -45,12 +49,13 @@ module Webrat
|
|
45
49
|
when "file" then FileField
|
46
50
|
when "reset" then ResetField
|
47
51
|
when "submit" then ButtonField
|
52
|
+
when "button" then ButtonField
|
48
53
|
when "image" then ButtonField
|
49
54
|
else TextField
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
53
|
-
|
58
|
+
|
54
59
|
def initialize(*args)
|
55
60
|
super
|
56
61
|
@value = default_value
|
@@ -60,7 +65,7 @@ module Webrat
|
|
60
65
|
return nil if labels.empty?
|
61
66
|
labels.first.text
|
62
67
|
end
|
63
|
-
|
68
|
+
|
64
69
|
def id
|
65
70
|
Webrat::XML.attribute(@element, "id")
|
66
71
|
end
|
@@ -68,66 +73,80 @@ module Webrat
|
|
68
73
|
def disabled?
|
69
74
|
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
|
70
75
|
end
|
71
|
-
|
76
|
+
|
72
77
|
def raise_error_if_disabled
|
73
78
|
return unless disabled?
|
74
79
|
raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
|
75
80
|
end
|
76
|
-
|
81
|
+
|
77
82
|
def to_param
|
78
83
|
return nil if disabled?
|
79
|
-
|
84
|
+
|
80
85
|
case Webrat.configuration.mode
|
81
86
|
when :rails
|
82
|
-
|
87
|
+
parse_rails_request_params("#{name}=#{escaped_value}")
|
83
88
|
when :merb
|
84
89
|
::Merb::Parse.query("#{name}=#{escaped_value}")
|
90
|
+
when :mechanize
|
91
|
+
{ name => value }
|
85
92
|
else
|
86
93
|
{ name => escaped_value }
|
87
94
|
end
|
88
95
|
end
|
89
|
-
|
96
|
+
|
90
97
|
def set(value)
|
91
98
|
@value = value
|
92
99
|
end
|
93
|
-
|
100
|
+
|
94
101
|
def unset
|
95
102
|
@value = default_value
|
96
103
|
end
|
97
|
-
|
104
|
+
|
98
105
|
protected
|
99
|
-
|
106
|
+
|
107
|
+
def parse_rails_request_params(params)
|
108
|
+
if defined?(ActionController::AbstractRequest)
|
109
|
+
ActionController::AbstractRequest.parse_query_parameters(params)
|
110
|
+
elsif defined?(ActionController::UrlEncodedPairParser)
|
111
|
+
# For Rails > 2.2
|
112
|
+
ActionController::UrlEncodedPairParser.parse_query_parameters(params)
|
113
|
+
else
|
114
|
+
# For Rails > 2.3
|
115
|
+
Rack::Utils.parse_nested_query(params)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
100
119
|
def form
|
101
120
|
Form.load(@session, form_element)
|
102
121
|
end
|
103
|
-
|
122
|
+
|
104
123
|
def form_element
|
105
124
|
parent = @element.parent
|
106
|
-
|
125
|
+
|
107
126
|
while parent.respond_to?(:parent)
|
108
127
|
return parent if parent.name == 'form'
|
109
128
|
parent = parent.parent
|
110
129
|
end
|
111
130
|
end
|
112
|
-
|
131
|
+
|
113
132
|
def name
|
114
133
|
Webrat::XML.attribute(@element, "name")
|
115
134
|
end
|
116
|
-
|
135
|
+
|
117
136
|
def escaped_value
|
118
137
|
CGI.escape(@value.to_s)
|
119
138
|
end
|
120
|
-
|
139
|
+
|
121
140
|
def labels
|
122
141
|
@labels ||= label_elements.map do |element|
|
123
142
|
Label.load(@session, element)
|
124
143
|
end
|
125
144
|
end
|
126
|
-
|
145
|
+
|
127
146
|
def label_elements
|
128
147
|
return @label_elements unless @label_elements.nil?
|
129
148
|
@label_elements = []
|
130
|
-
|
149
|
+
|
131
150
|
parent = @element.parent
|
132
151
|
while parent.respond_to?(:parent)
|
133
152
|
if parent.name == 'label'
|
@@ -136,18 +155,18 @@ module Webrat
|
|
136
155
|
end
|
137
156
|
parent = parent.parent
|
138
157
|
end
|
139
|
-
|
158
|
+
|
140
159
|
unless id.blank?
|
141
160
|
@label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']")
|
142
161
|
end
|
143
|
-
|
162
|
+
|
144
163
|
@label_elements
|
145
164
|
end
|
146
|
-
|
165
|
+
|
147
166
|
def default_value
|
148
167
|
Webrat::XML.attribute(@element, "value")
|
149
168
|
end
|
150
|
-
|
169
|
+
|
151
170
|
def replace_param_value(params, oval, nval)
|
152
171
|
output = Hash.new
|
153
172
|
params.each do |key, value|
|
@@ -164,13 +183,13 @@ module Webrat
|
|
164
183
|
output
|
165
184
|
end
|
166
185
|
end
|
167
|
-
|
186
|
+
|
168
187
|
class ButtonField < Field #:nodoc:
|
169
188
|
|
170
189
|
def self.xpath_search
|
171
|
-
[".//button", ".//input[@type = 'submit']", ".//input[@type = 'image']"]
|
190
|
+
[".//button", ".//input[@type = 'submit']", ".//input[@type = 'button']", ".//input[@type = 'image']"]
|
172
191
|
end
|
173
|
-
|
192
|
+
|
174
193
|
def to_param
|
175
194
|
return nil if @value.nil?
|
176
195
|
super
|
@@ -193,7 +212,7 @@ module Webrat
|
|
193
212
|
def self.xpath_search
|
194
213
|
".//input[@type = 'hidden']"
|
195
214
|
end
|
196
|
-
|
215
|
+
|
197
216
|
def to_param
|
198
217
|
if collection_name?
|
199
218
|
super
|
@@ -221,7 +240,7 @@ module Webrat
|
|
221
240
|
def self.xpath_search
|
222
241
|
".//input[@type = 'checkbox']"
|
223
242
|
end
|
224
|
-
|
243
|
+
|
225
244
|
def to_param
|
226
245
|
return nil if @value.nil?
|
227
246
|
super
|
@@ -231,7 +250,7 @@ module Webrat
|
|
231
250
|
raise_error_if_disabled
|
232
251
|
set(Webrat::XML.attribute(@element, "value") || "on")
|
233
252
|
end
|
234
|
-
|
253
|
+
|
235
254
|
def checked?
|
236
255
|
Webrat::XML.attribute(@element, "checked") == "checked"
|
237
256
|
end
|
@@ -254,11 +273,11 @@ module Webrat
|
|
254
273
|
end
|
255
274
|
|
256
275
|
class PasswordField < Field #:nodoc:
|
257
|
-
|
276
|
+
|
258
277
|
def self.xpath_search
|
259
278
|
".//input[@type = 'password']"
|
260
279
|
end
|
261
|
-
|
280
|
+
|
262
281
|
end
|
263
282
|
|
264
283
|
class RadioField < Field #:nodoc:
|
@@ -266,31 +285,31 @@ module Webrat
|
|
266
285
|
def self.xpath_search
|
267
286
|
".//input[@type = 'radio']"
|
268
287
|
end
|
269
|
-
|
288
|
+
|
270
289
|
def to_param
|
271
290
|
return nil if @value.nil?
|
272
291
|
super
|
273
292
|
end
|
274
|
-
|
293
|
+
|
275
294
|
def choose
|
276
295
|
raise_error_if_disabled
|
277
296
|
other_options.each do |option|
|
278
297
|
option.set(nil)
|
279
298
|
end
|
280
|
-
|
299
|
+
|
281
300
|
set(Webrat::XML.attribute(@element, "value") || "on")
|
282
301
|
end
|
283
|
-
|
302
|
+
|
284
303
|
def checked?
|
285
304
|
Webrat::XML.attribute(@element, "checked") == "checked"
|
286
305
|
end
|
287
|
-
|
306
|
+
|
288
307
|
protected
|
289
308
|
|
290
309
|
def other_options
|
291
310
|
form.fields.select { |f| f.name == name }
|
292
311
|
end
|
293
|
-
|
312
|
+
|
294
313
|
def default_value
|
295
314
|
if Webrat::XML.attribute(@element, "checked") == "checked"
|
296
315
|
Webrat::XML.attribute(@element, "value") || "on"
|
@@ -306,7 +325,7 @@ module Webrat
|
|
306
325
|
def self.xpath_search
|
307
326
|
".//textarea"
|
308
327
|
end
|
309
|
-
|
328
|
+
|
310
329
|
protected
|
311
330
|
|
312
331
|
def default_value
|
@@ -314,13 +333,13 @@ module Webrat
|
|
314
333
|
end
|
315
334
|
|
316
335
|
end
|
317
|
-
|
336
|
+
|
318
337
|
class FileField < Field #:nodoc:
|
319
|
-
|
338
|
+
|
320
339
|
def self.xpath_search
|
321
340
|
".//input[@type = 'file']"
|
322
341
|
end
|
323
|
-
|
342
|
+
|
324
343
|
attr_accessor :content_type
|
325
344
|
|
326
345
|
def set(value, content_type = nil)
|
@@ -335,9 +354,9 @@ module Webrat
|
|
335
354
|
replace_param_value(super, @value, test_uploaded_file)
|
336
355
|
end
|
337
356
|
end
|
338
|
-
|
357
|
+
|
339
358
|
protected
|
340
|
-
|
359
|
+
|
341
360
|
def test_uploaded_file
|
342
361
|
if content_type
|
343
362
|
ActionController::TestUploadedFile.new(@value, content_type)
|
@@ -369,17 +388,17 @@ module Webrat
|
|
369
388
|
def options
|
370
389
|
@options ||= SelectOption.load_all(@session, @element)
|
371
390
|
end
|
372
|
-
|
391
|
+
|
373
392
|
protected
|
374
393
|
|
375
394
|
def default_value
|
376
395
|
selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
|
377
|
-
selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
|
378
|
-
|
396
|
+
selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
|
397
|
+
|
379
398
|
selected_options.map do |option|
|
380
399
|
return "" if option.nil?
|
381
400
|
Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
|
382
|
-
end
|
401
|
+
end.uniq
|
383
402
|
end
|
384
403
|
|
385
404
|
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
|