dbrady-webrat 0.4.4.1 → 0.4.4.2
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 +43 -8
- data/README.rdoc +13 -1
- data/Rakefile +50 -6
- data/lib/webrat.rb +5 -8
- data/lib/webrat/core/configuration.rb +5 -1
- data/lib/webrat/core/elements/field.rb +13 -5
- data/lib/webrat/core/elements/link.rb +2 -1
- data/lib/webrat/core/locators/field_labeled_locator.rb +1 -1
- data/lib/webrat/core/locators/label_locator.rb +1 -1
- data/lib/webrat/core/locators/link_locator.rb +9 -1
- data/lib/webrat/core/logging.rb +4 -1
- data/lib/webrat/core/matchers/have_xpath.rb +2 -2
- data/lib/webrat/core/methods.rb +7 -5
- data/lib/webrat/core/save_and_open_page.rb +5 -7
- data/lib/webrat/core/scope.rb +2 -2
- data/lib/webrat/core/session.rb +16 -7
- data/lib/webrat/mechanize.rb +1 -1
- data/lib/webrat/merb_session.rb +31 -16
- data/lib/webrat/rack_test.rb +32 -0
- data/lib/webrat/rspec-rails.rb +1 -4
- data/lib/webrat/selenium.rb +2 -1
- 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/selenium_session.rb +23 -16
- data/vendor/selenium-server.jar +0 -0
- metadata +3 -2
data/History.txt
CHANGED
@@ -1,11 +1,46 @@
|
|
1
|
+
== 0.4.5 / ?
|
2
|
+
|
3
|
+
* Major enhancements
|
4
|
+
|
5
|
+
* Ruby 1.9 compatibility (Michael Fellinger, Jakub Kuźma)
|
6
|
+
* Improve performance (~2x) on JRuby by supporting Nokogiri
|
7
|
+
* Added support for external app servers in selenium mode (basically don't start one) (Mike Gaffney)
|
8
|
+
* Added support for uploading files for Merb (Ryan Carver)
|
9
|
+
|
10
|
+
* Minor enhancements
|
11
|
+
|
12
|
+
* Upgrade to selenium-client to 1.2.16 (Brian Landau)
|
13
|
+
* Upgrade selenium-server.jar to 1.0.1 (Brian Landau)
|
14
|
+
* Make redirect detection work in the face of rational maths (like when ruby-units is active) (Piers Cawley)
|
15
|
+
* Use Launchy to handle opening pages in the browser with cross-platform compatibility (Bryan Helmkamp)
|
16
|
+
* Added support for field_labeled_locators ending in non word characters
|
17
|
+
lh 148 (Zach Dennis)
|
18
|
+
* Filled in tests on click link lh 195 (diabolo)
|
19
|
+
* Added current_url to selenium session lh 215 (Luke Amdor)
|
20
|
+
* Added silence spec to selenium lh 238 (Martin Gamsjaeger aka snusnu)
|
21
|
+
* Added ability to configure the browser startup timeout for selenium lh 242 (Mike Gaffney, Mark Dodwell)
|
22
|
+
* Added delegation for field_named lh194 (pivotal labs)
|
23
|
+
* Added fix to keep from escaping field values in mechanize mode lh256 (jish)
|
24
|
+
* Adding fixes for click button/link and made the integration specs pass for the same in selenium lh254 (Ldiehl, Matthias Marschall)
|
25
|
+
* Adding clicking link by id in selenium mode lh221 (larrytheliquid)
|
26
|
+
* Adding fix for have_selector and have_xpath in descendent blocks lh234 (Thomas Jack)
|
27
|
+
* Adding fix for fields with labels with special characters (Thomas Jack, Mike Gaffney, Bryan Hemlkamp)
|
28
|
+
* Deprecated current_page lh50 (Mike Gaffney)
|
29
|
+
* Fixed issue with redirects and multiple hosts lh168 (Mutwin Kraus)
|
30
|
+
|
31
|
+
* Bug fixes
|
32
|
+
|
33
|
+
* Wait for application servers socket on 0.0.0.0 instead of the application_address
|
34
|
+
* Translate CSS and image paths with single quotes in save_and_open_page (Erin Staniland)
|
35
|
+
|
1
36
|
== 0.4.4 / 2009-04-06
|
2
37
|
|
3
38
|
* Major enhancements
|
4
39
|
|
5
40
|
* Make selenium process management code more robust and informative
|
6
|
-
|
41
|
+
|
7
42
|
* Minor enhancements
|
8
|
-
|
43
|
+
|
9
44
|
* Add support for Rails javascript post links (Mark Menard)
|
10
45
|
* Upgrade selenium-client dependency to 1.2.14, and update for new waiting
|
11
46
|
API (Balint Erdi)
|
@@ -16,7 +51,7 @@
|
|
16
51
|
* Don't create a new instance of WWW::Mechanize for each request
|
17
52
|
(Mark Menard)
|
18
53
|
* Select fields with duplicate selected options sent an incorrect value (Noah Davis)
|
19
|
-
|
54
|
+
|
20
55
|
== 0.4.3 / 2009-03-17
|
21
56
|
|
22
57
|
* Minor enhancements
|
@@ -26,7 +61,7 @@
|
|
26
61
|
* Initial Merb and Sinatra compatibility for Selenium mode (Corey Donohoe)
|
27
62
|
* When faced with a label with no for attribute, that contains a hidden field
|
28
63
|
and another field, as can be the case in Rails 2.3's checkbox view,
|
29
|
-
webrat now locates the non-hidden field. (Luke Melia)
|
64
|
+
webrat now locates the non-hidden field. (Luke Melia)
|
30
65
|
* Add application_framework config for Selenium mode to determine how to
|
31
66
|
start and stop the app server (Corey Donohoe)
|
32
67
|
|
@@ -42,7 +77,7 @@
|
|
42
77
|
attributes in a hash and :count and :content options. See
|
43
78
|
have_selector_spec.rb for more.
|
44
79
|
* Add the same functionality mentioned above to have_xpath
|
45
|
-
|
80
|
+
|
46
81
|
* Minor enhancements
|
47
82
|
|
48
83
|
* Squeeze extra whitespace out of failures messages from contain
|
@@ -69,7 +104,7 @@
|
|
69
104
|
redirected to (Adam Greene)
|
70
105
|
* Recognize input tags with type button (Lena Herrmann)
|
71
106
|
* Add uncheck method to Selenium mode (Lee Bankewitz)
|
72
|
-
|
107
|
+
|
73
108
|
* Bug fixes
|
74
109
|
|
75
110
|
* Make requests to a Rails app using a full URL instead of a relative path. This change
|
@@ -80,7 +115,7 @@
|
|
80
115
|
to behave correctly (Noah Davis)
|
81
116
|
* Switch to using selenium.click instead of .check when checking a checkbox
|
82
117
|
(Noah Davis)
|
83
|
-
* Create tmp/pids directory if directory does not exist. (Amos King and Mike Gaffney)
|
118
|
+
* Create tmp/pids directory if directory does not exist. (Amos King and Mike Gaffney)
|
84
119
|
* Setup deprecated writers for the selenium_environment= and selenium_port= config
|
85
120
|
* Ensure the previous pages params aren't passed through redirect (Daniel Lucraft and
|
86
121
|
Bryan Helmkamp)
|
@@ -156,7 +191,7 @@
|
|
156
191
|
* Added save_and_open_screengrab for Selenium mode (Luke Melia)
|
157
192
|
|
158
193
|
* Bug fixes
|
159
|
-
|
194
|
+
|
160
195
|
* field_labeled should disregard labels without matching fields (Kyle Hargraves)
|
161
196
|
* Fixed bug where Scope was creating a new DOM rather than re-using the existing DOM.
|
162
197
|
[#105] (Zach Dennis)
|
data/README.rdoc
CHANGED
@@ -11,6 +11,18 @@
|
|
11
11
|
Webrat lets you quickly write expressive and robust acceptance tests for a Ruby
|
12
12
|
web application.
|
13
13
|
|
14
|
+
== NOTA BENE: About the dbrady fork
|
15
|
+
|
16
|
+
This fork includes a patch that fixes Sinatra cookies so cucumber can
|
17
|
+
test cookie-based sessions. In all other regards, it is a tracking
|
18
|
+
fork of brynary's webrat. Once this patch (which has been pending
|
19
|
+
since February 2009, hem-HEM!) has been merged into core Sinatra, I
|
20
|
+
will pull down this fork.
|
21
|
+
|
22
|
+
Also, adds webrat/rack_test.rb to the gemspec so the file gets
|
23
|
+
installed. This is needed if you want your hancock specs to pass.
|
24
|
+
(http://github.com/atmos/hancock).
|
25
|
+
|
14
26
|
== Features
|
15
27
|
|
16
28
|
* Browser Simulator for expressive, high level acceptance testing without the
|
@@ -82,4 +94,4 @@ methods from Webrat::Session in your specs.
|
|
82
94
|
== License
|
83
95
|
|
84
96
|
Copyright (c) 2007-2008 Bryan Helmkamp, Seth Fitzsimmons.
|
85
|
-
See MIT-LICENSE.txt in this directory.
|
97
|
+
See MIT-LICENSE.txt in this directory.
|
data/Rakefile
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require "rake/gempackagetask"
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
require "rake/clean"
|
5
|
+
gem "rspec", "1.2.6"
|
5
6
|
require 'spec'
|
6
7
|
require 'spec/rake/spectask'
|
7
8
|
require 'spec/rake/verify_rcov'
|
@@ -85,10 +86,47 @@ task :docs => :clobber_docs do
|
|
85
86
|
system "hanna --title 'Webrat #{Webrat::VERSION} API Documentation'"
|
86
87
|
end
|
87
88
|
|
88
|
-
desc "Run
|
89
|
-
task
|
89
|
+
desc "Run everything against multiruby"
|
90
|
+
task :multiruby do
|
91
|
+
result = system "multiruby -S rake spec"
|
92
|
+
raise "Multiruby tests failed" unless result
|
90
93
|
result = system "jruby -S rake spec"
|
91
94
|
raise "JRuby tests failed" unless result
|
95
|
+
|
96
|
+
Dir.chdir "spec/integration/rails" do
|
97
|
+
result = system "multiruby -S rake test_unit:rails"
|
98
|
+
raise "Rails integration tests failed" unless result
|
99
|
+
|
100
|
+
result = system "jruby -S rake test_unit:rails"
|
101
|
+
raise "Rails integration tests failed" unless result
|
102
|
+
end
|
103
|
+
|
104
|
+
Dir.chdir "spec/integration/merb" do
|
105
|
+
result = system "multiruby -S rake spec"
|
106
|
+
raise "Merb integration tests failed" unless result
|
107
|
+
|
108
|
+
result = system "jruby -S rake spec"
|
109
|
+
raise "Rails integration tests failed" unless result
|
110
|
+
end
|
111
|
+
|
112
|
+
Dir.chdir "spec/integration/sinatra" do
|
113
|
+
result = system "multiruby -S rake test"
|
114
|
+
raise "Sinatra integration tests failed" unless result
|
115
|
+
|
116
|
+
result = system "jruby -S rake test"
|
117
|
+
raise "Sinatra integration tests failed" unless result
|
118
|
+
end
|
119
|
+
|
120
|
+
Dir.chdir "spec/integration/rack" do
|
121
|
+
result = system "multiruby -S rake test"
|
122
|
+
raise "Rack integration tests failed" unless result
|
123
|
+
|
124
|
+
result = system "jruby -S rake test"
|
125
|
+
raise "Rack integration tests failed" unless result
|
126
|
+
end
|
127
|
+
|
128
|
+
puts
|
129
|
+
puts "Multiruby OK!"
|
92
130
|
end
|
93
131
|
|
94
132
|
desc "Run each spec in isolation to test for dependency issues"
|
@@ -106,7 +144,7 @@ end
|
|
106
144
|
|
107
145
|
namespace :spec do
|
108
146
|
desc "Run the integration specs"
|
109
|
-
task :integration => ["integration:rails", "integration:merb", "integration:sinatra"]
|
147
|
+
task :integration => ["integration:rails", "integration:merb", "integration:sinatra", "integration:rack"]
|
110
148
|
|
111
149
|
namespace :integration do
|
112
150
|
desc "Run the Rails integration specs"
|
@@ -140,7 +178,15 @@ namespace :spec do
|
|
140
178
|
task :sinatra do
|
141
179
|
Dir.chdir "spec/integration/sinatra" do
|
142
180
|
result = system "rake test"
|
143
|
-
raise "Sinatra
|
181
|
+
raise "Sinatra integration tests failed" unless result
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
desc "Run the Sinatra integration specs"
|
186
|
+
task :rack do
|
187
|
+
Dir.chdir "spec/integration/rack" do
|
188
|
+
result = system "rake test"
|
189
|
+
raise "Rack integration tests failed" unless result
|
144
190
|
end
|
145
191
|
end
|
146
192
|
end
|
@@ -148,8 +194,6 @@ end
|
|
148
194
|
|
149
195
|
task :default => :spec
|
150
196
|
|
151
|
-
task :precommit => ["spec", "spec:jruby", "spec:integration"]
|
152
|
-
|
153
197
|
desc 'Removes trailing whitespace'
|
154
198
|
task :whitespace do
|
155
199
|
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
|
data/lib/webrat.rb
CHANGED
@@ -10,17 +10,14 @@ module Webrat
|
|
10
10
|
VERSION = '0.4.4'
|
11
11
|
|
12
12
|
def self.require_xml
|
13
|
-
gem "nokogiri", ">= 1.0.6"
|
14
|
-
|
15
13
|
if on_java?
|
16
|
-
|
17
|
-
require "nokogiri/css"
|
18
|
-
require "hpricot"
|
19
|
-
require "rexml/document"
|
14
|
+
gem "nokogiri", ">= 1.2.4"
|
20
15
|
else
|
21
|
-
|
22
|
-
require "webrat/core/xml/nokogiri"
|
16
|
+
gem "nokogiri", ">= 1.0.6"
|
23
17
|
end
|
18
|
+
|
19
|
+
require "nokogiri"
|
20
|
+
require "webrat/core/xml/nokogiri"
|
24
21
|
end
|
25
22
|
|
26
23
|
def self.on_java?
|
@@ -54,13 +54,16 @@ module Webrat
|
|
54
54
|
# Set the key that Selenium uses to determine the browser running. Default *firefox
|
55
55
|
attr_accessor :selenium_browser_key
|
56
56
|
|
57
|
+
# Set the timeout for waiting for the browser process to start
|
58
|
+
attr_accessor :selenium_browser_startup_timeout
|
59
|
+
|
57
60
|
# How many redirects to the same URL should be halted as an infinite redirect
|
58
61
|
# loop? Defaults to 10
|
59
62
|
attr_accessor :infinite_redirect_limit
|
60
63
|
|
61
64
|
def initialize # :nodoc:
|
62
65
|
self.open_error_files = true
|
63
|
-
self.parse_with_nokogiri =
|
66
|
+
self.parse_with_nokogiri = true
|
64
67
|
self.application_environment = :test
|
65
68
|
self.application_port = 3001
|
66
69
|
self.application_address = 'localhost'
|
@@ -68,6 +71,7 @@ module Webrat
|
|
68
71
|
self.selenium_server_port = 4444
|
69
72
|
self.infinite_redirect_limit = 10
|
70
73
|
self.selenium_browser_key = '*firefox'
|
74
|
+
self.selenium_browser_startup_timeout = 5
|
71
75
|
end
|
72
76
|
|
73
77
|
def parse_with_nokogiri? #:nodoc:
|
@@ -87,6 +87,8 @@ module Webrat
|
|
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
|
@@ -132,7 +134,7 @@ module Webrat
|
|
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
|
@@ -356,10 +358,16 @@ module Webrat
|
|
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
|
|
@@ -45,7 +45,15 @@ module Webrat
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def replace_nbsp(str)
|
48
|
-
str.
|
48
|
+
if str.respond_to?(:valid_encoding?)
|
49
|
+
if str.valid_encoding?
|
50
|
+
str.gsub(/\xc2\xa0/u, ' ')
|
51
|
+
else
|
52
|
+
str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ')
|
53
|
+
end
|
54
|
+
else
|
55
|
+
str.gsub(/\xc2\xa0/u, ' ')
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
def replace_nbsp_ref(str)
|
data/lib/webrat/core/logging.rb
CHANGED
@@ -32,7 +32,7 @@ module Webrat
|
|
32
32
|
|
33
33
|
def rexml_matches(stringlike)
|
34
34
|
if REXML::Node === stringlike || Array === stringlike
|
35
|
-
@query = query.map { |q| q.gsub(%r'
|
35
|
+
@query = query.map { |q| q.gsub(%r'^//', './/') }
|
36
36
|
else
|
37
37
|
@query = query
|
38
38
|
end
|
@@ -52,7 +52,7 @@ module Webrat
|
|
52
52
|
|
53
53
|
def nokogiri_matches(stringlike)
|
54
54
|
if Nokogiri::XML::NodeSet === stringlike
|
55
|
-
@query = query.gsub(%r'
|
55
|
+
@query = query.gsub(%r'^//', './/')
|
56
56
|
else
|
57
57
|
@query = query
|
58
58
|
end
|
data/lib/webrat/core/methods.rb
CHANGED
@@ -16,7 +16,11 @@ module Webrat
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def webrat_session
|
19
|
-
|
19
|
+
if Webrat.configuration.mode == :rack_test
|
20
|
+
@_webrat_session ||= ::Webrat::RackTestSession.new(rack_test_session)
|
21
|
+
else
|
22
|
+
@_webrat_session ||= ::Webrat.session_class.new(self)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
# all of these methods delegate to the @session, which should
|
@@ -53,9 +57,7 @@ module Webrat
|
|
53
57
|
:field_by_xpath,
|
54
58
|
:field_with_id,
|
55
59
|
:selenium,
|
56
|
-
:simulate, :automate
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
:simulate, :automate,
|
61
|
+
:field_named
|
60
62
|
end
|
61
63
|
end
|
@@ -18,17 +18,15 @@ module Webrat
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def open_in_browser(path) # :nodoc
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
`open #{path}`
|
26
|
-
end
|
21
|
+
require "launchy"
|
22
|
+
Launchy::Browser.run(path)
|
23
|
+
rescue LoadError
|
24
|
+
warn "Sorry, you need to install launchy to open pages: `gem install launchy`"
|
27
25
|
end
|
28
26
|
|
29
27
|
def rewrite_css_and_image_references(response_html) # :nodoc:
|
30
28
|
return response_html unless doc_root
|
31
|
-
response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\
|
29
|
+
response_html.gsub(/("|')\/(stylesheets|images)/, '\1' + doc_root + '/\2')
|
32
30
|
end
|
33
31
|
|
34
32
|
def saved_page_dir #:nodoc:
|
data/lib/webrat/core/scope.rb
CHANGED
@@ -209,8 +209,8 @@ module Webrat
|
|
209
209
|
# along with the form. An optional <tt>content_type</tt> may be given.
|
210
210
|
#
|
211
211
|
# Example:
|
212
|
-
#
|
213
|
-
#
|
212
|
+
# attach_file "Resume", "/path/to/the/resume.txt"
|
213
|
+
# attach_file "Photo", "/path/to/the/image.png", "image/png"
|
214
214
|
def attach_file(field_locator, path, content_type = nil)
|
215
215
|
locate_field(field_locator, FileField).set(path, content_type)
|
216
216
|
end
|
data/lib/webrat/core/session.rb
CHANGED
@@ -26,6 +26,8 @@ module Webrat
|
|
26
26
|
SinatraSession
|
27
27
|
when :mechanize
|
28
28
|
MechanizeSession
|
29
|
+
when :rack_test
|
30
|
+
RackTestSession
|
29
31
|
else
|
30
32
|
raise WebratError.new(<<-STR)
|
31
33
|
Unknown Webrat mode: #{Webrat.configuration.mode.inspect}
|
@@ -67,6 +69,7 @@ For example:
|
|
67
69
|
|
68
70
|
# For backwards compatibility -- removing in 1.0
|
69
71
|
def current_page #:nodoc:
|
72
|
+
warn "current_page is deprecated and will be going away in the next release. Use current_url instead."
|
70
73
|
page = OpenStruct.new
|
71
74
|
page.url = @current_url
|
72
75
|
page.http_method = @http_method
|
@@ -100,11 +103,8 @@ For example:
|
|
100
103
|
h['HTTP_REFERER'] = @current_url if @current_url
|
101
104
|
|
102
105
|
debug_log "REQUESTING PAGE: #{http_method.to_s.upcase} #{url} with #{data.inspect} and HTTP headers #{h.inspect}"
|
103
|
-
|
104
|
-
|
105
|
-
else
|
106
|
-
send "#{http_method}", url, data || {}, h
|
107
|
-
end
|
106
|
+
|
107
|
+
process_request(http_method, url, data, h)
|
108
108
|
|
109
109
|
save_and_open_page if exception_caught? && Webrat.configuration.open_error_files?
|
110
110
|
raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
|
@@ -144,7 +144,7 @@ For example:
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def redirect? #:nodoc:
|
147
|
-
response_code / 100 == 3
|
147
|
+
(response_code / 100).to_i == 3
|
148
148
|
end
|
149
149
|
|
150
150
|
def internal_redirect?
|
@@ -256,15 +256,24 @@ For example:
|
|
256
256
|
def_delegators :current_scope, :field_by_xpath
|
257
257
|
def_delegators :current_scope, :field_with_id
|
258
258
|
def_delegators :current_scope, :select_option
|
259
|
+
def_delegators :current_scope, :field_named
|
259
260
|
|
260
261
|
private
|
261
262
|
|
263
|
+
def process_request(http_method, url, data, headers)
|
264
|
+
if headers.empty?
|
265
|
+
send "#{http_method}", url, data || {}
|
266
|
+
else
|
267
|
+
send "#{http_method}", url, data || {}, headers
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
262
271
|
def response_location
|
263
272
|
response.headers["Location"]
|
264
273
|
end
|
265
274
|
|
266
275
|
def current_host
|
267
|
-
URI.parse(current_url).host || "www.example.com"
|
276
|
+
URI.parse(current_url).host || @custom_headers["Host"] || "www.example.com"
|
268
277
|
end
|
269
278
|
|
270
279
|
def response_location_host
|
data/lib/webrat/mechanize.rb
CHANGED
data/lib/webrat/merb_session.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
require "webrat"
|
2
|
-
|
3
|
-
require "cgi"
|
4
|
-
gem "extlib"
|
5
|
-
require "extlib"
|
6
2
|
require "merb-core"
|
7
|
-
|
8
|
-
# HashWithIndifferentAccess = Mash
|
3
|
+
require "webrat/merb_multipart_support"
|
9
4
|
|
10
5
|
module Webrat
|
11
6
|
class MerbSession < Session #:nodoc:
|
12
7
|
include Merb::Test::MakeRequest
|
13
8
|
|
9
|
+
# Include Webrat's own version of multipart_post/put because the officially
|
10
|
+
# supported methods in Merb don't perform the request correctly.
|
11
|
+
include MerbMultipartSupport
|
12
|
+
|
14
13
|
attr_accessor :response
|
15
14
|
|
16
15
|
def get(url, data, headers = nil)
|
@@ -38,12 +37,34 @@ module Webrat
|
|
38
37
|
end
|
39
38
|
|
40
39
|
def do_request(url, data, headers, method)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
if method == "POST" && has_file?(data)
|
41
|
+
@response = multipart_post(url, data, :headers => headers)
|
42
|
+
|
43
|
+
elsif method == "PUT" && has_file?(data)
|
44
|
+
@response = multipart_put(url, data, :headers => headers)
|
45
|
+
|
46
|
+
else
|
47
|
+
@response = request(url,
|
48
|
+
:params => (data && data.any?) ? data : nil,
|
49
|
+
:headers => headers,
|
50
|
+
:method => method)
|
51
|
+
end
|
45
52
|
end
|
46
53
|
|
54
|
+
protected
|
55
|
+
|
56
|
+
# Recursively search the data for a file attachment.
|
57
|
+
def has_file?(data)
|
58
|
+
data.each do |key, value|
|
59
|
+
if value.is_a?(Hash)
|
60
|
+
return has_file?(value)
|
61
|
+
else
|
62
|
+
return true if value.is_a?(File)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return false
|
66
|
+
end
|
67
|
+
|
47
68
|
end
|
48
69
|
end
|
49
70
|
|
@@ -57,9 +78,3 @@ module Merb #:nodoc:
|
|
57
78
|
end
|
58
79
|
end
|
59
80
|
end
|
60
|
-
|
61
|
-
class Merb::Test::RspecStory #:nodoc:
|
62
|
-
def browser
|
63
|
-
@browser ||= Webrat::MerbSession.new
|
64
|
-
end
|
65
|
-
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Webrat
|
2
|
+
class RackTestSession < Session
|
3
|
+
|
4
|
+
def initialize(rack_test_session) #:nodoc:
|
5
|
+
super()
|
6
|
+
@rack_test_session = rack_test_session
|
7
|
+
end
|
8
|
+
|
9
|
+
def response_body
|
10
|
+
response.body
|
11
|
+
end
|
12
|
+
|
13
|
+
def response_code
|
14
|
+
response.status
|
15
|
+
end
|
16
|
+
|
17
|
+
def response
|
18
|
+
@rack_test_session.last_response
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def process_request(http_method, url, data = {}, headers = {})
|
24
|
+
headers ||= {}
|
25
|
+
data ||= {}
|
26
|
+
|
27
|
+
env = headers.merge(:params => data, :method => http_method.to_s.upcase)
|
28
|
+
@rack_test_session.request(url, env)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/webrat/rspec-rails.rb
CHANGED
@@ -6,8 +6,5 @@
|
|
6
6
|
require "webrat/core/matchers"
|
7
7
|
|
8
8
|
Spec::Runner.configure do |config|
|
9
|
-
|
10
|
-
config.include(Webrat::Matchers, :type => :controller)
|
11
|
-
config.include(Webrat::Matchers, :type => :helper)
|
12
|
-
config.include(Webrat::Matchers, :type => :view)
|
9
|
+
config.include(Webrat::Matchers, :type => [:controller, :helper, :view])
|
13
10
|
end
|
data/lib/webrat/selenium.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "webrat"
|
2
|
-
gem "selenium-client", ">=1.2.
|
2
|
+
gem "selenium-client", ">=1.2.16"
|
3
3
|
require "selenium/client"
|
4
|
+
require "webrat/selenium/silence_stream"
|
4
5
|
require "webrat/selenium/selenium_session"
|
5
6
|
require "webrat/selenium/matchers"
|
6
7
|
require "webrat/core_extensions/tcp_socket"
|
@@ -1,12 +1,19 @@
|
|
1
1
|
if (locator == '*') {
|
2
2
|
return selenium.browserbot.locationStrategies['xpath'].call(this, "//input[@type='submit']", inDocument, inWindow)
|
3
3
|
}
|
4
|
+
var buttons = inDocument.getElementsByTagName('button');
|
4
5
|
var inputs = inDocument.getElementsByTagName('input');
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
var result = $A(inputs).concat($A(buttons)).find(function(candidate){
|
7
|
+
var type = candidate.getAttribute('type');
|
8
|
+
if (type == 'submit' || type == 'image' || type == 'button') {
|
9
|
+
var matches_id = PatternMatcher.matches(locator, candidate.id);
|
10
|
+
var matches_value = PatternMatcher.matches(locator, candidate.value);
|
11
|
+
var matches_html = PatternMatcher.matches(locator, candidate.innerHTML);
|
12
|
+
var matches_alt = PatternMatcher.matches(locator, candidate.alt);
|
13
|
+
if (matches_id || matches_value || matches_html || matches_alt) {
|
14
|
+
return true;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
return false;
|
12
18
|
});
|
19
|
+
return result;
|
@@ -1,6 +1,9 @@
|
|
1
1
|
var links = inDocument.getElementsByTagName('a');
|
2
2
|
var candidateLinks = $A(links).select(function(candidateLink) {
|
3
|
-
|
3
|
+
var textMatched = PatternMatcher.matches(locator, getText(candidateLink));
|
4
|
+
var idMatched = PatternMatcher.matches(locator, candidateLink.id);
|
5
|
+
var titleMatched = PatternMatcher.matches(locator, candidateLink.title);
|
6
|
+
return textMatched || idMatched || titleMatched;
|
4
7
|
});
|
5
8
|
if (candidateLinks.length == 0) {
|
6
9
|
return null;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "webrat/core/save_and_open_page"
|
2
2
|
require "webrat/selenium/selenium_rc_server"
|
3
|
-
require "webrat/selenium/
|
3
|
+
require "webrat/selenium/application_server_factory"
|
4
|
+
require "webrat/selenium/application_servers/base"
|
4
5
|
|
5
6
|
module Webrat
|
6
7
|
class TimeoutError < WebratError
|
@@ -22,6 +23,7 @@ module Webrat
|
|
22
23
|
|
23
24
|
class SeleniumSession
|
24
25
|
include Webrat::SaveAndOpenPage
|
26
|
+
include Webrat::Selenium::SilenceStream
|
25
27
|
|
26
28
|
def initialize(*args) # :nodoc:
|
27
29
|
end
|
@@ -40,7 +42,7 @@ module Webrat
|
|
40
42
|
webrat_deprecate :visits, :visit
|
41
43
|
|
42
44
|
def fill_in(field_identifier, options)
|
43
|
-
locator = "webrat=#{
|
45
|
+
locator = "webrat=#{field_identifier}"
|
44
46
|
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
45
47
|
selenium.type(locator, "#{options[:with]}")
|
46
48
|
end
|
@@ -55,6 +57,10 @@ module Webrat
|
|
55
57
|
selenium.get_html_source
|
56
58
|
end
|
57
59
|
|
60
|
+
def current_url
|
61
|
+
selenium.location
|
62
|
+
end
|
63
|
+
|
58
64
|
def click_button(button_text_or_regexp = nil, options = {})
|
59
65
|
if button_text_or_regexp.is_a?(Hash) && options == {}
|
60
66
|
pattern, options = nil, button_text_or_regexp
|
@@ -145,8 +151,10 @@ module Webrat
|
|
145
151
|
|
146
152
|
begin
|
147
153
|
value = yield
|
148
|
-
rescue
|
149
|
-
|
154
|
+
rescue Exception => e
|
155
|
+
unless is_ignorable_wait_for_exception?(e)
|
156
|
+
raise e
|
157
|
+
end
|
150
158
|
end
|
151
159
|
|
152
160
|
return value if value
|
@@ -177,23 +185,22 @@ module Webrat
|
|
177
185
|
else
|
178
186
|
$browser.capture_screenshot(filename)
|
179
187
|
end
|
180
|
-
|
181
|
-
end
|
188
|
+
open_in_browser(filename)
|
182
189
|
|
183
|
-
|
190
|
+
end
|
184
191
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
+
protected
|
193
|
+
def is_ignorable_wait_for_exception?(exception) #:nodoc:
|
194
|
+
if defined?(::Spec::Expectations::ExpectationNotMetError)
|
195
|
+
return true if exception.class == ::Spec::Expectations::ExpectationNotMetError
|
196
|
+
end
|
197
|
+
return true if [::Selenium::CommandError, Webrat::WebratError].include?(exception.class)
|
198
|
+
return false
|
192
199
|
end
|
193
200
|
|
194
201
|
def setup #:nodoc:
|
195
202
|
Webrat::Selenium::SeleniumRCServer.boot
|
196
|
-
Webrat::Selenium::
|
203
|
+
Webrat::Selenium::ApplicationServerFactory.app_server_instance.boot
|
197
204
|
|
198
205
|
create_browser
|
199
206
|
$browser.start
|
@@ -206,7 +213,7 @@ module Webrat
|
|
206
213
|
|
207
214
|
def create_browser
|
208
215
|
$browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
|
209
|
-
|
216
|
+
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}")
|
210
217
|
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address
|
211
218
|
|
212
219
|
at_exit do
|
data/vendor/selenium-server.jar
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbrady-webrat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.4.
|
4
|
+
version: 0.4.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Brady
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-17 10:31:47.766398 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/webrat/rack.rb
|
92
92
|
- lib/webrat/rails.rb
|
93
93
|
- lib/webrat/rspec-rails.rb
|
94
|
+
- lib/webrat/rack_test.rb
|
94
95
|
- lib/webrat/selenium
|
95
96
|
- lib/webrat/selenium/location_strategy_javascript
|
96
97
|
- lib/webrat/selenium/location_strategy_javascript/button.js
|