Class: Capybara::Apparition::ChromeClient

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/apparition/driver/response.rb,
lib/capybara/apparition/driver/chrome_client.rb

Defined Under Namespace

Classes: Response

Constant Summary collapse

DEFAULT_OPTIONS =
{
  host: 'localhost',
  port: 9222
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ws_url) ⇒ ChromeClient

Returns a new instance of ChromeClient.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/capybara/apparition/driver/chrome_client.rb', line 32

def initialize(ws_url)
  @ws = WebSocketClient.new(ws_url)
  @handlers = Hash.new { |hash, key| hash[key] = [] }

  @responses = {}

  @events = Queue.new

  @send_mutex = Mutex.new
  @msg_mutex = Mutex.new
  @message_available = ConditionVariable.new
  @session_handlers = Hash.new { |hash, key| hash[key] = Hash.new { |h, k| h[k] = [] } }
  @timeout = nil
  @async_ids = []

  start_threads
end

Instance Attribute Details

#timeoutObject

Returns the value of attribute timeout.



50
51
52
# File 'lib/capybara/apparition/driver/chrome_client.rb', line 50

def timeout
  @timeout
end

Class Method Details

.client(ws_url) ⇒ Object



15
16
17
# File 'lib/capybara/apparition/driver/chrome_client.rb', line 15

def client(ws_url)
  new(ws_url)
end

Instance Method Details

#add_async_id(msg_id) ⇒ Object



75
76
77
78
79
# File 'lib/capybara/apparition/driver/chrome_client.rb', line 75

def add_async_id(msg_id)
  @msg_mutex.synchronize do
    @async_ids.push(msg_id)
  end
end

#on(event_name, session_id = nil, &block) ⇒ Object



56
57
58
59
60
# File 'lib/capybara/apparition/driver/chrome_client.rb', line 56

def on(event_name, session_id = nil, &block)
  return @handlers[event_name] << block unless session_id

  @session_handlers[session_id][event_name] << block
end

#send_cmd(command, params) ⇒ Object



62
63
64
65
66
# File 'lib/capybara/apparition/driver/chrome_client.rb', line 62

def send_cmd(command, params)
  time = Time.now
  msg_id = send_msg(command, params)
  Response.new(self, msg_id, send_time: time)
end

#send_cmd_to_session(session_id, command, params) ⇒ Object



68
69
70
71
72
73
# File 'lib/capybara/apparition/driver/chrome_client.rb', line 68

def send_cmd_to_session(session_id, command, params)
  time = Time.now
  msg_id, msg = generate_msg(command, params)
  wrapper_msg_id = send_msg('Target.sendMessageToTarget', sessionId: session_id, message: msg)
  Response.new(self, wrapper_msg_id, msg_id, send_time: time)
end

#stopObject



52
53
54
# File 'lib/capybara/apparition/driver/chrome_client.rb', line 52

def stop
  @ws.close
end