Class: Applitools::Connectivity::ServerConnector
- Inherits:
-
Object
- Object
- Applitools::Connectivity::ServerConnector
show all
- Extended by:
- Helpers
- Defined in:
- lib/applitools/connectivity/server_connector.rb
Constant Summary
collapse
- DEFAULT_SERVER_URL =
'https://eyessdk.applitools.com'.freeze
- SSL_CERT =
File.join(File.dirname(File.expand_path(__FILE__)), '../../../certs/cacert.pem').to_s.freeze
- DEFAULT_TIMEOUT =
300
- API_SESSIONS_RUNNING =
'/api/sessions/running/'.freeze
- API_SINGLE_TEST =
'/api/sessions/'.freeze
- HTTP_STATUS_CODES =
{
created: 201,
accepted: 202,
ok: 200,
gone: 410
}.freeze
- RETRY_DELAY =
0.5
- RETRY_STEP_FACTOR =
1.5
- RETRY_MAX_DELAY =
5
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
abstract_attr_accessor, abstract_method, environment_attribute, environment_variables
Constructor Details
Returns a new instance of ServerConnector.
32
33
34
|
# File 'lib/applitools/connectivity/server_connector.rb', line 32
def initialize(url = nil)
self.server_url = url
end
|
Instance Attribute Details
#endpoint_url ⇒ Object
Returns the value of attribute endpoint_url.
28
29
30
|
# File 'lib/applitools/connectivity/server_connector.rb', line 28
def endpoint_url
@endpoint_url
end
|
#proxy ⇒ Object
Returns the value of attribute proxy.
29
30
31
|
# File 'lib/applitools/connectivity/server_connector.rb', line 29
def proxy
@proxy
end
|
#server_url ⇒ Object
Returns the value of attribute server_url.
27
28
29
|
# File 'lib/applitools/connectivity/server_connector.rb', line 27
def server_url
@server_url
end
|
Instance Method Details
#match_single_window(data) ⇒ Object
101
102
103
104
|
# File 'lib/applitools/connectivity/server_connector.rb', line 101
def match_single_window(data)
res = match_single_window_data(data)
Applitools::TestResults.new Oj.load(res.body)
end
|
#match_single_window_data(data) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/applitools/connectivity/server_connector.rb', line 73
def match_single_window_data(data)
json_data = Oj.dump(data.to_hash).force_encoding('BINARY')
body = [json_data.length].pack('L>') + json_data + data.screenshot
begin
Applitools::EyesLogger.debug 'Sending match data...'
res = long_post(
@single_check_endpoint_url,
content_type: 'application/octet-stream',
body: body,
query: { agent_id: data.agent_id }
)
rescue Errno::EWOULDBLOCK, Faraday::ConnectionFailed
@delays ||= request_delay(RETRY_DELAY, RETRY_STEP_FACTOR, RETRY_MAX_DELAY)
begin
sleep @delays.next
rescue StopIteration
raise Applitools::UnknownNetworkStackError.new('Unknown network stack error')
end
res = match_single_window_data(data)
ensure
@delays = nil
end
raise Applitools::EyesError.new("Request failed: #{res.status} #{res.} #{res.body}") unless res.success?
res
end
|
#match_window(session, data) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/applitools/connectivity/server_connector.rb', line 58
def match_window(session, data)
json_data = Oj.dump(Applitools::Utils.camelcase_hash_keys(data.to_hash)).force_encoding('BINARY')
body = [json_data.length].pack('L>') + json_data + data.screenshot
Applitools::EyesLogger.debug 'Sending match data...'
res = long_post(URI.join(endpoint_url, session.id.to_s), content_type: 'application/octet-stream', body: body)
raise Applitools::EyesError.new("Request failed: #{res.status} #{res.}") unless res.success?
Applitools::MatchResult.new Oj.load(res.body)
end
|
#post_dom_json(dom_data) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/applitools/connectivity/server_connector.rb', line 127
def post_dom_json(dom_data)
Applitools::EyesLogger.debug 'About to send captured DOM...'
request_body = Oj.dump(dom_data)
Applitools::EyesLogger.debug request_body
processed_request_body = yield(request_body) if block_given?
res = post(
endpoint_url + 'data',
body: processed_request_body.nil? ? request_body : processed_request_body,
content_type: 'application/octet-stream'
)
Applitools::EyesLogger.debug 'Done!'
raise Applitools::EyesError.new("Request failed: #{res.status} #{res.body}") unless res.success?
Applitools::EyesLogger.debug 'Server response headers:'
Applitools::EyesLogger.debug res..inspect
res.['location']
end
|
#set_proxy(uri, user = nil, password = nil) ⇒ Object
46
47
48
|
# File 'lib/applitools/connectivity/server_connector.rb', line 46
def set_proxy(uri, user = nil, password = nil)
self.proxy = Proxy.new uri, user, password
end
|
#start_session(session_start_info) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/applitools/connectivity/server_connector.rb', line 106
def start_session(session_start_info)
request_body = Oj.dump(
startInfo: Applitools::Utils.camelcase_hash_keys(session_start_info.to_hash)
)
res = post(
endpoint_url, body: request_body
)
raise Applitools::EyesError.new("Request failed: #{res.status} #{res.body} #{request_body}") unless res.success?
response = Oj.load(res.body)
Applitools::Session.new(response['id'], response['url'], res.status == HTTP_STATUS_CODES[:created])
end
|
#stop_session(session, aborted = nil, save = false) ⇒ Object
119
120
121
122
123
124
125
|
# File 'lib/applitools/connectivity/server_connector.rb', line 119
def stop_session(session, aborted = nil, save = false)
res = long_delete(URI.join(endpoint_url, session.id.to_s), query: { aborted: aborted, updateBaseline: save })
raise Applitools::EyesError.new("Request failed: #{res.status}") unless res.success?
response = Oj.load(res.body)
Applitools::TestResults.new(response)
end
|