add timeout option
This commit is contained in:
parent
34693f4ef0
commit
f6bfa0cf29
@ -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
|
||||
|
@ -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}"
|
||||
|
17
lib/persistent_selenium/drb.rb
Normal file
17
lib/persistent_selenium/drb.rb
Normal 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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user