class SeleniumSurfer::DriverBucket
### Webdriver connection wrapper
By wrapping the connection is posible to control reconnection and bound context, this allows for safe context navigation.
Attributes
session_id[R]
Public Class Methods
new(_session_id, _anonymous, _caps)
click to toggle source
# File lib/selenium_surfer/driver_bucket.rb, line 12 def initialize(_session_id, _anonymous, _caps) @session_id = _session_id @bound_ctx = nil @anonymous = _anonymous @caps = _caps end
Public Instance Methods
bind(_ctx)
click to toggle source
bind a context to this bucket
The context may implement the `on_unbind` method to be notified when the bucket it is unbound from the bucket
# File lib/selenium_surfer/driver_bucket.rb, line 72 def bind(_ctx) @bound_ctx.on_unbind if @bound_ctx and @bound_ctx.respond_to? :on_unbind @bound_ctx = _ctx end
bound?()
click to toggle source
return true if there is a context bound to this bucket
# File lib/selenium_surfer/driver_bucket.rb, line 63 def bound? not @bound_ctx.nil? end
driver(_reset=false)
click to toggle source
get the current driver instance, reset it if required
# File lib/selenium_surfer/driver_bucket.rb, line 20 def driver(_reset=false) reset if _reset # TODO retrieve config data from config file instead of ENV if @driver.nil? driver_name = SeleniumSurfer.config[:webdriver] raise ConfigurationError.new 'must provide a webdriver type' if driver_name.nil? case driver_name.to_sym when :remote # select capabilities object caps = SeleniumSurfer.config[:capabilities] caps = @caps if @caps caps = Selenium::WebDriver::Remote::Capabilities.firefox if caps.nil? url = SeleniumSurfer.config[:remote_host] # setup a custom client to use longer timeouts client = Selenium::WebDriver::Remote::Http::Default.new client.timeout = SeleniumSurfer.config[:remote_timeout] @driver = Selenium::WebDriver.for :remote, :url => url, :http_client => client, :desired_capabilities => caps else @driver = Selenium::WebDriver.for driver_name.to_sym # apply browser configuration to new driver @driver.manage.window.resize_to(SeleniumSurfer.config[:window_width], SeleniumSurfer.config[:window_height]) rescue nil end end return @driver end
reset()
click to toggle source
force current driver connection to be discarded
# File lib/selenium_surfer/driver_bucket.rb, line 55 def reset if @driver @driver.quit rescue nil @driver = nil end end
unbind()
click to toggle source
unbinds the currently bound context.
# File lib/selenium_surfer/driver_bucket.rb, line 78 def unbind if @bound_ctx @bound_ctx.on_unbind if @bound_ctx.respond_to? :on_unbind @bound_ctx = nil end reset if @anonymous # reset bucket if required end