jferris-webrat 0.4.3
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 +306 -0
- data/MIT-LICENSE.txt +19 -0
- data/README.rdoc +85 -0
- data/Rakefile +158 -0
- data/install.rb +1 -0
- data/lib/webrat/core/configuration.rb +98 -0
- data/lib/webrat/core/elements/area.rb +31 -0
- data/lib/webrat/core/elements/element.rb +33 -0
- data/lib/webrat/core/elements/field.rb +403 -0
- data/lib/webrat/core/elements/form.rb +103 -0
- data/lib/webrat/core/elements/label.rb +31 -0
- data/lib/webrat/core/elements/link.rb +90 -0
- data/lib/webrat/core/elements/select_option.rb +35 -0
- data/lib/webrat/core/locators/area_locator.rb +38 -0
- data/lib/webrat/core/locators/button_locator.rb +54 -0
- data/lib/webrat/core/locators/field_by_id_locator.rb +37 -0
- data/lib/webrat/core/locators/field_labeled_locator.rb +56 -0
- data/lib/webrat/core/locators/field_locator.rb +25 -0
- data/lib/webrat/core/locators/field_named_locator.rb +41 -0
- data/lib/webrat/core/locators/form_locator.rb +19 -0
- data/lib/webrat/core/locators/label_locator.rb +34 -0
- data/lib/webrat/core/locators/link_locator.rb +66 -0
- data/lib/webrat/core/locators/locator.rb +20 -0
- data/lib/webrat/core/locators/select_option_locator.rb +59 -0
- data/lib/webrat/core/locators.rb +20 -0
- data/lib/webrat/core/logging.rb +21 -0
- data/lib/webrat/core/matchers/have_content.rb +73 -0
- data/lib/webrat/core/matchers/have_selector.rb +74 -0
- data/lib/webrat/core/matchers/have_tag.rb +21 -0
- data/lib/webrat/core/matchers/have_xpath.rb +147 -0
- data/lib/webrat/core/matchers.rb +4 -0
- data/lib/webrat/core/methods.rb +61 -0
- data/lib/webrat/core/mime.rb +29 -0
- data/lib/webrat/core/save_and_open_page.rb +50 -0
- data/lib/webrat/core/scope.rb +350 -0
- data/lib/webrat/core/session.rb +281 -0
- data/lib/webrat/core/xml/hpricot.rb +19 -0
- data/lib/webrat/core/xml/nokogiri.rb +76 -0
- data/lib/webrat/core/xml/rexml.rb +24 -0
- data/lib/webrat/core/xml.rb +115 -0
- data/lib/webrat/core.rb +14 -0
- data/lib/webrat/core_extensions/blank.rb +58 -0
- data/lib/webrat/core_extensions/deprecate.rb +8 -0
- data/lib/webrat/core_extensions/detect_mapped.rb +12 -0
- data/lib/webrat/core_extensions/meta_class.rb +6 -0
- data/lib/webrat/core_extensions/nil_to_param.rb +5 -0
- data/lib/webrat/mechanize.rb +74 -0
- data/lib/webrat/merb.rb +9 -0
- data/lib/webrat/merb_session.rb +65 -0
- data/lib/webrat/rack.rb +24 -0
- data/lib/webrat/rails.rb +105 -0
- data/lib/webrat/rspec-rails.rb +13 -0
- data/lib/webrat/selenium/location_strategy_javascript/button.js +12 -0
- data/lib/webrat/selenium/location_strategy_javascript/label.js +16 -0
- data/lib/webrat/selenium/location_strategy_javascript/webrat.js +5 -0
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +9 -0
- data/lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js +15 -0
- data/lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js +5 -0
- 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/matchers.rb +4 -0
- data/lib/webrat/selenium/selenium_extensions.js +6 -0
- data/lib/webrat/selenium/selenium_session.rb +247 -0
- data/lib/webrat/selenium.rb +154 -0
- data/lib/webrat/sinatra.rb +53 -0
- data/lib/webrat.rb +34 -0
- data/vendor/selenium-server.jar +0 -0
- metadata +141 -0
@@ -0,0 +1,247 @@
|
|
1
|
+
require "webrat/core/save_and_open_page"
|
2
|
+
|
3
|
+
module Webrat
|
4
|
+
class TimeoutError < WebratError
|
5
|
+
end
|
6
|
+
|
7
|
+
class SeleniumResponse
|
8
|
+
attr_reader :body
|
9
|
+
attr_reader :session
|
10
|
+
|
11
|
+
def initialize(session, body)
|
12
|
+
@session = session
|
13
|
+
@body = body
|
14
|
+
end
|
15
|
+
|
16
|
+
def selenium
|
17
|
+
session.selenium
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class SeleniumSession
|
22
|
+
include Webrat::SaveAndOpenPage
|
23
|
+
|
24
|
+
def initialize(*args) # :nodoc:
|
25
|
+
end
|
26
|
+
|
27
|
+
def simulate
|
28
|
+
end
|
29
|
+
|
30
|
+
def automate
|
31
|
+
yield
|
32
|
+
end
|
33
|
+
|
34
|
+
def visit(url)
|
35
|
+
selenium.open(url)
|
36
|
+
end
|
37
|
+
|
38
|
+
webrat_deprecate :visits, :visit
|
39
|
+
|
40
|
+
def fill_in(field_identifier, options)
|
41
|
+
locator = "webrat=#{Regexp.escape(field_identifier)}"
|
42
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
43
|
+
selenium.type(locator, "#{options[:with]}")
|
44
|
+
end
|
45
|
+
|
46
|
+
webrat_deprecate :fills_in, :fill_in
|
47
|
+
|
48
|
+
def response
|
49
|
+
SeleniumResponse.new(self, response_body)
|
50
|
+
end
|
51
|
+
|
52
|
+
def response_body #:nodoc:
|
53
|
+
selenium.get_html_source
|
54
|
+
end
|
55
|
+
|
56
|
+
def click_button(button_text_or_regexp = nil, options = {})
|
57
|
+
if button_text_or_regexp.is_a?(Hash) && options == {}
|
58
|
+
pattern, options = nil, button_text_or_regexp
|
59
|
+
elsif button_text_or_regexp
|
60
|
+
pattern = adjust_if_regexp(button_text_or_regexp)
|
61
|
+
end
|
62
|
+
pattern ||= '*'
|
63
|
+
locator = "button=#{pattern}"
|
64
|
+
|
65
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
66
|
+
selenium.click locator
|
67
|
+
end
|
68
|
+
|
69
|
+
webrat_deprecate :clicks_button, :click_button
|
70
|
+
|
71
|
+
def click_link(link_text_or_regexp, options = {})
|
72
|
+
pattern = adjust_if_regexp(link_text_or_regexp)
|
73
|
+
locator = "webratlink=#{pattern}"
|
74
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
75
|
+
selenium.click locator
|
76
|
+
end
|
77
|
+
|
78
|
+
webrat_deprecate :clicks_link, :click_link
|
79
|
+
|
80
|
+
def click_link_within(selector, link_text, options = {})
|
81
|
+
locator = "webratlinkwithin=#{selector}|#{link_text}"
|
82
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
83
|
+
selenium.click locator
|
84
|
+
end
|
85
|
+
|
86
|
+
webrat_deprecate :clicks_link_within, :click_link_within
|
87
|
+
|
88
|
+
def select(option_text, options = {})
|
89
|
+
id_or_name_or_label = options[:from]
|
90
|
+
|
91
|
+
if id_or_name_or_label
|
92
|
+
select_locator = "webrat=#{id_or_name_or_label}"
|
93
|
+
else
|
94
|
+
select_locator = "webratselectwithoption=#{option_text}"
|
95
|
+
end
|
96
|
+
|
97
|
+
selenium.wait_for_element select_locator, :timeout_in_seconds => 5
|
98
|
+
selenium.select(select_locator, option_text)
|
99
|
+
end
|
100
|
+
|
101
|
+
webrat_deprecate :selects, :select
|
102
|
+
|
103
|
+
def choose(label_text)
|
104
|
+
locator = "webrat=#{label_text}"
|
105
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
106
|
+
selenium.click locator
|
107
|
+
end
|
108
|
+
|
109
|
+
webrat_deprecate :chooses, :choose
|
110
|
+
|
111
|
+
def check(label_text)
|
112
|
+
locator = "webrat=#{label_text}"
|
113
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
114
|
+
selenium.click locator
|
115
|
+
end
|
116
|
+
alias_method :uncheck, :check
|
117
|
+
|
118
|
+
webrat_deprecate :checks, :check
|
119
|
+
|
120
|
+
def fire_event(field_identifier, event)
|
121
|
+
locator = "webrat=#{Regexp.escape(field_identifier)}"
|
122
|
+
selenium.fire_event(locator, "#{event}")
|
123
|
+
end
|
124
|
+
|
125
|
+
def key_down(field_identifier, key_code)
|
126
|
+
locator = "webrat=#{Regexp.escape(field_identifier)}"
|
127
|
+
selenium.key_down(locator, key_code)
|
128
|
+
end
|
129
|
+
|
130
|
+
def key_up(field_identifier, key_code)
|
131
|
+
locator = "webrat=#{Regexp.escape(field_identifier)}"
|
132
|
+
selenium.key_up(locator, key_code)
|
133
|
+
end
|
134
|
+
|
135
|
+
def wait_for(params={})
|
136
|
+
timeout = params[:timeout] || 5
|
137
|
+
message = params[:message] || "Timeout exceeded"
|
138
|
+
|
139
|
+
begin_time = Time.now
|
140
|
+
|
141
|
+
while (Time.now - begin_time) < timeout
|
142
|
+
value = nil
|
143
|
+
|
144
|
+
begin
|
145
|
+
value = yield
|
146
|
+
rescue ::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError
|
147
|
+
value = nil
|
148
|
+
end
|
149
|
+
|
150
|
+
return value if value
|
151
|
+
|
152
|
+
sleep 0.25
|
153
|
+
end
|
154
|
+
|
155
|
+
raise Webrat::TimeoutError.new(message + " (after #{timeout} sec)")
|
156
|
+
true
|
157
|
+
end
|
158
|
+
|
159
|
+
def selenium
|
160
|
+
return $browser if $browser
|
161
|
+
setup
|
162
|
+
$browser
|
163
|
+
end
|
164
|
+
|
165
|
+
webrat_deprecate :browser, :selenium
|
166
|
+
|
167
|
+
|
168
|
+
def save_and_open_screengrab
|
169
|
+
return unless File.exist?(saved_page_dir)
|
170
|
+
|
171
|
+
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.png"
|
172
|
+
|
173
|
+
if $browser.chrome_backend?
|
174
|
+
$browser.capture_entire_page_screenshot(filename, '')
|
175
|
+
else
|
176
|
+
$browser.capture_screenshot(filename)
|
177
|
+
end
|
178
|
+
open_in_browser(filename)
|
179
|
+
end
|
180
|
+
|
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
|
190
|
+
|
191
|
+
def setup #:nodoc:
|
192
|
+
silence_stream(STDOUT) do
|
193
|
+
silence_stream(STDERR) do
|
194
|
+
Webrat.start_selenium_server
|
195
|
+
Webrat.start_app_server
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
create_browser
|
200
|
+
$browser.start
|
201
|
+
teardown_at_exit
|
202
|
+
|
203
|
+
extend_selenium
|
204
|
+
define_location_strategies
|
205
|
+
$browser.window_maximize
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
def create_browser
|
210
|
+
$browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
|
211
|
+
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}")
|
212
|
+
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address
|
213
|
+
end
|
214
|
+
|
215
|
+
def teardown_at_exit #:nodoc:
|
216
|
+
at_exit do
|
217
|
+
silence_stream(STDOUT) do
|
218
|
+
$browser.stop
|
219
|
+
Webrat.stop_app_server
|
220
|
+
Webrat.stop_selenium_server
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def adjust_if_regexp(text_or_regexp) #:nodoc:
|
226
|
+
if text_or_regexp.is_a?(Regexp)
|
227
|
+
"evalregex:#{text_or_regexp.inspect}"
|
228
|
+
else
|
229
|
+
"evalregex:/#{text_or_regexp}/"
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def extend_selenium #:nodoc:
|
234
|
+
extensions_file = File.join(File.dirname(__FILE__), "selenium_extensions.js")
|
235
|
+
extenions_js = File.read(extensions_file)
|
236
|
+
selenium.get_eval(extenions_js)
|
237
|
+
end
|
238
|
+
|
239
|
+
def define_location_strategies #:nodoc:
|
240
|
+
Dir[File.join(File.dirname(__FILE__), "location_strategy_javascript", "*.js")].sort.each do |file|
|
241
|
+
strategy_js = File.read(file)
|
242
|
+
strategy_name = File.basename(file, '.js')
|
243
|
+
selenium.add_location_strategy(strategy_name, strategy_js)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require "webrat"
|
2
|
+
gem "selenium-client", ">=1.2.14"
|
3
|
+
require "selenium/client"
|
4
|
+
require "webrat/selenium/selenium_session"
|
5
|
+
require "webrat/selenium/matchers"
|
6
|
+
|
7
|
+
module Webrat
|
8
|
+
|
9
|
+
def self.with_selenium_server #:nodoc:
|
10
|
+
start_selenium_server
|
11
|
+
yield
|
12
|
+
stop_selenium_server
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.start_selenium_server #:nodoc:
|
16
|
+
unless Webrat.configuration.selenium_server_address
|
17
|
+
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5)
|
18
|
+
remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
|
19
|
+
remote_control.start :background => true
|
20
|
+
end
|
21
|
+
TCPSocket.wait_for_service :host => (Webrat.configuration.selenium_server_address || "0.0.0.0"), :port => Webrat.configuration.selenium_server_port
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.stop_selenium_server #:nodoc:
|
25
|
+
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address
|
26
|
+
end
|
27
|
+
|
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
|
56
|
+
TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
|
57
|
+
end
|
58
|
+
|
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
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.prepare_pid_file(file_path, pid_file_name)
|
80
|
+
FileUtils.mkdir_p File.expand_path(file_path)
|
81
|
+
File.expand_path("#{file_path}/#{pid_file_name}")
|
82
|
+
end
|
83
|
+
|
84
|
+
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
85
|
+
# Activate it with (for example, in your <tt>env.rb</tt>):
|
86
|
+
#
|
87
|
+
# require "webrat"
|
88
|
+
#
|
89
|
+
# Webrat.configure do |config|
|
90
|
+
# config.mode = :selenium
|
91
|
+
# end
|
92
|
+
#
|
93
|
+
# == Dropping down to the selenium-client API
|
94
|
+
#
|
95
|
+
# If you ever need to do something with Selenium not provided in the Webrat API,
|
96
|
+
# you can always drop down to the selenium-client API using the <tt>selenium</tt> method.
|
97
|
+
# For example:
|
98
|
+
#
|
99
|
+
# When "I drag the photo to the left" do
|
100
|
+
# selenium.dragdrop("id=photo_123", "+350, 0")
|
101
|
+
# end
|
102
|
+
#
|
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
|
117
|
+
#
|
118
|
+
# Webrat will automatically start the Selenium Java server process and an instance
|
119
|
+
# of Mongrel when a test is run. The Mongrel will run in the "selenium" environment
|
120
|
+
# instead of "test", so ensure you've got that defined, and will run on port
|
121
|
+
# Webrat.configuration.application_port.
|
122
|
+
#
|
123
|
+
# == Waiting
|
124
|
+
#
|
125
|
+
# In order to make writing Selenium tests as easy as possible, Webrat will automatically
|
126
|
+
# wait for the correct elements to exist on the page when trying to manipulate them
|
127
|
+
# with methods like <tt>fill_in</tt>, etc. In general, this means you should be able to write
|
128
|
+
# your Webrat::Selenium tests ignoring the concurrency issues that can plague in-browser
|
129
|
+
# testing, so long as you're using the Webrat API.
|
130
|
+
module Selenium
|
131
|
+
module Methods
|
132
|
+
def response
|
133
|
+
webrat_session.response
|
134
|
+
end
|
135
|
+
|
136
|
+
def wait_for(*args, &block)
|
137
|
+
webrat_session.wait_for(*args, &block)
|
138
|
+
end
|
139
|
+
|
140
|
+
def save_and_open_screengrab
|
141
|
+
webrat_session.save_and_open_screengrab
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
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
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "webrat/rack"
|
2
|
+
require "sinatra/test"
|
3
|
+
|
4
|
+
module Webrat
|
5
|
+
class SinatraSession < RackSession
|
6
|
+
include Sinatra::Test
|
7
|
+
|
8
|
+
attr_reader :request, :response
|
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
|
+
@cookies = []
|
16
|
+
end
|
17
|
+
|
18
|
+
%w(get head post put delete).each do |verb|
|
19
|
+
class_eval <<-RUBY
|
20
|
+
def #{verb}(path, data, headers = {})
|
21
|
+
params = data.inject({}) do |data, (key,value)|
|
22
|
+
data[key] = Rack::Utils.unescape(value)
|
23
|
+
data
|
24
|
+
end
|
25
|
+
headers["HTTP_HOST"] = "www.example.com"
|
26
|
+
headers["HTTP_COOKIE"] = @cookies.join(',')
|
27
|
+
@browser.#{verb}(path, params, headers)
|
28
|
+
set_cookies
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
end
|
32
|
+
|
33
|
+
def response_body
|
34
|
+
@browser.body
|
35
|
+
end
|
36
|
+
|
37
|
+
def response_code
|
38
|
+
@browser.status
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def set_cookies
|
44
|
+
if set_cookie = @browser.response.headers['Set-Cookie']
|
45
|
+
@cookies << set_cookie
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def response
|
50
|
+
@browser.response
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/webrat.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
+
|
5
|
+
module Webrat
|
6
|
+
# The common base class for all exceptions raised by Webrat.
|
7
|
+
class WebratError < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
VERSION = '0.4.3'
|
11
|
+
|
12
|
+
def self.require_xml
|
13
|
+
gem "nokogiri", ">= 1.0.6"
|
14
|
+
|
15
|
+
if on_java?
|
16
|
+
# We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching
|
17
|
+
require "nokogiri/css"
|
18
|
+
require "hpricot"
|
19
|
+
require "rexml/document"
|
20
|
+
else
|
21
|
+
require "nokogiri"
|
22
|
+
require "webrat/core/xml/nokogiri"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.on_java?
|
27
|
+
RUBY_PLATFORM =~ /java/
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
Webrat.require_xml
|
33
|
+
|
34
|
+
require "webrat/core"
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jferris-webrat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan Helmkamp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-31 21:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.0
|
24
|
+
version:
|
25
|
+
description: Webrat. Ruby Acceptance Testing for Web applications
|
26
|
+
email: bryan@brynary.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- MIT-LICENSE.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- install.rb
|
37
|
+
- MIT-LICENSE.txt
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- lib/webrat
|
41
|
+
- lib/webrat/core
|
42
|
+
- lib/webrat/core/configuration.rb
|
43
|
+
- lib/webrat/core/elements
|
44
|
+
- lib/webrat/core/elements/area.rb
|
45
|
+
- lib/webrat/core/elements/element.rb
|
46
|
+
- lib/webrat/core/elements/field.rb
|
47
|
+
- lib/webrat/core/elements/form.rb
|
48
|
+
- lib/webrat/core/elements/label.rb
|
49
|
+
- lib/webrat/core/elements/link.rb
|
50
|
+
- lib/webrat/core/elements/select_option.rb
|
51
|
+
- lib/webrat/core/locators
|
52
|
+
- lib/webrat/core/locators/area_locator.rb
|
53
|
+
- lib/webrat/core/locators/button_locator.rb
|
54
|
+
- lib/webrat/core/locators/field_by_id_locator.rb
|
55
|
+
- lib/webrat/core/locators/field_labeled_locator.rb
|
56
|
+
- lib/webrat/core/locators/field_locator.rb
|
57
|
+
- lib/webrat/core/locators/field_named_locator.rb
|
58
|
+
- lib/webrat/core/locators/form_locator.rb
|
59
|
+
- lib/webrat/core/locators/label_locator.rb
|
60
|
+
- lib/webrat/core/locators/link_locator.rb
|
61
|
+
- lib/webrat/core/locators/locator.rb
|
62
|
+
- lib/webrat/core/locators/select_option_locator.rb
|
63
|
+
- lib/webrat/core/locators.rb
|
64
|
+
- lib/webrat/core/logging.rb
|
65
|
+
- lib/webrat/core/matchers
|
66
|
+
- lib/webrat/core/matchers/have_content.rb
|
67
|
+
- lib/webrat/core/matchers/have_selector.rb
|
68
|
+
- lib/webrat/core/matchers/have_tag.rb
|
69
|
+
- lib/webrat/core/matchers/have_xpath.rb
|
70
|
+
- lib/webrat/core/matchers.rb
|
71
|
+
- lib/webrat/core/methods.rb
|
72
|
+
- lib/webrat/core/mime.rb
|
73
|
+
- lib/webrat/core/save_and_open_page.rb
|
74
|
+
- lib/webrat/core/scope.rb
|
75
|
+
- lib/webrat/core/session.rb
|
76
|
+
- lib/webrat/core/xml
|
77
|
+
- lib/webrat/core/xml/hpricot.rb
|
78
|
+
- lib/webrat/core/xml/nokogiri.rb
|
79
|
+
- lib/webrat/core/xml/rexml.rb
|
80
|
+
- lib/webrat/core/xml.rb
|
81
|
+
- lib/webrat/core.rb
|
82
|
+
- lib/webrat/core_extensions
|
83
|
+
- lib/webrat/core_extensions/blank.rb
|
84
|
+
- lib/webrat/core_extensions/deprecate.rb
|
85
|
+
- lib/webrat/core_extensions/detect_mapped.rb
|
86
|
+
- lib/webrat/core_extensions/meta_class.rb
|
87
|
+
- lib/webrat/core_extensions/nil_to_param.rb
|
88
|
+
- lib/webrat/mechanize.rb
|
89
|
+
- lib/webrat/merb.rb
|
90
|
+
- lib/webrat/merb_session.rb
|
91
|
+
- lib/webrat/rack.rb
|
92
|
+
- lib/webrat/rails.rb
|
93
|
+
- lib/webrat/rspec-rails.rb
|
94
|
+
- lib/webrat/selenium
|
95
|
+
- lib/webrat/selenium/location_strategy_javascript
|
96
|
+
- lib/webrat/selenium/location_strategy_javascript/button.js
|
97
|
+
- lib/webrat/selenium/location_strategy_javascript/label.js
|
98
|
+
- lib/webrat/selenium/location_strategy_javascript/webrat.js
|
99
|
+
- lib/webrat/selenium/location_strategy_javascript/webratlink.js
|
100
|
+
- lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js
|
101
|
+
- lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js
|
102
|
+
- lib/webrat/selenium/matchers
|
103
|
+
- lib/webrat/selenium/matchers/have_content.rb
|
104
|
+
- lib/webrat/selenium/matchers/have_selector.rb
|
105
|
+
- lib/webrat/selenium/matchers/have_tag.rb
|
106
|
+
- lib/webrat/selenium/matchers/have_xpath.rb
|
107
|
+
- lib/webrat/selenium/matchers.rb
|
108
|
+
- lib/webrat/selenium/selenium_extensions.js
|
109
|
+
- lib/webrat/selenium/selenium_session.rb
|
110
|
+
- lib/webrat/selenium.rb
|
111
|
+
- lib/webrat/sinatra.rb
|
112
|
+
- lib/webrat.rb
|
113
|
+
- vendor/selenium-server.jar
|
114
|
+
has_rdoc: true
|
115
|
+
homepage: http://github.com/brynary/webrat
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: "0"
|
126
|
+
version:
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: "0"
|
132
|
+
version:
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project: webrat
|
136
|
+
rubygems_version: 1.2.0
|
137
|
+
signing_key:
|
138
|
+
specification_version: 2
|
139
|
+
summary: Webrat. Ruby Acceptance Testing for Web applications
|
140
|
+
test_files: []
|
141
|
+
|