add timeout option

This commit is contained in:
John Bintz 2013-05-14 10:57:55 -04:00
parent 34693f4ef0
commit f6bfa0cf29
4 changed files with 28 additions and 6 deletions

View File

@ -3,7 +3,7 @@ require 'selenium-webdriver'
module PersistentSelenium
class << self
attr_writer :port, :browser
attr_writer :port, :browser, :timeout
def port
@port ||= 9854
@ -13,6 +13,10 @@ module PersistentSelenium
@browser ||= :firefox
end
def timeout
@timeout ||= 120
end
def url
"druby://localhost:#{port}"
end

View File

@ -10,14 +10,15 @@ module PersistentSelenium
end
desc "start", "Start the server"
method_options :port => PersistentSelenium.port, :browser => PersistentSelenium.browser
method_options :port => PersistentSelenium.port, :browser => PersistentSelenium.browser, :timeout => PersistentSelenium.timeout
def start
require 'persistent_selenium/browser'
require 'drb'
require 'persistent_selenium/drb'
PersistentSelenium.configure do |c|
c.port = options[:port]
c.browser = options[:browser]
c.timeout = options[:timeout]
end
puts "Starting persistent_selenium on #{PersistentSelenium.port} with #{PersistentSelenium.browser}"

View File

@ -0,0 +1,17 @@
require 'drb'
module DRb
class DRbTCPSocket
alias :_set_sockopt :set_sockopt
def set_sockopt(soc)
_set_sockopt(soc)
optval = [ PersistentSelenium.timeout, 0 ].pack("l_2")
soc.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
soc.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
end
end
end

View File

@ -11,10 +11,10 @@ Before do
end
end
Capybara.register_driver :persistent_selenium do |app|
require 'drb'
require 'persistent_selenium/drb'
DRb.start_service
Capybara.register_driver :persistent_selenium do |app|
service = DRb.start_service
browser = DRbObject.new nil, PersistentSelenium.url
server = Capybara::Server.new(app)