webrat 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +17 -0
- data/lib/webrat.rb +1 -1
- data/lib/webrat/core/configuration.rb +5 -1
- data/lib/webrat/core/elements/field.rb +12 -5
- data/lib/webrat/core/elements/label.rb +1 -1
- data/lib/webrat/selenium.rb +69 -14
- data/lib/webrat/selenium/selenium_session.rb +13 -3
- data/lib/webrat/sinatra.rb +34 -20
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
== 0.4.3 / 2009-03-17
|
2
|
+
|
3
|
+
* Minor enhancements
|
4
|
+
|
5
|
+
* Support Rails 2.3. Use Rack::Utils to parse params (Matthew Ford)
|
6
|
+
* Support for "modular" Sinatra app style (Simon Rozet)
|
7
|
+
* Initial Merb and Sinatra compatibility for Selenium mode (Corey Donohoe)
|
8
|
+
* When faced with a label with no for attribute, that contains a hidden field
|
9
|
+
and another field, as can be the case in Rails 2.3's checkbox view,
|
10
|
+
webrat now locates the non-hidden field. (Luke Melia)
|
11
|
+
* Add application_framework config for Selenium mode to determine how to
|
12
|
+
start and stop the app server (Corey Donohoe)
|
13
|
+
|
14
|
+
* Bug fixes
|
15
|
+
|
16
|
+
* Fix following of absolute redirect URL in Sinatra (Simon Rozet)
|
17
|
+
|
1
18
|
== 0.4.2 / 2009-02-24
|
2
19
|
|
3
20
|
* Major enhancements
|
data/lib/webrat.rb
CHANGED
@@ -39,6 +39,9 @@ module Webrat
|
|
39
39
|
webrat_deprecate :selenium_port, :application_port
|
40
40
|
webrat_deprecate :selenium_port=, :application_port=
|
41
41
|
|
42
|
+
# Which underlying app framework we're testing with selenium
|
43
|
+
attr_accessor :application_framework
|
44
|
+
|
42
45
|
# Which server the application is running on for selenium testing? Defaults to localhost
|
43
46
|
attr_accessor :application_address
|
44
47
|
|
@@ -61,6 +64,7 @@ module Webrat
|
|
61
64
|
self.application_environment = :selenium
|
62
65
|
self.application_port = 3001
|
63
66
|
self.application_address = 'localhost'
|
67
|
+
self.application_framework = 'rails'
|
64
68
|
self.selenium_server_port = 4444
|
65
69
|
self.infinite_redirect_limit = 10
|
66
70
|
self.selenium_browser_key = '*firefox'
|
@@ -91,4 +95,4 @@ module Webrat
|
|
91
95
|
|
92
96
|
end
|
93
97
|
|
94
|
-
end
|
98
|
+
end
|
@@ -15,6 +15,10 @@ module Webrat
|
|
15
15
|
def self.xpath_search
|
16
16
|
[".//button", ".//input", ".//textarea", ".//select"]
|
17
17
|
end
|
18
|
+
|
19
|
+
def self.xpath_search_excluding_hidden
|
20
|
+
[".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
|
21
|
+
end
|
18
22
|
|
19
23
|
def self.field_classes
|
20
24
|
@field_classes || []
|
@@ -80,7 +84,7 @@ module Webrat
|
|
80
84
|
|
81
85
|
case Webrat.configuration.mode
|
82
86
|
when :rails
|
83
|
-
|
87
|
+
parse_rails_request_params("#{name}=#{escaped_value}")
|
84
88
|
when :merb
|
85
89
|
::Merb::Parse.query("#{name}=#{escaped_value}")
|
86
90
|
else
|
@@ -98,12 +102,15 @@ module Webrat
|
|
98
102
|
|
99
103
|
protected
|
100
104
|
|
101
|
-
def
|
105
|
+
def parse_rails_request_params(params)
|
102
106
|
if defined?(ActionController::AbstractRequest)
|
103
|
-
ActionController::AbstractRequest
|
104
|
-
|
107
|
+
ActionController::AbstractRequest.parse_query_parameters(params)
|
108
|
+
elsif defined?(ActionController::UrlEncodedPairParser)
|
105
109
|
# For Rails > 2.2
|
106
|
-
ActionController::UrlEncodedPairParser
|
110
|
+
ActionController::UrlEncodedPairParser.parse_query_parameters(params)
|
111
|
+
else
|
112
|
+
# For Rails > 2.3
|
113
|
+
Rack::Utils.parse_nested_query(params)
|
107
114
|
end
|
108
115
|
end
|
109
116
|
|
@@ -21,7 +21,7 @@ module Webrat
|
|
21
21
|
|
22
22
|
def field_element
|
23
23
|
if for_id.blank?
|
24
|
-
Webrat::XML.xpath_at(@element, *Field.
|
24
|
+
Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
|
25
25
|
else
|
26
26
|
Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
|
27
27
|
end
|
data/lib/webrat/selenium.rb
CHANGED
@@ -25,15 +25,55 @@ module Webrat
|
|
25
25
|
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.
|
29
|
-
|
30
|
-
|
28
|
+
def self.pid_file
|
29
|
+
if File.exists?('config.ru')
|
30
|
+
prepare_pid_file(Dir.pwd, 'rack.pid')
|
31
|
+
else
|
32
|
+
prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
# Start the appserver for the underlying framework to test
|
36
|
+
#
|
37
|
+
# Sinatra: requires a config.ru in the root of your sinatra app to use this
|
38
|
+
# Merb: Attempts to use bin/merb and falls back to the system merb
|
39
|
+
# Rails: Calls mongrel_rails to startup the appserver
|
40
|
+
def self.start_app_server
|
41
|
+
case Webrat.configuration.application_framework
|
42
|
+
when :sinatra
|
43
|
+
fork do
|
44
|
+
File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
|
45
|
+
exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
|
46
|
+
end
|
47
|
+
when :merb
|
48
|
+
cmd = 'merb'
|
49
|
+
if File.exist?('bin/merb')
|
50
|
+
cmd = 'bin/merb'
|
51
|
+
end
|
52
|
+
system("#{cmd} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}")
|
53
|
+
else # rails
|
54
|
+
system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
|
55
|
+
end
|
31
56
|
TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
|
32
57
|
end
|
33
58
|
|
34
|
-
|
35
|
-
|
36
|
-
|
59
|
+
# Stop the appserver for the underlying framework under test
|
60
|
+
#
|
61
|
+
# Sinatra: Reads and kills the pid from the pid file created on startup
|
62
|
+
# Merb: Reads and kills the pid from the pid file created on startup
|
63
|
+
# Rails: Calls mongrel_rails stop to kill the appserver
|
64
|
+
def self.stop_app_server
|
65
|
+
case Webrat.configuration.application_framework
|
66
|
+
when :sinatra
|
67
|
+
pid = File.read('rack.pid')
|
68
|
+
system("kill -9 #{pid}")
|
69
|
+
FileUtils.rm_f 'rack.pid'
|
70
|
+
when :merb
|
71
|
+
pid = File.read("log/merb.#{Webrat.configuration.application_port}.pid")
|
72
|
+
system("kill -9 #{pid}")
|
73
|
+
FileUtils.rm_f "log/merb.#{Webrat.configuration.application_port}.pid"
|
74
|
+
else # rails
|
75
|
+
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
76
|
+
end
|
37
77
|
end
|
38
78
|
|
39
79
|
def self.prepare_pid_file(file_path, pid_file_name)
|
@@ -60,11 +100,25 @@ module Webrat
|
|
60
100
|
# selenium.dragdrop("id=photo_123", "+350, 0")
|
61
101
|
# end
|
62
102
|
#
|
63
|
-
# ==
|
103
|
+
# == Choosing the underlying framework to test
|
104
|
+
#
|
105
|
+
# Webrat assumes you're using rails by default but it can also work with sinatra
|
106
|
+
# and merb. To take advantage of this you can use the configuration block to
|
107
|
+
# set the application_framework variable.
|
108
|
+
# require "webrat"
|
109
|
+
#
|
110
|
+
# Webrat.configure do |config|
|
111
|
+
# config.mode = :selenium
|
112
|
+
# config.application_port = 4567
|
113
|
+
# config.application_framework = :sinatra # could also be :merb
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# == Auto-starting of the appserver and java server
|
64
117
|
#
|
65
118
|
# Webrat will automatically start the Selenium Java server process and an instance
|
66
119
|
# of Mongrel when a test is run. The Mongrel will run in the "selenium" environment
|
67
|
-
# instead of "test", so ensure you've got that defined, and will run on port
|
120
|
+
# instead of "test", so ensure you've got that defined, and will run on port
|
121
|
+
# Webrat.configuration.application_port.
|
68
122
|
#
|
69
123
|
# == Waiting
|
70
124
|
#
|
@@ -89,11 +143,12 @@ module Webrat
|
|
89
143
|
end
|
90
144
|
end
|
91
145
|
end
|
92
|
-
|
93
|
-
module ActionController #:nodoc:
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
146
|
+
if defined?(ActionController::IntegrationTest)
|
147
|
+
module ActionController #:nodoc:
|
148
|
+
IntegrationTest.class_eval do
|
149
|
+
include Webrat::Methods
|
150
|
+
include Webrat::Selenium::Methods
|
151
|
+
include Webrat::Selenium::Matchers
|
152
|
+
end
|
98
153
|
end
|
99
154
|
end
|
@@ -179,11 +179,21 @@ module Webrat
|
|
179
179
|
end
|
180
180
|
|
181
181
|
protected
|
182
|
+
def silence_stream(stream)
|
183
|
+
old_stream = stream.dup
|
184
|
+
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
185
|
+
stream.sync = true
|
186
|
+
yield
|
187
|
+
ensure
|
188
|
+
stream.reopen(old_stream)
|
189
|
+
end
|
182
190
|
|
183
191
|
def setup #:nodoc:
|
184
192
|
silence_stream(STDOUT) do
|
185
|
-
|
186
|
-
|
193
|
+
silence_stream(STDERR) do
|
194
|
+
Webrat.start_selenium_server
|
195
|
+
Webrat.start_app_server
|
196
|
+
end
|
187
197
|
end
|
188
198
|
|
189
199
|
create_browser
|
@@ -234,4 +244,4 @@ module Webrat
|
|
234
244
|
end
|
235
245
|
end
|
236
246
|
end
|
237
|
-
end
|
247
|
+
end
|
data/lib/webrat/sinatra.rb
CHANGED
@@ -1,30 +1,44 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'sinatra/test'
|
4
|
-
|
5
|
-
class Sinatra::Application
|
6
|
-
# Override this to prevent Sinatra from barfing on the options passed from RSpec
|
7
|
-
def self.load_default_options_from_command_line!
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
disable :run
|
12
|
-
disable :reload
|
1
|
+
require "webrat/rack"
|
2
|
+
require "sinatra/test"
|
13
3
|
|
14
4
|
module Webrat
|
15
|
-
class SinatraSession < RackSession
|
5
|
+
class SinatraSession < RackSession
|
16
6
|
include Sinatra::Test
|
17
7
|
|
18
8
|
attr_reader :request, :response
|
19
9
|
|
10
|
+
def initialize(context = nil)
|
11
|
+
super(context)
|
12
|
+
|
13
|
+
app = context.respond_to?(:app) ? context.app : Sinatra::Application
|
14
|
+
@browser = Sinatra::TestHarness.new(app)
|
15
|
+
end
|
16
|
+
|
20
17
|
%w(get head post put delete).each do |verb|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
class_eval <<-RUBY
|
19
|
+
def #{verb}(path, data, headers = {})
|
20
|
+
params = data.inject({}) do |data, (key,value)|
|
21
|
+
data[key] = Rack::Utils.unescape(value)
|
22
|
+
data
|
23
|
+
end
|
24
|
+
headers["HTTP_HOST"] = "www.example.com"
|
25
|
+
@browser.#{verb}(path, params, headers)
|
26
|
+
end
|
27
|
+
RUBY
|
28
28
|
end
|
29
|
+
|
30
|
+
def response_body
|
31
|
+
@browser.body
|
32
|
+
end
|
33
|
+
|
34
|
+
def response_code
|
35
|
+
@browser.status
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def response
|
41
|
+
@browser.response
|
42
|
+
end
|
29
43
|
end
|
30
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webrat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-03-17 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|