class Applitools::AgentConnector

Attributes

auth[R]

debug_output $stdout # comment out when not debugging

uri[R]

debug_output $stdout # comment out when not debugging

Public Class Methods

new(base_uri, username, password) click to toggle source
# 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

Public Instance Methods

match_window(session, data) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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