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 module PersistentSelenium
class << self class << self
attr_writer :port, :browser attr_writer :port, :browser, :timeout
def port def port
@port ||= 9854 @port ||= 9854
@ -13,6 +13,10 @@ module PersistentSelenium
@browser ||= :firefox @browser ||= :firefox
end end
def timeout
@timeout ||= 120
end
def url def url
"druby://localhost:#{port}" "druby://localhost:#{port}"
end end

View File

@ -10,14 +10,15 @@ module PersistentSelenium
end end
desc "start", "Start the server" 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 def start
require 'persistent_selenium/browser' require 'persistent_selenium/browser'
require 'drb' require 'persistent_selenium/drb'
PersistentSelenium.configure do |c| PersistentSelenium.configure do |c|
c.port = options[:port] c.port = options[:port]
c.browser = options[:browser] c.browser = options[:browser]
c.timeout = options[:timeout]
end end
puts "Starting persistent_selenium on #{PersistentSelenium.port} with #{PersistentSelenium.browser}" 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
end end
Capybara.register_driver :persistent_selenium do |app| require 'persistent_selenium/drb'
require 'drb'
DRb.start_service Capybara.register_driver :persistent_selenium do |app|
service = DRb.start_service
browser = DRbObject.new nil, PersistentSelenium.url browser = DRbObject.new nil, PersistentSelenium.url
server = Capybara::Server.new(app) server = Capybara::Server.new(app)