brynary-webrat 0.3.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +58 -15
- data/README.rdoc +6 -2
- data/Rakefile +43 -8
- data/lib/webrat.rb +1 -1
- data/lib/webrat/core/configuration.rb +56 -13
- data/lib/webrat/core/elements/field.rb +9 -1
- data/lib/webrat/core/locators/field_labeled_locator.rb +8 -2
- data/lib/webrat/core/matchers/have_content.rb +14 -0
- data/lib/webrat/core/matchers/have_selector.rb +15 -0
- data/lib/webrat/core/matchers/have_tag.rb +14 -0
- data/lib/webrat/core/matchers/have_xpath.rb +10 -0
- data/lib/webrat/core/methods.rb +1 -0
- data/lib/webrat/core/scope.rb +30 -10
- data/lib/webrat/core/session.rb +64 -32
- data/lib/webrat/core/xml/nokogiri.rb +3 -3
- data/lib/webrat/mechanize.rb +33 -2
- data/lib/webrat/merb.rb +6 -74
- data/lib/webrat/merb_session.rb +65 -0
- data/lib/webrat/rack.rb +0 -2
- data/lib/webrat/rails.rb +36 -29
- data/lib/webrat/selenium.rb +30 -43
- data/lib/webrat/selenium/matchers.rb +38 -0
- data/lib/webrat/selenium/selenium_session.rb +52 -46
- data/lib/webrat/sinatra.rb +13 -5
- metadata +4 -5
- data/lib/webrat/rails/redirect_actions.rb +0 -18
data/History.txt
CHANGED
@@ -5,19 +5,31 @@
|
|
5
5
|
* Removed init.rb auto-require of webrat/rails
|
6
6
|
* Removed auto-require of webrat/rails when requiring webrat when RAILS_ENV is
|
7
7
|
defined
|
8
|
-
|
9
|
-
In your env.rb file, ensure you have:
|
10
|
-
|
11
|
-
require "webrat
|
12
|
-
|
8
|
+
|
9
|
+
In your env.rb or test_helper.rb file, ensure you have something like:
|
10
|
+
|
11
|
+
require "webrat"
|
12
|
+
|
13
|
+
Webrat.configure do |config|
|
14
|
+
config.mode = :rails
|
15
|
+
end
|
16
|
+
|
13
17
|
* Major enhancements
|
14
18
|
|
19
|
+
* Added Selenium grid configuration and support. (Amos King && Cornel Borcean)
|
15
20
|
* Added select_time, select_date, and select_datetime to API. [#36] (Ben Mabey)
|
16
21
|
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)
|
17
22
|
|
18
23
|
* Minor enhancements
|
19
24
|
|
25
|
+
* Support passing an ActiveRecord model to #within when in Rails mode [#68] (Luke Melia)
|
26
|
+
* Make assert_* matchers in rails mode increment the assertions count [#123] (Amos King)
|
27
|
+
* Added assert_* matchers to selenium matchers [#110] (Amos King)
|
28
|
+
* Added assert_contain, assert_not_contain [#86] (Mike Gaffney, Amos King)
|
29
|
+
* Add configuration options for the Selenium environment and port (Kieran Pilkington)
|
30
|
+
* Maximize the browser window after initializing Selenium (Luke Melia)
|
20
31
|
* Better inspect output for Webrat elements
|
32
|
+
* Sets the Webrat mode with Configuration#mode= in the config block [#85] (Mike Gaffney)
|
21
33
|
* Detect if the document is XML or HTML using the Content-Type when in Rails mode
|
22
34
|
* Expose #selenium method for direct access to Selenium client
|
23
35
|
* Check nokogiri gem version before requiring nokogiri
|
@@ -51,9 +63,17 @@
|
|
51
63
|
* Raise Webrat::PageLoadError when a failure occurs so that application exceptions
|
52
64
|
can be more accurately tested (Ryan Briones)
|
53
65
|
* Helpful error message for missing option in select box. [#40] (Ben Mabey)
|
66
|
+
* Extracted save_and_open page to make it usable in Selenium mode (Luke Melia)
|
67
|
+
* Added save_and_open_screengrab for Selenium mode (Luke Melia)
|
54
68
|
|
55
69
|
* Bug fixes
|
56
70
|
|
71
|
+
* field_labeled should disregard labels without matching fields (Kyle Hargraves)
|
72
|
+
* Fixed bug where Scope was creating a new DOM rather than re-using the existing DOM.
|
73
|
+
[#105] (Zach Dennis)
|
74
|
+
* Support Rails > v2.2 by using ActionController::RequestParser for param parsing [#107]
|
75
|
+
(Marcello Nuccio)
|
76
|
+
* Raise a Webrat::NotFoundError if the scope passed to #within doesn't exist [#90]
|
57
77
|
* Match against link _text_ which decodes character references.
|
58
78
|
Useful for multibyte languages like Japanese (moronatural@gmail.com)
|
59
79
|
* Fix params hash generation for Mechanize when Merb is not defined [#62]
|
@@ -65,16 +85,39 @@
|
|
65
85
|
* Fixed bug where Webrat would lose complex parameters (like foo[bar[baz]][])
|
66
86
|
in Merb due to not correctly merging Mashes. (Drew Colthorp)
|
67
87
|
* Extend Rails' ActionController::IntegrationTest instead of
|
68
|
-
ActionController::Integration::Session (Fixes using Webrat's #select method and
|
88
|
+
ActionController::Integration::Session (Fixes using Webrat's #select method and
|
69
89
|
avoids usage of method_missing)
|
70
|
-
|
90
|
+
* Ensure that Webrat::MechanizeSession.request_page always uses an absolute
|
91
|
+
URL. (Graham Ashton)
|
92
|
+
* Strip anchor tags from URIs before passing to Rails integration session
|
93
|
+
(Noah Davis)
|
94
|
+
* Treat text and regexp when matching Selenium buttons (Ross Kaffenberger)
|
95
|
+
* Allow SeleniumSession's click_button to be called without an argument without
|
96
|
+
blowing up (Luke Melia)
|
97
|
+
|
98
|
+
== 0.3.4 / 2008-12-29
|
99
|
+
|
100
|
+
* 1 Minor enhancement
|
101
|
+
|
102
|
+
* Fix compatibility with Nokogiri 1.1.0 on JRuby
|
103
|
+
|
104
|
+
* 1 Bug fix
|
105
|
+
|
106
|
+
* Correct version for Nokogiri dependency in gem
|
107
|
+
|
108
|
+
== 0.3.3 / 2008-12-28
|
109
|
+
|
110
|
+
* 1 Minor enhancement
|
111
|
+
|
112
|
+
* Fix compatibility with Nokogiri 1.1.0 on MRI
|
113
|
+
|
71
114
|
== 0.3.2 / 2008-11-08
|
72
115
|
|
73
116
|
* 1 Minor enhancement
|
74
117
|
|
75
118
|
* Fixes behavior or have_tag when a block is passed. It passes the matched node(s)
|
76
119
|
to the block for further specs again. (Carl Lerche)
|
77
|
-
|
120
|
+
|
78
121
|
== 0.3.1 / 2008-11-07
|
79
122
|
|
80
123
|
* 1 Minor enhancement
|
@@ -90,7 +133,7 @@
|
|
90
133
|
* Added experimental Selenium support (Luke Melia)
|
91
134
|
* Add have_selector, have_xpath, have_tag and contain matchers from Merb
|
92
135
|
* Switch from Hpricot to Nokogiri for XML parsing (thanks, Aaron Patterson)
|
93
|
-
|
136
|
+
|
94
137
|
* 37 Minor enhancements
|
95
138
|
|
96
139
|
* Added #within for manipulating the current page within a selector scope
|
@@ -137,7 +180,7 @@
|
|
137
180
|
* Switched tests to specs, and from Mocha to RSpec's mocking library
|
138
181
|
* Add support to click_button for IDs (Gwyn Morfey)
|
139
182
|
* Miscellaneous core refactorings (Jan Suchal)
|
140
|
-
|
183
|
+
|
141
184
|
* 8 Bug fixes
|
142
185
|
|
143
186
|
* Fix initialization of WWW::Mechanize (Derek Kastner)
|
@@ -149,7 +192,7 @@
|
|
149
192
|
* Don't explode if encountering inputs with no type attribute (assume text)
|
150
193
|
* Fix bug where choosing a radio button in a series with a default submitted the
|
151
194
|
incorrect field value (Luke Melia)
|
152
|
-
|
195
|
+
|
153
196
|
== 0.2.0 / 2008-04-04
|
154
197
|
|
155
198
|
* 4 Major enhancements
|
@@ -159,12 +202,12 @@
|
|
159
202
|
* Add basic support for Rails-generated JavaScript link tags
|
160
203
|
* Add support for checkboxes (Patches from Kyle Hargraves and Jarkko Laine)
|
161
204
|
* Add support for textarea fields (Sacha Schlegel)
|
162
|
-
|
205
|
+
|
163
206
|
* 8 Minor enhancements
|
164
|
-
|
207
|
+
|
165
208
|
* Added reloads method to reload the page (Kamal Fariz Mahyuddi)
|
166
209
|
* Prevent making a request if clicking on local anchor link (Kamal Fariz Mahyuddi)
|
167
|
-
* Added clicks_link_within(selector, link_text), allowing restricting link search
|
210
|
+
* Added clicks_link_within(selector, link_text), allowing restricting link search
|
168
211
|
to within a given css selector (Luke Melia)
|
169
212
|
* Allow specifying the input name/label when doing a select (David Chelimsky)
|
170
213
|
* Raise a specific exception if the developer tries to manipulate form elements
|
@@ -172,7 +215,7 @@
|
|
172
215
|
* Add support for alternate POST, PUT and DELETE link clicking (Kyle Hargraves)
|
173
216
|
* Change clicks_link to find the shortest matching link (Luke Melia)
|
174
217
|
* Improve matching for labels in potentially ambiguous cases
|
175
|
-
|
218
|
+
|
176
219
|
* 7 Bug fixes
|
177
220
|
|
178
221
|
* Fix incorrect serializing of collection inputs, i.e. name contains []
|
data/README.rdoc
CHANGED
@@ -59,9 +59,13 @@ To install the latest code as a plugin: (_Note:_ This may be less stable than us
|
|
59
59
|
|
60
60
|
script/plugin install git://github.com/brynary/webrat.git
|
61
61
|
|
62
|
-
In your test_helper.rb
|
62
|
+
In your test_helper.rb or env.rb (for Cucumber) add:
|
63
63
|
|
64
|
-
require "webrat
|
64
|
+
require "webrat"
|
65
|
+
|
66
|
+
Webrat.configure do |config|
|
67
|
+
config.mode = :rails
|
68
|
+
end
|
65
69
|
|
66
70
|
== Install with Merb
|
67
71
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'rubygems'
|
1
|
+
# require 'rubygems'
|
2
2
|
require "rake/gempackagetask"
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
require "rake/clean"
|
@@ -28,8 +28,8 @@ spec = Gem::Specification.new do |s|
|
|
28
28
|
s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
|
29
29
|
|
30
30
|
# Dependencies
|
31
|
-
s.add_dependency "nokogiri", ">= 1.0
|
32
|
-
|
31
|
+
s.add_dependency "nokogiri", ">= 1.1.0"
|
32
|
+
|
33
33
|
s.rubyforge_project = "webrat"
|
34
34
|
end
|
35
35
|
|
@@ -52,13 +52,13 @@ end
|
|
52
52
|
desc "Run API and Core specs"
|
53
53
|
Spec::Rake::SpecTask.new do |t|
|
54
54
|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
|
55
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
55
|
+
t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
|
56
56
|
end
|
57
57
|
|
58
58
|
desc "Run all specs in spec directory with RCov"
|
59
59
|
Spec::Rake::SpecTask.new(:rcov) do |t|
|
60
60
|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
|
61
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
61
|
+
t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
|
62
62
|
t.rcov = true
|
63
63
|
t.rcov_opts = lambda do
|
64
64
|
IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
|
@@ -71,8 +71,8 @@ end
|
|
71
71
|
|
72
72
|
desc 'Install the package as a gem.'
|
73
73
|
task :install_gem => [:clean, :package] do
|
74
|
-
|
75
|
-
sh "sudo gem install --local #{
|
74
|
+
gem_filename = Dir['pkg/*.gem'].first
|
75
|
+
sh "sudo gem install --local #{gem_filename}"
|
76
76
|
end
|
77
77
|
|
78
78
|
desc "Delete generated RDoc"
|
@@ -99,6 +99,41 @@ task :spec_deps do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
task :prepare do
|
103
|
+
system "ln -s ../../../../.. ./spec/integration/rails/vendor/plugins/webrat"
|
104
|
+
end
|
105
|
+
|
106
|
+
namespace :spec do
|
107
|
+
desc "Run the integration specs"
|
108
|
+
task :integration => ["integration:rails", "integration:merb", "integration:sinatra"]
|
109
|
+
|
110
|
+
namespace :integration do
|
111
|
+
desc "Run the Rails integration specs"
|
112
|
+
task :rails do
|
113
|
+
Dir.chdir "spec/integration/rails" do
|
114
|
+
result = system "rake test:integration"
|
115
|
+
raise "Rails integration tests failed" unless result
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "Run the Merb integration specs"
|
120
|
+
task :merb do
|
121
|
+
Dir.chdir "spec/integration/merb" do
|
122
|
+
result = system "rake spec"
|
123
|
+
raise "Merb integration tests failed" unless result
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "Run the Sinatra integration specs"
|
128
|
+
task :sinatra do
|
129
|
+
Dir.chdir "spec/integration/sinatra" do
|
130
|
+
result = system "rake test"
|
131
|
+
raise "Sinatra tntegration tests failed" unless result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
102
137
|
task :default => :spec
|
103
138
|
|
104
|
-
task :precommit => ["spec", "spec:jruby"]
|
139
|
+
task :precommit => ["spec", "spec:jruby", "spec:integration"]
|
data/lib/webrat.rb
CHANGED
@@ -1,44 +1,87 @@
|
|
1
|
+
require "webrat/core_extensions/deprecate"
|
2
|
+
|
1
3
|
module Webrat
|
2
|
-
|
4
|
+
|
3
5
|
# Configures Webrat. If this is not done, Webrat will be created
|
4
|
-
# with all of the default settings.
|
5
|
-
def self.configure(configuration = Webrat
|
6
|
+
# with all of the default settings.
|
7
|
+
def self.configure(configuration = Webrat.configuration)
|
6
8
|
yield configuration if block_given?
|
7
9
|
@@configuration = configuration
|
8
10
|
end
|
9
|
-
|
11
|
+
|
10
12
|
def self.configuration # :nodoc:
|
11
13
|
@@configuration ||= Webrat::Configuration.new
|
12
14
|
end
|
13
15
|
|
14
16
|
# Webrat can be configured using the Webrat.configure method. For example:
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# Webrat.configure do |config|
|
17
19
|
# config.parse_with_nokogiri = false
|
18
20
|
# end
|
19
21
|
class Configuration
|
22
|
+
|
20
23
|
# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
|
21
24
|
attr_writer :parse_with_nokogiri
|
22
|
-
|
25
|
+
|
23
26
|
# Webrat's mode, set automatically when requiring webrat/rails, webrat/merb, etc.
|
24
|
-
|
25
|
-
|
27
|
+
attr_reader :mode # :nodoc:
|
28
|
+
|
26
29
|
# Save and open pages with error status codes (500-599) in a browser? Defualts to true.
|
27
30
|
attr_writer :open_error_files
|
28
|
-
|
31
|
+
|
32
|
+
# Which rails environment should the selenium tests be run in? Defaults to selenium.
|
33
|
+
attr_accessor :application_environment
|
34
|
+
webrat_deprecate :selenium_environment, :application_environment
|
35
|
+
|
36
|
+
# Which port is the application running on for selenium testing? Defaults to 3001.
|
37
|
+
attr_accessor :application_port
|
38
|
+
webrat_deprecate :selenium_port, :application_port
|
39
|
+
|
40
|
+
# Which server the application is running on for selenium testing? Defaults to localhost
|
41
|
+
attr_accessor :application_address
|
42
|
+
|
43
|
+
# Which server Selenium server is running on. Defaults to nil(server starts in webrat process and runs locally)
|
44
|
+
attr_accessor :selenium_server_address
|
45
|
+
|
46
|
+
# Which server Selenium port is running on. Defaults to 4444
|
47
|
+
attr_accessor :selenium_server_port
|
48
|
+
|
49
|
+
# Set the key that Selenium uses to determine the browser running. Default *firefox
|
50
|
+
attr_accessor :selenium_browser_key
|
51
|
+
|
29
52
|
def initialize # :nodoc:
|
30
53
|
self.open_error_files = true
|
31
54
|
self.parse_with_nokogiri = !Webrat.on_java?
|
55
|
+
self.application_environment = :selenium
|
56
|
+
self.application_port = 3001
|
57
|
+
self.application_address = 'localhost'
|
58
|
+
self.selenium_server_port = 4444
|
59
|
+
self.selenium_browser_key = '*firefox'
|
32
60
|
end
|
33
|
-
|
61
|
+
|
34
62
|
def parse_with_nokogiri? #:nodoc:
|
35
63
|
@parse_with_nokogiri ? true : false
|
36
64
|
end
|
37
|
-
|
65
|
+
|
38
66
|
def open_error_files? #:nodoc:
|
39
67
|
@open_error_files ? true : false
|
40
68
|
end
|
41
|
-
|
69
|
+
|
70
|
+
# Allows setting of webrat's mode, valid modes are:
|
71
|
+
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
|
72
|
+
def mode=(mode)
|
73
|
+
@mode = mode.to_sym
|
74
|
+
|
75
|
+
# This is a temporary hack to support backwards compatibility
|
76
|
+
# with Merb 1.0.8 until it's updated to use the new Webrat.configure
|
77
|
+
# syntax
|
78
|
+
if @mode == :merb
|
79
|
+
require("webrat/merb_session")
|
80
|
+
else
|
81
|
+
require("webrat/#{mode}")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
42
85
|
end
|
43
|
-
|
86
|
+
|
44
87
|
end
|
@@ -79,7 +79,7 @@ module Webrat
|
|
79
79
|
|
80
80
|
case Webrat.configuration.mode
|
81
81
|
when :rails
|
82
|
-
|
82
|
+
rails_request_parser.parse_query_parameters("#{name}=#{escaped_value}")
|
83
83
|
when :merb
|
84
84
|
::Merb::Parse.query("#{name}=#{escaped_value}")
|
85
85
|
else
|
@@ -97,6 +97,14 @@ module Webrat
|
|
97
97
|
|
98
98
|
protected
|
99
99
|
|
100
|
+
def rails_request_parser
|
101
|
+
if defined?(ActionController::RequestParser) # For Rails > 2.2
|
102
|
+
ActionController::RequestParser
|
103
|
+
else
|
104
|
+
ActionController::AbstractRequest
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
100
108
|
def form
|
101
109
|
Form.load(@session, form_element)
|
102
110
|
end
|
@@ -7,7 +7,7 @@ module Webrat
|
|
7
7
|
class FieldLabeledLocator < Locator # :nodoc:
|
8
8
|
|
9
9
|
def locate
|
10
|
-
matching_labels.any? && matching_labels.
|
10
|
+
matching_labels.any? && matching_labels.detect_mapped { |label| label.field }
|
11
11
|
end
|
12
12
|
|
13
13
|
def matching_labels
|
@@ -42,9 +42,15 @@ module Webrat
|
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
+
# Locates a form field based on a <tt>label</tt> element in the HTML source.
|
46
|
+
# This can be useful in order to verify that a field is pre-filled with the
|
47
|
+
# correct value.
|
48
|
+
#
|
49
|
+
# Example:
|
50
|
+
# field_labeled("First name").value.should == "Bryan"
|
45
51
|
def field_labeled(label, *field_types)
|
46
52
|
FieldLabeledLocator.new(@session, dom, label, *field_types).locate!
|
47
53
|
end
|
48
54
|
|
49
55
|
end
|
50
|
-
end
|
56
|
+
end
|
@@ -51,5 +51,19 @@ module Webrat
|
|
51
51
|
HasContent.new(content)
|
52
52
|
end
|
53
53
|
|
54
|
+
# Asserts that the body of the response contain
|
55
|
+
# the supplied string or regexp
|
56
|
+
def assert_contain(content)
|
57
|
+
hc = HasContent.new(content)
|
58
|
+
assert hc.matches?(response_body), hc.failure_message
|
59
|
+
end
|
60
|
+
|
61
|
+
# Asserts that the body of the response
|
62
|
+
# does not contain the supplied string or regepx
|
63
|
+
def assert_not_contain(content)
|
64
|
+
hc = HasContent.new(content)
|
65
|
+
assert !hc.matches?(response_body), hc.negative_failure_message
|
66
|
+
end
|
67
|
+
|
54
68
|
end
|
55
69
|
end
|
@@ -33,5 +33,20 @@ module Webrat
|
|
33
33
|
end
|
34
34
|
alias_method :match_selector, :have_selector
|
35
35
|
|
36
|
+
|
37
|
+
# Asserts that the body of the response contains
|
38
|
+
# the supplied selector
|
39
|
+
def assert_have_selector(expected)
|
40
|
+
hs = HaveSelector.new(expected)
|
41
|
+
assert hs.matches?(response_body), hs.failure_message
|
42
|
+
end
|
43
|
+
|
44
|
+
# Asserts that the body of the response
|
45
|
+
# does not contain the supplied string or regepx
|
46
|
+
def assert_have_no_selector(expected)
|
47
|
+
hs = HaveSelector.new(expected)
|
48
|
+
assert !hs.matches?(response_body), hs.negative_failure_message
|
49
|
+
end
|
50
|
+
|
36
51
|
end
|
37
52
|
end
|