Class: Applitools::Connectivity::UniversalClient

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/applitools/universal_sdk/universal_client.rb

Constant Summary collapse

CORE_GET_EC_CLIENT =
'Core.getECClient'
SESSION_INIT =
'Core.makeCore'
CORE_MAKE_MANAGER =
'Core.makeManager'
CORE_GET_VIEWPORT_SIZE =
'Core.getViewportSize'
CORE_SET_VIEWPORT_SIZE =
'Core.setViewportSize'
CORE_CLOSE_BATCHES =
'Core.closeBatch'
CORE_DELETE_TEST =
'Core.deleteTest'
EYES_MANAGER_MAKE_EYES =
'EyesManager.openEyes'
EYES_MANAGER_CLOSE_ALL_EYES =
'EyesManager.getResults'
EYES_CHECK =
'Eyes.check'
EYES_CHECK_AND_CLOSE =

'Eyes.checkAndClose'
EYES_LOCATE =
'Core.locate'
EYES_EXTRACT_TEXT_REGIONS =
'Core.locateText'
EYES_EXTRACT_TEXT =
'Core.extractText'
EYES_CLOSE =
'Eyes.close'
EYES_ABORT =
'Eyes.abort'
EYES_GET_RESULTS =
'Eyes.getResults'
SERVER_LOG_EVENT_NAME =
'Logger.log'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(eyes = nil) ⇒ UniversalClient

Returns a new instance of UniversalClient.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/applitools/universal_sdk/universal_client.rb', line 44

def initialize(eyes=nil)
  # @socket = Applitools::Connectivity::UniversalClientSocket.new
  prepare_socket(eyes)
  # store on open for next check calls
  @open_config = nil
  @commands_config = {
    open: {},
    screenshot: {},
    check: {},
    close: {}
  }
end

Instance Attribute Details

#commands_configObject

Returns the value of attribute commands_config.



42
43
44
# File 'lib/applitools/universal_sdk/universal_client.rb', line 42

def commands_config
  @commands_config
end

Instance Method Details

#config_mapping(old_config, command_config, name) ⇒ Object



112
113
114
115
# File 'lib/applitools/universal_sdk/universal_client.rb', line 112

def config_mapping(old_config, command_config, name)
  return if old_config[name].nil?
  command_config[name] = old_config.delete(name)
end

#core_close_batches(close_batch_settings = nil) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/applitools/universal_sdk/universal_client.rb', line 321

def core_close_batches(close_batch_settings=nil)
  # interface CloseBatchRequestPayload {
  #   settings: CloseBatchSettings | CloseBatchSettings[]
  # }
  unless close_batch_settings.is_a?(Hash)
    batch_ids = [@open_config[:batch][:id]]
    batch_ids = [close_batch_settings] if close_batch_settings.is_a?(String)
    batch_ids = close_batch_settings if close_batch_settings.is_a?(Array)
    optional = [:serverUrl, :apiKey, :proxy].map {|k| [k, @open_config[k]] }.to_h
    optional[:eyesServerUrl] = optional.delete(:serverUrl) if optional[:serverUrl] # v4
    close_batch_settings = { settings: ({ batchIds: batch_ids }.merge(optional).compact) }
  end
  command_with_result(CORE_CLOSE_BATCHES, close_batch_settings)
end

#core_delete_test(delete_test_settings) ⇒ Object



336
337
338
339
340
341
# File 'lib/applitools/universal_sdk/universal_client.rb', line 336

def core_delete_test(delete_test_settings)
  # interface DeleteTestRequestPayload {
  #   settings: DeleteTestSettings | DeleteTestSettings[]
  # }
  command_with_result(CORE_DELETE_TEST, delete_test_settings)
end

#core_get_viewport_size(driver) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
# File 'lib/applitools/universal_sdk/universal_client.rb', line 301

def core_get_viewport_size(driver)
  # interface GetViewportSizeRequestPayload {
  #   target: DriverTarget
  # }
  #
  # interface GetViewportSizeResponsePayload {
  #   width: number
  #   height: number
  # }
  command_with_result(CORE_GET_VIEWPORT_SIZE, {target: driver})
end

#core_make_ec_client(server_url, api_key, proxy) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/applitools/universal_sdk/universal_client.rb', line 57

def core_make_ec_client(server_url, api_key, proxy)
  # ECClientSettings
  #
  # {
  #   "options": { // default options that will be used if user do not provide `applitools:` caps
  #     "serverUrl": "https://eyesapi.applitools.com/",
  #     "apiKey": "DFH$HJD%77333J355",
  #   },
  #   "proxy": {
  #     "url": "http://localhost:8080",
  #     "username": "username",
  #     "password": "Pa$$w0rD"
  #   },
  # }
  ec_client_capabilities = {}
  ec_client_capabilities[:ecServerUrl] = server_url unless server_url.nil?
  ec_client_capabilities[:apiKey] = api_key unless api_key.nil?
  ec_client_settings = {}
  ec_client_settings[:options] = ec_client_capabilities unless ec_client_capabilities.empty?
  ec_client_settings[:proxy] = proxy unless proxy.nil?
  make_ec_client_request_payload = {settings: ec_client_settings}
  # interface GetECClientRequestPayload {
  #   settings?: ECClientSettings
  # }
  #
  # interface GetECClientResponsePayload {
  #   url: string
  # }
  command_with_result(CORE_GET_EC_CLIENT, make_ec_client_request_payload)
end

#core_make_manager(eyes_manager_config) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/applitools/universal_sdk/universal_client.rb', line 96

def core_make_manager(eyes_manager_config)
  # interface MakeManagerRequestPayload {
  #   type: 'ufg' | 'classic'
  #   settings?: EyesManagerSettings
  # }
  # ### EyesManagerSettings
  # {
  #   "concurrency": 10,
  #   "legacyConcurrency": 50,
  #   "agentId": "js/eyes/1.0.0"
  # }
  #
  # type MakeManagerResponsePayload = Ref<EyesManager>
  command_with_result(CORE_MAKE_MANAGER, eyes_manager_config)
end

#core_set_viewport_size(driver, size) ⇒ Object



313
314
315
316
317
318
319
# File 'lib/applitools/universal_sdk/universal_client.rb', line 313

def core_set_viewport_size(driver, size)
  # interface SetViewportSizeRequestPayload {
  #   target: DriverTarget
  #   size: {width: number, height: number}
  # }
  command_with_result(CORE_SET_VIEWPORT_SIZE, {target: driver, size: size})
end

#eyes_abort(eyes) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/applitools/universal_sdk/universal_client.rb', line 284

def eyes_abort(eyes)
  # interface AbortPayload {
  #   eyes: Ref<Eyes>
  #   settings?: CloseSettings
  # }
  #
  # type AbortResponsePayload = void
  settings = commands_config[:close]
  # CloseSettings
  #
  # {
  #   "updateBaselineIfNew": true,
  #   "updateBaselineIfDifferent": true
  # }
  command_with_result(EYES_ABORT, {eyes: eyes, settings: settings})
end

#eyes_check(eyes, settings, image_target = {}) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/applitools/universal_sdk/universal_client.rb', line 212

def eyes_check(eyes, settings, image_target = {})
  # interface CheckRequestPayload {
  #   eyes: Ref<Eyes>
  #   target?: ImageTarget | DriverTarget
  #   settings?: CheckSettings
  #   config?: Config
  # }
  #
  # type CheckResponsePayload = CheckResult[]
  payload = {eyes: eyes, settings: settings, config: commands_config}
  payload[:target] = image_target unless image_target.empty?
  command_with_result(EYES_CHECK, payload)
end

#eyes_close(eyes) ⇒ Object



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/applitools/universal_sdk/universal_client.rb', line 266

def eyes_close(eyes)
  # interface CloseResponsePayload {
  #   eyes: Ref<Eyes>
  #   settings?: CloseSettings
  #   config?: Config
  # }
  #
  # type CloseResponsePayload = void
  settings = commands_config[:close]
  # CloseSettings
  #
  # {
  #   "updateBaselineIfNew": true,
  #   "updateBaselineIfDifferent": true
  # }
  command_with_result(EYES_CLOSE, {eyes: eyes, settings: settings, config: commands_config})
end

#eyes_extract_text(eyes, regions, driver_target) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/applitools/universal_sdk/universal_client.rb', line 253

def eyes_extract_text(eyes, regions, driver_target)
  # interface ExtractTextRequestPayload {
  #   target?: ImageTarget | DriverTarget
  #   settings?: ExtractTextSettings | ExtractTextSettings[]
  #   config?: Config
  # }
  #
  # type ExtractTextResponsePayload = string[]
  payload = {target: driver_target, settings: regions, config: commands_config}
  payload.delete(:settings) if regions.empty?
  command_with_result(EYES_EXTRACT_TEXT, payload)
end

#eyes_extract_text_regions(eyes, settings, driver_target) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/applitools/universal_sdk/universal_client.rb', line 240

def eyes_extract_text_regions(eyes, settings, driver_target)
  # interface LocateTextRequestPayload {
  #   target?: ImageTarget | DriverTarget
  #   settings?: LocateTextSettings
  #   config?: Config
  # }
  #
  # type LocateTextResponsePayload = Record<string, {text: string, x: number, y: number, width: number, height: number}[]>
  payload = {target: driver_target, settings: settings, config: commands_config}
  payload.delete(:target) if driver_target.nil? || driver_target.empty?
  command_with_result(EYES_EXTRACT_TEXT_REGIONS, payload)
end

#eyes_get_results(eyes) ⇒ Object



201
202
203
204
205
206
207
208
209
210
# File 'lib/applitools/universal_sdk/universal_client.rb', line 201

def eyes_get_results(eyes)
  # interface GetEyesResultsPayload {
  #   eyes: Ref<Eyes>
  #   settings?: GetResultsSettings
  # }
  #
  # type GetEyesResultsResponsePayload = TestResult[]
  settings = {throwErr: false}
  command_with_result(EYES_GET_RESULTS, {eyes: eyes, settings: settings})
end

#eyes_locate(eyes, settings, driver_target) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/applitools/universal_sdk/universal_client.rb', line 226

def eyes_locate(eyes, settings, driver_target)
  # interface LocateRequestPayload {
  #   target?: ImageTarget | DriverTarget
  #   settings?: LocateSettings
  #   config?: Config
  # }
  #
  # interface LocateResponsePayload {
  #   [key: string]: Array<{x: number, y: number, width: number, height: number}>
  # }

  command_with_result(EYES_LOCATE, {target: driver_target, settings: settings, config: commands_config})
end

#eyes_manager_close_all_eyes(manager, remove_duplicate_tests) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/applitools/universal_sdk/universal_client.rb', line 176

def eyes_manager_close_all_eyes(manager, remove_duplicate_tests)
  # interface GetManagerResultsRequestPayload {
  #   manager: Ref<EyesManager>
  #   settings?: {throwErr?: boolean}
  # }
  #
  # interface GetManagerResultsResponsePayload {
  #   results: {
  #     error?: Error
  #     result?: TestResult
  #     renderer?: TType extends 'ufg' ? Renderer : never
  #     userTestId: string
  #   }[]
  #   passed: number
  #   unresolved: number
  #   failed: number
  #   exceptions: number
  #   mismatches: number
  #   missing: number
  #   matches: number
  # }
  settings = {throwErr: false, removeDuplicateTests: remove_duplicate_tests}
  command_with_result(EYES_MANAGER_CLOSE_ALL_EYES, {manager: manager, settings: settings})
end

#eyes_manager_make_eyes(manager, driver_config, config) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/applitools/universal_sdk/universal_client.rb', line 161

def eyes_manager_make_eyes(manager, driver_config, config)
  @open_config = config

  map_open_eyes_config_to_commands_config(config)
  # interface OpenEyesRequestPayload {
  #   manager: Ref<EyesManager>
  #   target?: DriverTarget
  #   settings?: OpenSettings
  #   config?: Config
  # }
  #
  # type OpenEyesResponsePayload = Ref<Eyes>
  command_with_result(EYES_MANAGER_MAKE_EYES, {manager: manager, target: driver_config, settings: commands_config[:open], config: commands_config})
end

#make_manager(eyes_manager_config) ⇒ Object



88
89
90
91
92
93
# File 'lib/applitools/universal_sdk/universal_client.rb', line 88

def make_manager(eyes_manager_config)
  Applitools::EyesLogger.logger.debug "EyesManager config: #{eyes_manager_config}"
  eyes_manager = core_make_manager(eyes_manager_config)
  Applitools::EyesLogger.logger.debug "EyesManager applitools-ref-id: #{eyes_manager[:"applitools-ref-id"]}"
  Applitools::UniversalEyesManager.new(eyes_manager, self)
end

#map_open_eyes_config_to_commands_config(config) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/applitools/universal_sdk/universal_client.rb', line 117

def map_open_eyes_config_to_commands_config(config)
  [
    :eyesServerUrl, :apiKey, :proxy, :connectionTimeout, :removeSession, :agentId, :appName, :testName, :displayName,
    :userTestId, :sessionType, :properties, :batch, :keepBatchOpen, :environmentName, :environment, :branchName,
    :parentBranchName, :baselineEnvName, :baselineBranchName, :compareWithParentBranch, :ignoreBaseline,
    :ignoreGitBranching, :saveDiffs, :abortIdleTestTimeout
  ].each do |k|
    config_mapping(config, commands_config[:open], k)
  end

  commands_config[:open][:keepBatchOpen] = config.delete(:dontCloseBatches) unless config[:dontCloseBatches].nil?

  [:hideCaret, :hideScrollbars, :disableBrowserFetching, :sendDom, :stitchMode,
   :layoutBreakpoints, :waitBeforeCapture].each do |k|
    config_mapping(config, commands_config[:check], k)
  end

  commands_config[:check][:environments] = config.delete(:browsersInfo) unless config[:browsersInfo].nil?

  unless config[:defaultMatchSettings].nil?
    if config[:defaultMatchSettings][:accessibilitySettings]
      commands_config[:check][:accessibilitySettings] = {}
      commands_config[:check][:accessibilitySettings][:level] = config[:defaultMatchSettings][:accessibilitySettings].delete(:level) unless config[:defaultMatchSettings][:accessibilitySettings][:level].nil?
      commands_config[:check][:accessibilitySettings][:version] = config[:defaultMatchSettings][:accessibilitySettings].delete(:guidelinesVersion) unless config[:defaultMatchSettings][:accessibilitySettings][:guidelinesVersion].nil?
      config[:defaultMatchSettings].delete(:accessibilitySettings) if config[:defaultMatchSettings][:accessibilitySettings].empty?
    end
    commands_config[:check][:ignoreCaret] = config[:defaultMatchSettings].delete(:ignoreCaret) unless config[:defaultMatchSettings][:ignoreCaret].nil?
    commands_config[:check][:matchLevel] = config[:defaultMatchSettings].delete(:matchLevel) unless config[:defaultMatchSettings][:matchLevel].nil?
    config.delete(:defaultMatchSettings) if config[:defaultMatchSettings].empty?
  end

  if commands_config[:check][:fully].nil?
    commands_config[:check][:fully] = config.delete(:forceFullPageScreenshot) unless config[:forceFullPageScreenshot].nil?
  end

  commands_config[:close][:updateBaselineIfNew] = config.delete(:saveNewTests) unless config[:saveNewTests].nil?
  commands_config[:close][:updateBaselineIfDifferent] = config.delete(:saveFailedTests) unless config[:saveFailedTests].nil?

  commands_config[:screenshot] = commands_config[:check]
end