Class: WatirProxy::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-proxy.rb

Constant Summary collapse

@@default_browser =
:firefox
@@default_drb_uri =
'druby://localhost:12444'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream = $stdout) ⇒ Server

Returns a new instance of Server.



68
69
70
71
72
# File 'lib/watir-proxy.rb', line 68

def initialize(stream = $stdout)
  @stream  = stream
  @current_browser = @@default_browser
  @browsers = {}
end

Instance Attribute Details

#current_browserObject

Returns the value of attribute current_browser.



27
28
29
# File 'lib/watir-proxy.rb', line 27

def current_browser
  @current_browser
end

#streamObject

Returns the value of attribute stream.



27
28
29
# File 'lib/watir-proxy.rb', line 27

def stream
  @stream
end

Class Method Details

.browser(opts = {}, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/watir-proxy.rb', line 32

def self.browser(opts = {}, &block)
  drb, browser = nil, nil
  begin
    drb = DRbObject.new_with_uri(self.drb_uri(opts))
  rescue DRb::DRbConnError => e
    browser = self.new(StringIO.new).browser(opts)
  end

  Browser.new({
    :drb     => drb,
    :browser => browser,
    :options => opts,
  })
end

.default_drb_uriObject



47
48
49
# File 'lib/watir-proxy.rb', line 47

def self.default_drb_uri
  @@default_drb_uri
end

.drb_uri(opts = {}) ⇒ Object



51
52
53
# File 'lib/watir-proxy.rb', line 51

def self.drb_uri(opts = {})
  opts[:drb_uri] || ENV['WATIR_PROXY_DRB_URI'] || self.default_drb_uri
end

.start_service(opts = {}, &block) ⇒ Object



55
56
57
58
# File 'lib/watir-proxy.rb', line 55

def self.start_service(opts = {}, &block)
  DRb.start_service(self.drb_uri(opts), self.new)
  yield if block
end

.stop_service(&block) ⇒ Object



60
61
62
# File 'lib/watir-proxy.rb', line 60

def self.stop_service(&block)
  DRb.stop_service
end

.threadObject



64
65
66
# File 'lib/watir-proxy.rb', line 64

def self.thread
  DRb.thread
end

Instance Method Details

#browser(opts = {}) ⇒ Object



78
79
80
81
# File 'lib/watir-proxy.rb', line 78

def browser(opts = {})
  @current_browser = opts[:type] || @current_browser
  @browsers[@current_browser] ||= new_browser(@current_browser)
end

#browser_call(opts, name, *args) ⇒ Object



74
75
76
# File 'lib/watir-proxy.rb', line 74

def browser_call(opts, name, *args)
  self.browser(opts).send name, *args
end

#new_browser(type) ⇒ Object



83
84
85
# File 'lib/watir-proxy.rb', line 83

def new_browser(type)
  Watir::Browser.new(type)
end