Class: Applitools::AgentConnector

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/eyes_selenium/eyes/agent_connector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_url) ⇒ AgentConnector

Returns a new instance of AgentConnector.



20
21
22
# File 'lib/eyes_selenium/eyes/agent_connector.rb', line 20

def initialize(server_url)
  self.server_url = server_url
end

Instance Attribute Details

#api_keyObject

comment out when not debugging http_proxy ‘localhost’, 8888 debug_output $stdout



12
13
14
# File 'lib/eyes_selenium/eyes/agent_connector.rb', line 12

def api_key
  @api_key
end

#server_urlObject

comment out when not debugging http_proxy ‘localhost’, 8888 debug_output $stdout



12
13
14
# File 'lib/eyes_selenium/eyes/agent_connector.rb', line 12

def server_url
  @server_url
end

Instance Method Details

#match_window(session, data) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/eyes_selenium/eyes/agent_connector.rb', line 24

def match_window(session, data)
  self.class.headers 'Content-Type' => 'application/octet-stream'
  json_data = data.to_hash.to_json.force_encoding('BINARY') # Notice that this does not include the screenshot
  body = [json_data.length].pack('L>') + json_data + data.screenshot
  EyesLogger.debug 'Sending match data...'
  res = self.class.post(@endpoint_uri + "/#{session.id}", query: {apiKey: api_key}, body: body)
  raise Applitools::EyesError.new('could not connect to server') if res.code != 200
  EyesLogger.debug "Got response! #{res.parsed_response['asExpected']}"
  res.parsed_response['asExpected']
end

#start_session(session_start_info) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/eyes_selenium/eyes/agent_connector.rb', line 35

def start_session(session_start_info)
 self.class.headers 'Content-Type' => 'application/json'
 res = self.class.post(@endpoint_uri, query: {apiKey: api_key}, body: { startInfo: session_start_info.to_hash }.to_json)
 status_code = res.response.message
 parsed_res = res.parsed_response
 Applitools::Session.new(parsed_res['id'], parsed_res['url'], status_code == 'Created' )
end

#stop_session(session, aborted = nil, save = false) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/eyes_selenium/eyes/agent_connector.rb', line 43

def stop_session(session, aborted=nil, save=false)
  self.class.headers 'Content-Type' => 'application/json'
  res = self.class.send_long_request('stop_session') do
      self.class.delete(@endpoint_uri + "/#{session.id}", query: { aborted: aborted.to_s, updateBaseline: save.to_s, apiKey: api_key })
  end
  parsed_res = res.parsed_response
  parsed_res.delete('$id')
  Applitools::TestResults.new(*parsed_res.values)
end