webrat 0.7.0 → 0.7.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/Gemfile +0 -6
- data/History.txt +17 -0
- data/Rakefile +7 -9
- data/lib/webrat.rb +1 -1
- data/lib/webrat/adapters/mechanize.rb +22 -6
- data/lib/webrat/adapters/rack.rb +4 -0
- data/lib/webrat/adapters/rails.rb +4 -0
- data/lib/webrat/core/configuration.rb +16 -1
- data/lib/webrat/core/elements/field.rb +40 -89
- data/lib/webrat/core/elements/form.rb +55 -31
- data/lib/webrat/core/locators/form_locator.rb +1 -1
- data/lib/webrat/core/matchers/have_xpath.rb +4 -2
- data/lib/webrat/core/methods.rb +1 -1
- data/lib/webrat/core/mime.rb +2 -2
- data/lib/webrat/core/scope.rb +1 -0
- data/lib/webrat/core/session.rb +4 -3
- data/lib/webrat/core_extensions/{nil_to_param.rb → nil_to_query_string.rb} +1 -1
- data/lib/webrat/selenium/location_strategy_javascript/label.js +9 -3
- data/lib/webrat/selenium/selenium_rc_server.rb +4 -1
- data/lib/webrat/selenium/selenium_session.rb +9 -4
- data/spec/fakes/test_adapter.rb +1 -1
- data/spec/integration/mechanize/sample_app.rb +16 -1
- data/spec/integration/mechanize/spec/mechanize_spec.rb +9 -1
- data/spec/integration/rack/app.rb +2 -2
- data/spec/integration/rack/test/helper.rb +0 -1
- data/spec/integration/rack/test/webrat_rack_test.rb +3 -2
- data/spec/integration/sinatra/classic_app.rb +0 -1
- data/spec/integration/sinatra/modular_app.rb +0 -1
- data/spec/integration/sinatra/test/classic_app_test.rb +1 -0
- data/spec/integration/sinatra/test/test_helper.rb +0 -1
- data/spec/private/core/field_spec.rb +1 -1
- data/spec/private/core/form_spec.rb +51 -0
- data/spec/private/core/session_spec.rb +5 -18
- data/spec/private/mechanize/mechanize_adapter_spec.rb +24 -1
- data/spec/private/rails/attaches_file_spec.rb +33 -0
- data/spec/public/matchers/have_xpath_spec.rb +6 -0
- data/spec/public/submit_form_spec.rb +52 -1
- data/spec/spec_helper.rb +0 -1
- data/webrat.gemspec +6 -4
- metadata +38 -18
data/Gemfile
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
== 0.7.1 / 2010-04-26
|
2
|
+
|
3
|
+
* Minor enhancements
|
4
|
+
|
5
|
+
* Move verbose selenium output that can clutter build output behind setting
|
6
|
+
* Added application_port_for_selenium to webrat configuration. The use case is when you want to test through a web server sitting in front of your application server. (Luke Melia)
|
7
|
+
* New webrat configuration option selenium_firefox_profile which is passed to selenium server
|
8
|
+
* Allow submit_form to select by CSS too (Damian Janowski)
|
9
|
+
|
10
|
+
* Bug fixes
|
11
|
+
|
12
|
+
* Fix that current_url wasn't reflecting redirects in Mechanize [#332] (Emrys Ingersoll)
|
13
|
+
* Fix attach_file with nested params [#341] (Álvaro Gil)
|
14
|
+
* Fix that a 304 was considered a redirect (Larry Marburger)
|
15
|
+
* Fix selection of LABEL elements in Selenium mode under IE [#317] (Damian Janowski, Noah Davis)
|
16
|
+
* Fix have_xpath not matching negative expectation in the block [#182] (Luismi Cavallé)
|
17
|
+
|
1
18
|
== 0.7.0 / 2010-01-17
|
2
19
|
|
3
20
|
* Major enhancements
|
data/Rakefile
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
|
3
1
|
begin
|
4
2
|
require 'spec/rake/spectask'
|
5
3
|
rescue LoadError
|
@@ -90,14 +88,14 @@ namespace :spec do
|
|
90
88
|
namespace :rails do
|
91
89
|
task :selenium do
|
92
90
|
Dir.chdir "spec/integration/rails" do
|
93
|
-
result = system "rake test_unit:selenium"
|
91
|
+
result = system "rake -rubygems test_unit:selenium"
|
94
92
|
raise "Rails integration tests failed" unless result
|
95
93
|
end
|
96
94
|
end
|
97
95
|
|
98
96
|
task :webrat do
|
99
97
|
Dir.chdir "spec/integration/rails" do
|
100
|
-
result = system "rake test_unit:rails"
|
98
|
+
result = system "rake -rubygems test_unit:rails"
|
101
99
|
raise "Rails integration tests failed" unless result
|
102
100
|
end
|
103
101
|
end
|
@@ -106,7 +104,7 @@ namespace :spec do
|
|
106
104
|
desc "Run the Merb integration specs"
|
107
105
|
task :merb do
|
108
106
|
Dir.chdir "spec/integration/merb" do
|
109
|
-
result = system "rake spec"
|
107
|
+
result = system "rake -rubygems spec"
|
110
108
|
raise "Merb integration tests failed" unless result
|
111
109
|
end
|
112
110
|
end
|
@@ -114,7 +112,7 @@ namespace :spec do
|
|
114
112
|
desc "Run the Sinatra integration specs"
|
115
113
|
task :sinatra do
|
116
114
|
Dir.chdir "spec/integration/sinatra" do
|
117
|
-
result = system "rake test"
|
115
|
+
result = system "rake -rubygems test"
|
118
116
|
raise "Sinatra integration tests failed" unless result
|
119
117
|
end
|
120
118
|
end
|
@@ -122,7 +120,7 @@ namespace :spec do
|
|
122
120
|
desc "Run the Sinatra integration specs"
|
123
121
|
task :rack do
|
124
122
|
Dir.chdir "spec/integration/rack" do
|
125
|
-
result = system "rake test"
|
123
|
+
result = system "rake -rubygems test"
|
126
124
|
raise "Rack integration tests failed" unless result
|
127
125
|
end
|
128
126
|
end
|
@@ -130,7 +128,7 @@ namespace :spec do
|
|
130
128
|
desc "Run the Mechanize integration specs"
|
131
129
|
task :mechanize do
|
132
130
|
Dir.chdir "spec/integration/mechanize" do
|
133
|
-
result = system "rake spec"
|
131
|
+
result = system "rake -rubygems spec"
|
134
132
|
raise "Mechanize integration tests failed" unless result
|
135
133
|
end
|
136
134
|
end
|
@@ -142,4 +140,4 @@ task :whitespace do
|
|
142
140
|
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
|
143
141
|
end
|
144
142
|
|
145
|
-
task :default => :spec
|
143
|
+
task :default => :spec
|
data/lib/webrat.rb
CHANGED
@@ -4,6 +4,8 @@ module Webrat #:nodoc:
|
|
4
4
|
class MechanizeAdapter #:nodoc:
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
+
Mechanize = WWW::Mechanize if defined?(WWW::Mechanize)
|
8
|
+
|
7
9
|
attr_accessor :response
|
8
10
|
alias :page :response
|
9
11
|
|
@@ -20,13 +22,19 @@ module Webrat #:nodoc:
|
|
20
22
|
|
21
23
|
def post(url, data, headers_argument_not_used = nil)
|
22
24
|
post_data = data.inject({}) do |memo, param|
|
23
|
-
case param
|
25
|
+
case param
|
24
26
|
when Hash
|
25
|
-
param.
|
26
|
-
|
27
|
-
|
27
|
+
param.each {|attribute, value| memo[attribute] = value }
|
28
|
+
memo
|
29
|
+
when Array
|
30
|
+
case param.last
|
31
|
+
when Hash
|
32
|
+
param.last.each {|attribute, value| memo["#{param.first}[#{attribute}]"] = value }
|
33
|
+
else
|
34
|
+
memo[param.first] = param.last
|
35
|
+
end
|
36
|
+
memo
|
28
37
|
end
|
29
|
-
memo
|
30
38
|
end
|
31
39
|
@response = mechanize.post(url, post_data)
|
32
40
|
end
|
@@ -39,8 +47,16 @@ module Webrat #:nodoc:
|
|
39
47
|
@response.code.to_i
|
40
48
|
end
|
41
49
|
|
50
|
+
def response_headers
|
51
|
+
@response.header
|
52
|
+
end
|
53
|
+
|
42
54
|
def mechanize
|
43
|
-
@mechanize ||=
|
55
|
+
@mechanize ||= begin
|
56
|
+
mechanize = Mechanize.new
|
57
|
+
mechanize.redirect_ok = false
|
58
|
+
mechanize
|
59
|
+
end
|
44
60
|
end
|
45
61
|
|
46
62
|
def_delegators :mechanize, :basic_auth
|
data/lib/webrat/adapters/rack.rb
CHANGED
@@ -40,6 +40,13 @@ module Webrat
|
|
40
40
|
webrat_deprecate :selenium_port, :application_port
|
41
41
|
webrat_deprecate :selenium_port=, :application_port=
|
42
42
|
|
43
|
+
# Which port should selenium use to access the application. Defaults to application_port
|
44
|
+
attr_writer :application_port_for_selenium
|
45
|
+
|
46
|
+
def application_port_for_selenium
|
47
|
+
@application_port_for_selenium || self.application_port
|
48
|
+
end
|
49
|
+
|
43
50
|
# Which underlying app framework we're testing with selenium
|
44
51
|
attr_accessor :application_framework
|
45
52
|
|
@@ -58,10 +65,17 @@ module Webrat
|
|
58
65
|
# Set the timeout for waiting for the browser process to start
|
59
66
|
attr_accessor :selenium_browser_startup_timeout
|
60
67
|
|
68
|
+
# Set the firefox profile for selenium to use
|
69
|
+
attr_accessor :selenium_firefox_profile
|
70
|
+
|
61
71
|
# How many redirects to the same URL should be halted as an infinite redirect
|
62
72
|
# loop? Defaults to 10
|
63
73
|
attr_accessor :infinite_redirect_limit
|
64
74
|
|
75
|
+
# Print out the full HTML on wait failure
|
76
|
+
# Defaults to false
|
77
|
+
attr_accessor :selenium_verbose_output
|
78
|
+
|
65
79
|
def initialize # :nodoc:
|
66
80
|
self.open_error_files = true
|
67
81
|
self.application_environment = :test
|
@@ -72,11 +86,12 @@ module Webrat
|
|
72
86
|
self.infinite_redirect_limit = 10
|
73
87
|
self.selenium_browser_key = '*firefox'
|
74
88
|
self.selenium_browser_startup_timeout = 5
|
89
|
+
self.selenium_verbose_output = false
|
75
90
|
|
76
91
|
tmp_dir = Pathname.new(Dir.pwd).join("tmp")
|
77
92
|
self.saved_pages_dir = tmp_dir.exist? ? tmp_dir : Dir.pwd
|
78
93
|
end
|
79
|
-
|
94
|
+
|
80
95
|
def open_error_files? #:nodoc:
|
81
96
|
@open_error_files ? true : false
|
82
97
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "cgi"
|
2
|
+
require "digest/md5"
|
2
3
|
require "webrat/core_extensions/blank"
|
3
|
-
require "webrat/core_extensions/
|
4
|
+
require "webrat/core_extensions/nil_to_query_string"
|
4
5
|
|
5
6
|
require "webrat/core/elements/element"
|
6
7
|
|
@@ -13,7 +14,7 @@ module Webrat
|
|
13
14
|
attr_reader :value
|
14
15
|
|
15
16
|
def self.xpath_search
|
16
|
-
|
17
|
+
".//button|.//input|.//textarea|.//select"
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.xpath_search_excluding_hidden
|
@@ -84,19 +85,17 @@ module Webrat
|
|
84
85
|
raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
|
85
86
|
end
|
86
87
|
|
87
|
-
def
|
88
|
+
def to_query_string
|
88
89
|
return nil if disabled?
|
89
90
|
|
90
|
-
|
91
|
-
when :rails
|
92
|
-
|
93
|
-
when :
|
94
|
-
|
95
|
-
else
|
96
|
-
{ name => [*@value].first.to_s }
|
91
|
+
query_string = case Webrat.configuration.mode
|
92
|
+
when :rails, :merb, :rack, :sinatra
|
93
|
+
build_query_string
|
94
|
+
when :mechanize
|
95
|
+
build_query_string(false)
|
97
96
|
end
|
98
97
|
|
99
|
-
|
98
|
+
query_string
|
100
99
|
end
|
101
100
|
|
102
101
|
def set(value)
|
@@ -109,18 +108,6 @@ module Webrat
|
|
109
108
|
|
110
109
|
protected
|
111
110
|
|
112
|
-
def parse_rails_request_params(params)
|
113
|
-
if defined?(ActionController::AbstractRequest)
|
114
|
-
ActionController::AbstractRequest.parse_query_parameters(params)
|
115
|
-
elsif defined?(ActionController::UrlEncodedPairParser)
|
116
|
-
# For Rails > 2.2
|
117
|
-
ActionController::UrlEncodedPairParser.parse_query_parameters(params)
|
118
|
-
else
|
119
|
-
# For Rails > 2.3
|
120
|
-
Rack::Utils.parse_nested_query(params)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
111
|
def form
|
125
112
|
Form.load(@session, form_element)
|
126
113
|
end
|
@@ -138,25 +125,22 @@ module Webrat
|
|
138
125
|
@element["name"]
|
139
126
|
end
|
140
127
|
|
141
|
-
def
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
# Because we have to escape it before sending it to the above case statement,
|
146
|
-
# we have to make sure we unescape each value when it gets back so assertions
|
147
|
-
# involving characters like <, >, and & work as expected
|
148
|
-
def unescape_params(params)
|
149
|
-
case params.class.name
|
150
|
-
when 'Hash', 'Mash'
|
151
|
-
params.each { |key,value| params[key] = unescape_params(value) }
|
152
|
-
params
|
153
|
-
when 'Array'
|
154
|
-
params.collect { |value| unescape_params(value) }
|
128
|
+
def build_query_string(escape_value=true)
|
129
|
+
if @value.is_a?(Array)
|
130
|
+
@value.collect {|value| "#{name}=#{ escape_value ? escape(value) : value }" }.join("&")
|
155
131
|
else
|
156
|
-
|
132
|
+
"#{name}=#{ escape_value ? escape(value) : value }"
|
157
133
|
end
|
158
134
|
end
|
159
135
|
|
136
|
+
def escape(value)
|
137
|
+
CGI.escape(value.to_s)
|
138
|
+
end
|
139
|
+
|
140
|
+
def escaped_value
|
141
|
+
CGI.escape(@value.to_s)
|
142
|
+
end
|
143
|
+
|
160
144
|
def labels
|
161
145
|
@labels ||= label_elements.map do |element|
|
162
146
|
Label.load(@session, element)
|
@@ -186,22 +170,6 @@ module Webrat
|
|
186
170
|
def default_value
|
187
171
|
@element["value"]
|
188
172
|
end
|
189
|
-
|
190
|
-
def replace_param_value(params, oval, nval)
|
191
|
-
output = Hash.new
|
192
|
-
params.each do |key, value|
|
193
|
-
case value
|
194
|
-
when Hash
|
195
|
-
value = replace_param_value(value, oval, nval)
|
196
|
-
when Array
|
197
|
-
value = value.map { |o| o == oval ? nval : oval }
|
198
|
-
when oval
|
199
|
-
value = nval
|
200
|
-
end
|
201
|
-
output[key] = value
|
202
|
-
end
|
203
|
-
output
|
204
|
-
end
|
205
173
|
end
|
206
174
|
|
207
175
|
class ButtonField < Field #:nodoc:
|
@@ -210,7 +178,7 @@ module Webrat
|
|
210
178
|
[".//button", ".//input[@type = 'submit']", ".//input[@type = 'button']", ".//input[@type = 'image']"]
|
211
179
|
end
|
212
180
|
|
213
|
-
def
|
181
|
+
def to_query_string
|
214
182
|
return nil if @value.nil?
|
215
183
|
super
|
216
184
|
end
|
@@ -233,13 +201,13 @@ module Webrat
|
|
233
201
|
".//input[@type = 'hidden']"
|
234
202
|
end
|
235
203
|
|
236
|
-
def
|
204
|
+
def to_query_string
|
237
205
|
if collection_name?
|
238
206
|
super
|
239
207
|
else
|
240
208
|
checkbox_with_same_name = form.field_named(name, CheckboxField)
|
241
209
|
|
242
|
-
if checkbox_with_same_name.
|
210
|
+
if checkbox_with_same_name.to_query_string.blank?
|
243
211
|
super
|
244
212
|
else
|
245
213
|
nil
|
@@ -261,7 +229,7 @@ module Webrat
|
|
261
229
|
".//input[@type = 'checkbox']"
|
262
230
|
end
|
263
231
|
|
264
|
-
def
|
232
|
+
def to_query_string
|
265
233
|
return nil if @value.nil?
|
266
234
|
super
|
267
235
|
end
|
@@ -306,7 +274,7 @@ module Webrat
|
|
306
274
|
".//input[@type = 'radio']"
|
307
275
|
end
|
308
276
|
|
309
|
-
def
|
277
|
+
def to_query_string
|
310
278
|
return nil if @value.nil?
|
311
279
|
super
|
312
280
|
end
|
@@ -363,30 +331,32 @@ module Webrat
|
|
363
331
|
attr_accessor :content_type
|
364
332
|
|
365
333
|
def set(value, content_type = nil)
|
334
|
+
@original_value = @value
|
335
|
+
@content_type ||= content_type
|
366
336
|
super(value)
|
367
|
-
@content_type = content_type
|
368
337
|
end
|
369
338
|
|
370
|
-
def
|
371
|
-
|
372
|
-
super
|
373
|
-
else
|
374
|
-
replace_param_value(super, @value, test_uploaded_file)
|
375
|
-
end
|
339
|
+
def digest_value
|
340
|
+
@value ? Digest::MD5.hexdigest(self.object_id.to_s) : ""
|
376
341
|
end
|
377
342
|
|
378
|
-
|
343
|
+
def to_query_string
|
344
|
+
@value.nil? ? set("") : set(digest_value)
|
345
|
+
super
|
346
|
+
end
|
379
347
|
|
380
348
|
def test_uploaded_file
|
349
|
+
return "" if @original_value.blank?
|
350
|
+
|
381
351
|
case Webrat.configuration.mode
|
382
352
|
when :rails
|
383
353
|
if content_type
|
384
|
-
ActionController::TestUploadedFile.new(@
|
354
|
+
ActionController::TestUploadedFile.new(@original_value, content_type)
|
385
355
|
else
|
386
|
-
ActionController::TestUploadedFile.new(@
|
356
|
+
ActionController::TestUploadedFile.new(@original_value)
|
387
357
|
end
|
388
358
|
when :rack, :merb
|
389
|
-
Rack::Test::UploadedFile.new(@
|
359
|
+
Rack::Test::UploadedFile.new(@original_value, content_type)
|
390
360
|
end
|
391
361
|
end
|
392
362
|
|
@@ -450,25 +420,6 @@ module Webrat
|
|
450
420
|
@value.delete(value)
|
451
421
|
end
|
452
422
|
|
453
|
-
# We have to overide how the uri string is formed when dealing with multiples
|
454
|
-
# Where normally a select field might produce name=value with a multiple,
|
455
|
-
# we need to form something like name[]=value1&name[]=value2
|
456
|
-
def to_param
|
457
|
-
return nil if disabled?
|
458
|
-
|
459
|
-
uri_string = @value.collect {|value| "#{name}=#{CGI.escape(value)}"}.join("&")
|
460
|
-
params = case Webrat.configuration.mode
|
461
|
-
when :rails
|
462
|
-
parse_rails_request_params(uri_string)
|
463
|
-
when :merb
|
464
|
-
::Merb::Parse.query(uri_string)
|
465
|
-
else
|
466
|
-
{ name => @value }
|
467
|
-
end
|
468
|
-
|
469
|
-
unescape_params(params)
|
470
|
-
end
|
471
|
-
|
472
423
|
protected
|
473
424
|
|
474
425
|
# Overwrite SelectField definition because we don't want to select the first option
|