jwilger-webrat 0.4.3.4 → 0.4.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +34 -0
- data/Rakefile +16 -3
- data/lib/webrat/core/configuration.rb +9 -16
- 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 +11 -11
- 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 +9 -9
- data/lib/webrat/core/locators/link_locator.rb +12 -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 +7 -4
- 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 +14 -10
- 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 +54 -52
- data/lib/webrat/core/session.rb +20 -13
- 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/core_extensions/tcp_socket.rb +27 -0
- 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/rack_test.rb +32 -0
- data/lib/webrat/rails.rb +2 -2
- data/lib/webrat/rspec-rails.rb +2 -2
- data/lib/webrat/selenium/application_server.rb +75 -0
- 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/merb_application_server.rb +50 -0
- data/lib/webrat/selenium/rails_application_server.rb +44 -0
- data/lib/webrat/selenium/selenium_rc_server.rb +90 -0
- data/lib/webrat/selenium/selenium_session.rb +22 -31
- data/lib/webrat/selenium/silence_stream.rb +14 -0
- data/lib/webrat/selenium/sinatra_application_server.rb +37 -0
- data/lib/webrat/selenium.rb +5 -81
- data/lib/webrat.rb +8 -11
- metadata +10 -2
@@ -0,0 +1,27 @@
|
|
1
|
+
class TCPSocket
|
2
|
+
|
3
|
+
def self.wait_for_service_with_timeout(options)
|
4
|
+
start_time = Time.now
|
5
|
+
|
6
|
+
until listening_service?(options)
|
7
|
+
verbose_wait
|
8
|
+
|
9
|
+
if options[:timeout] && (Time.now > start_time + options[:timeout])
|
10
|
+
raise SocketError.new("Socket did not open within #{options[:timeout]} seconds")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.wait_for_service_termination_with_timeout(options)
|
16
|
+
start_time = Time.now
|
17
|
+
|
18
|
+
while listening_service?(options)
|
19
|
+
verbose_wait
|
20
|
+
|
21
|
+
if options[:timeout] && (Time.now > start_time + options[:timeout])
|
22
|
+
raise SocketError.new("Socket did not terminate within #{options[:timeout]} seconds")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/webrat/mechanize.rb
CHANGED
@@ -2,14 +2,14 @@ require "mechanize"
|
|
2
2
|
|
3
3
|
module Webrat #:nodoc:
|
4
4
|
class MechanizeSession < Session #:nodoc:
|
5
|
-
|
5
|
+
|
6
6
|
attr_accessor :response
|
7
7
|
alias :page :response
|
8
|
-
|
8
|
+
|
9
9
|
def request_page(url, http_method, data) #:nodoc:
|
10
10
|
super(absolute_url(url), http_method, data)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def get(url, data, headers_argument_not_used = nil)
|
14
14
|
@response = mechanize.get(url, data)
|
15
15
|
end
|
@@ -26,7 +26,7 @@ module Webrat #:nodoc:
|
|
26
26
|
end
|
27
27
|
@response = mechanize.post(url, post_data)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def response_body
|
31
31
|
@response.content
|
32
32
|
end
|
@@ -34,13 +34,13 @@ module Webrat #:nodoc:
|
|
34
34
|
def response_code
|
35
35
|
@response.code.to_i
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def mechanize
|
39
|
-
@mechanize
|
39
|
+
@mechanize ||= WWW::Mechanize.new
|
40
40
|
end
|
41
41
|
|
42
42
|
def_delegators :mechanize, :basic_auth
|
43
|
-
|
43
|
+
|
44
44
|
def absolute_url(url) #:nodoc:
|
45
45
|
current_host, current_path = split_current_url
|
46
46
|
if url =~ Regexp.new('^https?://')
|
@@ -53,13 +53,13 @@ module Webrat #:nodoc:
|
|
53
53
|
url
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
private
|
58
58
|
def split_current_url
|
59
59
|
current_url =~ Regexp.new('^(https?://[^/]+)(/.*)?')
|
60
60
|
[Regexp.last_match(1), Regexp.last_match(2)]
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def absolute_path(current_path, url)
|
64
64
|
levels_up = url.split('/').find_all { |x| x == '..' }.size
|
65
65
|
ancestor = if current_path.nil?
|
data/lib/webrat/merb.rb
CHANGED
data/lib/webrat/merb_session.rb
CHANGED
@@ -10,36 +10,36 @@ require "merb-core"
|
|
10
10
|
module Webrat
|
11
11
|
class MerbSession < Session #:nodoc:
|
12
12
|
include Merb::Test::MakeRequest
|
13
|
-
|
13
|
+
|
14
14
|
attr_accessor :response
|
15
|
-
|
15
|
+
|
16
16
|
def get(url, data, headers = nil)
|
17
17
|
do_request(url, data, headers, "GET")
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def post(url, data, headers = nil)
|
21
21
|
do_request(url, data, headers, "POST")
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def put(url, data, headers = nil)
|
25
25
|
do_request(url, data, headers, "PUT")
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def delete(url, data, headers = nil)
|
29
29
|
do_request(url, data, headers, "DELETE")
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def response_body
|
33
33
|
@response.body.to_s
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def response_code
|
37
37
|
@response.status
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def do_request(url, data, headers, method)
|
41
|
-
@response = request(url,
|
42
|
-
:params => (data && data.any?) ? data : nil,
|
41
|
+
@response = request(url,
|
42
|
+
:params => (data && data.any?) ? data : nil,
|
43
43
|
:headers => headers,
|
44
44
|
:method => method)
|
45
45
|
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/rails.rb
CHANGED
@@ -7,7 +7,7 @@ require "action_controller/record_identifier"
|
|
7
7
|
module Webrat
|
8
8
|
class RailsSession < Session #:nodoc:
|
9
9
|
include ActionController::RecordIdentifier
|
10
|
-
|
10
|
+
|
11
11
|
# The Rails version of within supports passing in a model and Webrat
|
12
12
|
# will apply a scope based on Rails' dom_id for that model.
|
13
13
|
#
|
@@ -22,7 +22,7 @@ module Webrat
|
|
22
22
|
super('#' + dom_id(selector_or_object), &block)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def doc_root
|
27
27
|
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
28
28
|
end
|
data/lib/webrat/rspec-rails.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Supports using the matchers in controller, helper, and view specs if you're
|
2
2
|
# using rspec-rails. Just add a require statement to spec/spec_helper.rb or env.rb:
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# require 'webrat/rspec-rails'
|
5
5
|
#
|
6
6
|
require "webrat/core/matchers"
|
@@ -10,4 +10,4 @@ Spec::Runner.configure do |config|
|
|
10
10
|
config.include(Webrat::Matchers, :type => :controller)
|
11
11
|
config.include(Webrat::Matchers, :type => :helper)
|
12
12
|
config.include(Webrat::Matchers, :type => :view)
|
13
|
-
end
|
13
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Webrat
|
2
|
+
module Selenium
|
3
|
+
|
4
|
+
class ApplicationServer
|
5
|
+
|
6
|
+
include Webrat::Selenium::SilenceStream
|
7
|
+
|
8
|
+
def self.boot
|
9
|
+
case Webrat.configuration.application_framework
|
10
|
+
when :sinatra
|
11
|
+
require "webrat/selenium/sinatra_application_server"
|
12
|
+
SinatraApplicationServer.new.boot
|
13
|
+
when :merb
|
14
|
+
require "webrat/selenium/merb_application_server"
|
15
|
+
MerbApplicationServer.new.boot
|
16
|
+
when :rails
|
17
|
+
require "webrat/selenium/rails_application_server"
|
18
|
+
RailsApplicationServer.new.boot
|
19
|
+
else
|
20
|
+
raise WebratError.new(<<-STR)
|
21
|
+
Unknown Webrat application_framework: #{Webrat.configuration.application_framework.inspect}
|
22
|
+
|
23
|
+
Please ensure you have a Webrat configuration block that specifies an application_framework
|
24
|
+
in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).
|
25
|
+
|
26
|
+
For example:
|
27
|
+
|
28
|
+
Webrat.configure do |config|
|
29
|
+
# ...
|
30
|
+
config.application_framework = :rails
|
31
|
+
end
|
32
|
+
STR
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def boot
|
37
|
+
start
|
38
|
+
wait
|
39
|
+
stop_at_exit
|
40
|
+
end
|
41
|
+
|
42
|
+
def stop_at_exit
|
43
|
+
at_exit do
|
44
|
+
stop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def wait
|
49
|
+
$stderr.print "==> Waiting for #{Webrat.configuration.application_framework} application server on port #{Webrat.configuration.application_port}... "
|
50
|
+
wait_for_socket
|
51
|
+
$stderr.print "Ready!\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
def wait_for_socket
|
55
|
+
silence_stream(STDOUT) do
|
56
|
+
silence_stream(STDERR) do
|
57
|
+
TCPSocket.wait_for_service_with_timeout \
|
58
|
+
:host => Webrat.configuration.application_address,
|
59
|
+
:port => Webrat.configuration.application_port.to_i,
|
60
|
+
:timeout => 30 # seconds
|
61
|
+
end
|
62
|
+
end
|
63
|
+
rescue SocketError
|
64
|
+
fail
|
65
|
+
end
|
66
|
+
|
67
|
+
def prepare_pid_file(file_path, pid_file_name)
|
68
|
+
FileUtils.mkdir_p File.expand_path(file_path)
|
69
|
+
File.expand_path("#{file_path}/#{pid_file_name}")
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -5,14 +5,14 @@ module Webrat
|
|
5
5
|
def initialize(content)
|
6
6
|
@content = content
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def matches?(response)
|
10
10
|
if @content.is_a?(Regexp)
|
11
11
|
text_finder = "regexp:#{@content.source}"
|
12
12
|
else
|
13
13
|
text_finder = @content
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
response.session.wait_for do
|
17
17
|
response.selenium.is_text_present(text_finder)
|
18
18
|
end
|
@@ -47,7 +47,7 @@ module Webrat
|
|
47
47
|
def contain(content)
|
48
48
|
HasContent.new(content)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
# Asserts that the body of the response contain
|
52
52
|
# the supplied string or regexp
|
53
53
|
def assert_contain(content)
|
@@ -63,4 +63,4 @@ module Webrat
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
-
end
|
66
|
+
end
|
@@ -5,7 +5,7 @@ module Webrat
|
|
5
5
|
def initialize(expected)
|
6
6
|
@expected = expected
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def matches?(response)
|
10
10
|
response.session.wait_for do
|
11
11
|
response.selenium.is_element_present("css=#{@expected}")
|
@@ -26,11 +26,11 @@ module Webrat
|
|
26
26
|
"expected following text to not match selector #{@expected}:\n#{@document}"
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def have_selector(content)
|
31
31
|
HaveSelector.new(content)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# Asserts that the body of the response contains
|
35
35
|
# the supplied selector
|
36
36
|
def assert_have_selector(expected)
|
@@ -46,4 +46,4 @@ module Webrat
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
|
-
end
|
49
|
+
end
|
@@ -1,72 +1,72 @@
|
|
1
1
|
module Webrat
|
2
2
|
module Selenium
|
3
3
|
module Matchers
|
4
|
-
|
4
|
+
|
5
5
|
class HaveTag < HaveSelector #:nodoc:
|
6
6
|
# ==== Returns
|
7
7
|
# String:: The failure message.
|
8
8
|
def failure_message
|
9
9
|
"expected following output to contain a #{tag_inspect} tag:\n#{@document}"
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
# ==== Returns
|
13
13
|
# String:: The failure message to be displayed in negative matches.
|
14
14
|
def negative_failure_message
|
15
15
|
"expected following output to omit a #{tag_inspect}:\n#{@document}"
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def tag_inspect
|
19
19
|
options = @expected.last.dup
|
20
20
|
content = options.delete(:content)
|
21
|
-
|
21
|
+
|
22
22
|
html = "<#{@expected.first}"
|
23
23
|
options.each do |k,v|
|
24
24
|
html << " #{k}='#{v}'"
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
if content
|
28
28
|
html << ">#{content}</#{@expected.first}>"
|
29
29
|
else
|
30
30
|
html << "/>"
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
html
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def query
|
37
37
|
options = @expected.last.dup
|
38
38
|
selector = @expected.first.to_s
|
39
|
-
|
39
|
+
|
40
40
|
selector << ":contains('#{options.delete(:content)}')" if options[:content]
|
41
|
-
|
41
|
+
|
42
42
|
options.each do |key, value|
|
43
43
|
selector << "[#{key}='#{value}']"
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
Nokogiri::CSS.parse(selector).map { |ast| ast.to_xpath }
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def have_tag(name, attributes = {}, &block)
|
51
51
|
HaveTag.new([name, attributes], &block)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
alias_method :match_tag, :have_tag
|
55
|
-
|
55
|
+
|
56
56
|
# Asserts that the body of the response contains
|
57
57
|
# the supplied tag with the associated selectors
|
58
58
|
def assert_have_tag(name, attributes = {})
|
59
59
|
ht = HaveTag.new([name, attributes])
|
60
60
|
assert ht.matches?(response), ht.failure_message
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
# Asserts that the body of the response
|
64
64
|
# does not contain the supplied string or regepx
|
65
65
|
def assert_have_no_tag(name, attributes = {})
|
66
66
|
ht = HaveTag.new([name, attributes])
|
67
67
|
assert !ht.matches?(response), ht.negative_failure_message
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
end
|
71
71
|
end
|
72
|
-
end
|
72
|
+
end
|
@@ -5,7 +5,7 @@ module Webrat
|
|
5
5
|
def initialize(expected)
|
6
6
|
@expected = expected
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def matches?(response)
|
10
10
|
response.session.wait_for do
|
11
11
|
response.selenium.is_element_present("xpath=#{@expected}")
|
@@ -26,11 +26,11 @@ module Webrat
|
|
26
26
|
"expected following text to not match xpath #{@expected}:\n#{@document}"
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def have_xpath(xpath)
|
31
31
|
HaveXpath.new(xpath)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def assert_have_xpath(expected)
|
35
35
|
hs = HaveXpath.new(expected)
|
36
36
|
assert hs.matches?(response), hs.failure_message
|
@@ -42,4 +42,4 @@ module Webrat
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Webrat
|
2
|
+
module Selenium
|
3
|
+
|
4
|
+
class MerbApplicationServer < ApplicationServer
|
5
|
+
|
6
|
+
def start
|
7
|
+
system start_command
|
8
|
+
end
|
9
|
+
|
10
|
+
def stop
|
11
|
+
silence_stream(STDERR) do
|
12
|
+
silence_stream(STDOUT) do
|
13
|
+
pid = File.read(pid_file)
|
14
|
+
system("kill -9 #{pid}")
|
15
|
+
FileUtils.rm_f pid_file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def fail
|
21
|
+
$stderr.puts
|
22
|
+
$stderr.puts
|
23
|
+
$stderr.puts "==> Failed to boot the Merb application server... exiting!"
|
24
|
+
$stderr.puts
|
25
|
+
$stderr.puts "Verify you can start a Merb server on port #{Webrat.configuration.application_port} with the following command:"
|
26
|
+
$stderr.puts
|
27
|
+
$stderr.puts " #{start_command}"
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
def pid_file
|
32
|
+
"log/merb.#{Webrat.configuration.application_port}.pid"
|
33
|
+
end
|
34
|
+
|
35
|
+
def start_command
|
36
|
+
"#{merb_command} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def merb_command
|
40
|
+
if File.exist?('bin/merb')
|
41
|
+
merb_cmd = 'bin/merb'
|
42
|
+
else
|
43
|
+
merb_cmd = 'merb'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Webrat
|
2
|
+
module Selenium
|
3
|
+
|
4
|
+
class RailsApplicationServer < ApplicationServer
|
5
|
+
|
6
|
+
def start
|
7
|
+
system start_command
|
8
|
+
end
|
9
|
+
|
10
|
+
def stop
|
11
|
+
silence_stream(STDERR) do
|
12
|
+
silence_stream(STDOUT) do
|
13
|
+
system stop_command
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def fail
|
19
|
+
$stderr.puts
|
20
|
+
$stderr.puts
|
21
|
+
$stderr.puts "==> Failed to boot the Rails application server... exiting!"
|
22
|
+
$stderr.puts
|
23
|
+
$stderr.puts "Verify you can start a Rails server on port #{Webrat.configuration.application_port} with the following command:"
|
24
|
+
$stderr.puts
|
25
|
+
$stderr.puts " #{start_command}"
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
29
|
+
def pid_file
|
30
|
+
prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
|
31
|
+
end
|
32
|
+
|
33
|
+
def start_command
|
34
|
+
"mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &"
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop_command
|
38
|
+
"mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Webrat
|
2
|
+
module Selenium
|
3
|
+
|
4
|
+
class SeleniumRCServer
|
5
|
+
|
6
|
+
include Webrat::Selenium::SilenceStream
|
7
|
+
|
8
|
+
def self.boot
|
9
|
+
new.boot
|
10
|
+
end
|
11
|
+
|
12
|
+
def boot
|
13
|
+
return if selenium_grid?
|
14
|
+
|
15
|
+
start
|
16
|
+
wait
|
17
|
+
stop_at_exit
|
18
|
+
end
|
19
|
+
|
20
|
+
def start
|
21
|
+
silence_stream(STDERR) do
|
22
|
+
silence_stream(STDOUT) do
|
23
|
+
remote_control.start :background => true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def stop_at_exit
|
29
|
+
at_exit do
|
30
|
+
stop
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def remote_control
|
35
|
+
return @remote_control if @remote_control
|
36
|
+
|
37
|
+
@remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0",
|
38
|
+
Webrat.configuration.selenium_server_port,
|
39
|
+
Webrat.configuration.selenium_browser_startup_timeout)
|
40
|
+
@remote_control.jar_file = jar_path
|
41
|
+
|
42
|
+
return @remote_control
|
43
|
+
end
|
44
|
+
|
45
|
+
def jar_path
|
46
|
+
File.expand_path(__FILE__ + "../../../../../vendor/selenium-server.jar")
|
47
|
+
end
|
48
|
+
|
49
|
+
def selenium_grid?
|
50
|
+
Webrat.configuration.selenium_server_address
|
51
|
+
end
|
52
|
+
|
53
|
+
def wait
|
54
|
+
$stderr.print "==> Waiting for Selenium RC server on port #{Webrat.configuration.selenium_server_port}... "
|
55
|
+
wait_for_socket
|
56
|
+
$stderr.print "Ready!\n"
|
57
|
+
rescue SocketError
|
58
|
+
fail
|
59
|
+
end
|
60
|
+
|
61
|
+
def wait_for_socket
|
62
|
+
silence_stream(STDERR) do
|
63
|
+
silence_stream(STDOUT) do
|
64
|
+
TCPSocket.wait_for_service_with_timeout \
|
65
|
+
:host => (Webrat.configuration.selenium_server_address || "0.0.0.0"),
|
66
|
+
:port => Webrat.configuration.selenium_server_port,
|
67
|
+
:timeout => 15 # seconds
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def fail
|
73
|
+
$stderr.puts
|
74
|
+
$stderr.puts
|
75
|
+
$stderr.puts "==> Failed to boot the Selenium RC server... exiting!"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
|
79
|
+
def stop
|
80
|
+
silence_stream(STDERR) do
|
81
|
+
silence_stream(STDOUT) do
|
82
|
+
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|