diabolo-webrat 0.4.2 → 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 +22 -3
- data/Rakefile +6 -1
- data/lib/webrat/core/configuration.rb +4 -4
- data/lib/webrat/core/elements/area.rb +7 -7
- data/lib/webrat/core/elements/element.rb +11 -11
- data/lib/webrat/core/elements/field.rb +50 -50
- data/lib/webrat/core/elements/form.rb +17 -17
- data/lib/webrat/core/elements/label.rb +6 -6
- data/lib/webrat/core/elements/link.rb +13 -11
- data/lib/webrat/core/elements/select_option.rb +9 -9
- data/lib/webrat/core/locators/area_locator.rb +10 -10
- data/lib/webrat/core/locators/button_locator.rb +13 -13
- data/lib/webrat/core/locators/field_by_id_locator.rb +8 -8
- data/lib/webrat/core/locators/field_labeled_locator.rb +10 -10
- data/lib/webrat/core/locators/field_locator.rb +7 -7
- data/lib/webrat/core/locators/field_named_locator.rb +10 -10
- data/lib/webrat/core/locators/form_locator.rb +6 -6
- data/lib/webrat/core/locators/label_locator.rb +8 -8
- data/lib/webrat/core/locators/link_locator.rb +11 -12
- data/lib/webrat/core/locators/locator.rb +5 -5
- data/lib/webrat/core/locators/select_option_locator.rb +11 -11
- data/lib/webrat/core/locators.rb +2 -2
- data/lib/webrat/core/logging.rb +3 -3
- data/lib/webrat/core/matchers/have_content.rb +12 -12
- data/lib/webrat/core/matchers/have_selector.rb +9 -9
- data/lib/webrat/core/matchers/have_tag.rb +4 -4
- data/lib/webrat/core/matchers/have_xpath.rb +24 -24
- data/lib/webrat/core/methods.rb +9 -9
- data/lib/webrat/core/mime.rb +3 -3
- data/lib/webrat/core/save_and_open_page.rb +9 -9
- data/lib/webrat/core/scope.rb +51 -51
- data/lib/webrat/core/session.rb +7 -7
- data/lib/webrat/core/xml/hpricot.rb +3 -3
- data/lib/webrat/core/xml/nokogiri.rb +11 -11
- data/lib/webrat/core/xml/rexml.rb +3 -3
- data/lib/webrat/core/xml.rb +16 -16
- data/lib/webrat/core_extensions/blank.rb +1 -1
- data/lib/webrat/core_extensions/deprecate.rb +1 -1
- data/lib/webrat/core_extensions/detect_mapped.rb +4 -4
- data/lib/webrat/core_extensions/meta_class.rb +1 -1
- data/lib/webrat/mechanize.rb +9 -9
- data/lib/webrat/merb.rb +1 -1
- data/lib/webrat/merb_session.rb +10 -10
- data/lib/webrat/rails.rb +2 -2
- data/lib/webrat/rspec-rails.rb +2 -2
- data/lib/webrat/selenium/matchers/have_content.rb +4 -4
- data/lib/webrat/selenium/matchers/have_selector.rb +4 -4
- data/lib/webrat/selenium/matchers/have_tag.rb +16 -16
- data/lib/webrat/selenium/matchers/have_xpath.rb +4 -4
- data/lib/webrat/selenium/matchers.rb +1 -1
- data/lib/webrat/selenium/selenium_session.rb +12 -18
- data/lib/webrat/selenium.rb +3 -77
- data/lib/webrat.rb +4 -4
- metadata +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
require "webrat/core/save_and_open_page"
|
|
2
|
+
require "webrat/selenium/selenium_rc_server"
|
|
3
|
+
require "webrat/selenium/application_server"
|
|
2
4
|
|
|
3
5
|
module Webrat
|
|
4
6
|
class TimeoutError < WebratError
|
|
@@ -39,7 +41,7 @@ module Webrat
|
|
|
39
41
|
|
|
40
42
|
def fill_in(field_identifier, options)
|
|
41
43
|
locator = "webrat=#{Regexp.escape(field_identifier)}"
|
|
42
|
-
selenium.wait_for_element locator, 5
|
|
44
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
|
43
45
|
selenium.type(locator, "#{options[:with]}")
|
|
44
46
|
end
|
|
45
47
|
|
|
@@ -62,7 +64,7 @@ module Webrat
|
|
|
62
64
|
pattern ||= '*'
|
|
63
65
|
locator = "button=#{pattern}"
|
|
64
66
|
|
|
65
|
-
selenium.wait_for_element locator, 5
|
|
67
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
|
66
68
|
selenium.click locator
|
|
67
69
|
end
|
|
68
70
|
|
|
@@ -71,7 +73,7 @@ module Webrat
|
|
|
71
73
|
def click_link(link_text_or_regexp, options = {})
|
|
72
74
|
pattern = adjust_if_regexp(link_text_or_regexp)
|
|
73
75
|
locator = "webratlink=#{pattern}"
|
|
74
|
-
selenium.wait_for_element locator, 5
|
|
76
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
|
75
77
|
selenium.click locator
|
|
76
78
|
end
|
|
77
79
|
|
|
@@ -79,7 +81,7 @@ module Webrat
|
|
|
79
81
|
|
|
80
82
|
def click_link_within(selector, link_text, options = {})
|
|
81
83
|
locator = "webratlinkwithin=#{selector}|#{link_text}"
|
|
82
|
-
selenium.wait_for_element locator, 5
|
|
84
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
|
83
85
|
selenium.click locator
|
|
84
86
|
end
|
|
85
87
|
|
|
@@ -94,7 +96,7 @@ module Webrat
|
|
|
94
96
|
select_locator = "webratselectwithoption=#{option_text}"
|
|
95
97
|
end
|
|
96
98
|
|
|
97
|
-
selenium.wait_for_element select_locator, 5
|
|
99
|
+
selenium.wait_for_element select_locator, :timeout_in_seconds => 5
|
|
98
100
|
selenium.select(select_locator, option_text)
|
|
99
101
|
end
|
|
100
102
|
|
|
@@ -102,7 +104,7 @@ module Webrat
|
|
|
102
104
|
|
|
103
105
|
def choose(label_text)
|
|
104
106
|
locator = "webrat=#{label_text}"
|
|
105
|
-
selenium.wait_for_element locator, 5
|
|
107
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
|
106
108
|
selenium.click locator
|
|
107
109
|
end
|
|
108
110
|
|
|
@@ -110,7 +112,7 @@ module Webrat
|
|
|
110
112
|
|
|
111
113
|
def check(label_text)
|
|
112
114
|
locator = "webrat=#{label_text}"
|
|
113
|
-
selenium.wait_for_element locator, 5
|
|
115
|
+
selenium.wait_for_element locator, :timeout_in_seconds => 5
|
|
114
116
|
selenium.click locator
|
|
115
117
|
end
|
|
116
118
|
alias_method :uncheck, :check
|
|
@@ -179,6 +181,7 @@ module Webrat
|
|
|
179
181
|
end
|
|
180
182
|
|
|
181
183
|
protected
|
|
184
|
+
|
|
182
185
|
def silence_stream(stream)
|
|
183
186
|
old_stream = stream.dup
|
|
184
187
|
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
|
@@ -189,16 +192,11 @@ module Webrat
|
|
|
189
192
|
end
|
|
190
193
|
|
|
191
194
|
def setup #:nodoc:
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
Webrat.start_selenium_server
|
|
195
|
-
Webrat.start_app_server
|
|
196
|
-
end
|
|
197
|
-
end
|
|
195
|
+
Webrat::Selenium::SeleniumRCServer.boot
|
|
196
|
+
Webrat::Selenium::ApplicationServer.boot
|
|
198
197
|
|
|
199
198
|
create_browser
|
|
200
199
|
$browser.start
|
|
201
|
-
teardown_at_exit
|
|
202
200
|
|
|
203
201
|
extend_selenium
|
|
204
202
|
define_location_strategies
|
|
@@ -210,14 +208,10 @@ module Webrat
|
|
|
210
208
|
$browser = ::Selenium::Client::Driver.new(Webrat.configuration.selenium_server_address || "localhost",
|
|
211
209
|
Webrat.configuration.selenium_server_port, Webrat.configuration.selenium_browser_key, "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port}")
|
|
212
210
|
$browser.set_speed(0) unless Webrat.configuration.selenium_server_address
|
|
213
|
-
end
|
|
214
211
|
|
|
215
|
-
def teardown_at_exit #:nodoc:
|
|
216
212
|
at_exit do
|
|
217
213
|
silence_stream(STDOUT) do
|
|
218
214
|
$browser.stop
|
|
219
|
-
Webrat.stop_app_server
|
|
220
|
-
Webrat.stop_selenium_server
|
|
221
215
|
end
|
|
222
216
|
end
|
|
223
217
|
end
|
data/lib/webrat/selenium.rb
CHANGED
|
@@ -1,86 +1,11 @@
|
|
|
1
1
|
require "webrat"
|
|
2
|
-
gem "selenium-client", ">=1.2.
|
|
2
|
+
gem "selenium-client", ">=1.2.14"
|
|
3
3
|
require "selenium/client"
|
|
4
4
|
require "webrat/selenium/selenium_session"
|
|
5
5
|
require "webrat/selenium/matchers"
|
|
6
|
+
require "webrat/core_extensions/tcp_socket"
|
|
6
7
|
|
|
7
8
|
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
9
|
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
|
85
10
|
# Activate it with (for example, in your <tt>env.rb</tt>):
|
|
86
11
|
#
|
|
@@ -143,6 +68,7 @@ module Webrat
|
|
|
143
68
|
end
|
|
144
69
|
end
|
|
145
70
|
end
|
|
71
|
+
|
|
146
72
|
if defined?(ActionController::IntegrationTest)
|
|
147
73
|
module ActionController #:nodoc:
|
|
148
74
|
IntegrationTest.class_eval do
|
data/lib/webrat.rb
CHANGED
|
@@ -7,11 +7,11 @@ module Webrat
|
|
|
7
7
|
class WebratError < StandardError
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
VERSION = '0.4.
|
|
10
|
+
VERSION = '0.4.4'
|
|
11
11
|
|
|
12
12
|
def self.require_xml
|
|
13
13
|
gem "nokogiri", ">= 1.0.6"
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
if on_java?
|
|
16
16
|
# We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching
|
|
17
17
|
require "nokogiri/css"
|
|
@@ -22,11 +22,11 @@ module Webrat
|
|
|
22
22
|
require "webrat/core/xml/nokogiri"
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
def self.on_java?
|
|
27
27
|
RUBY_PLATFORM =~ /java/
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
Webrat.require_xml
|