Class: Applitools::AgentConnector

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/eyes_selenium_ruby/eyes/agent_connecter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri, username, password) ⇒ AgentConnector

Returns a new instance of AgentConnector.



8
9
10
11
12
# File 'lib/eyes_selenium_ruby/eyes/agent_connecter.rb', line 8

def initialize(base_uri, username, password)
  # Remove trailing slashes in base uri and add the running sessions endpoint uri.
  @uri = base_uri.gsub(/\/$/,"") + "/api/sessions/running"
  @auth = { username: username, password: password }
end

Instance Attribute Details

#authObject (readonly)

debug_output $stdout # comment out when not debugging



7
8
9
# File 'lib/eyes_selenium_ruby/eyes/agent_connecter.rb', line 7

def auth
  @auth
end

#uriObject (readonly)

debug_output $stdout # comment out when not debugging



7
8
9
# File 'lib/eyes_selenium_ruby/eyes/agent_connecter.rb', line 7

def uri
  @uri
end

Instance Method Details

#match_window(session, data) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/eyes_selenium_ruby/eyes/agent_connecter.rb', line 14

def match_window(session, data)
  self.class.headers 'Content-Type' => 'application/octet-stream'
  json_data = data.to_hash.to_json.encode('UTF-8') # Notice that this does not include the screenshot
  body = [json_data.length].pack('L>') + json_data + data.screenshot

  res = self.class.post(uri + "/#{session.id}",basic_auth: auth, body: body)
  raise Applitools::EyesError.new("could not connect to server") if res.code != 200
  res.parsed_response["asExpected"]
end

#start_session(session_start_info) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/eyes_selenium_ruby/eyes/agent_connecter.rb', line 24

def start_session(session_start_info)
 self.class.headers 'Content-Type' => 'application/json'
 res = self.class.post(uri, basic_auth: auth, 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) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/eyes_selenium_ruby/eyes/agent_connecter.rb', line 32

def stop_session(session, aborted=nil)
  self.class.headers 'Content-Type' => 'application/json'
  res = self.class.delete(uri + "/#{session.id}", basic_auth: auth, params: { aborted: aborted.to_s })
  parsed_res = res.parsed_response
  parsed_res.delete("$id")
  Applitools::TestResults.new(*parsed_res.values)
end