Class: Applitools::MatchWindowData

Inherits:
Object
  • Object
show all
Defined in:
lib/applitools/core/match_window_data.rb

Direct Known Subclasses

MatchSingleCheckData

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_image_match_settings = nil) ⇒ MatchWindowData

Returns a new instance of MatchWindowData.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/applitools/core/match_window_data.rb', line 62

def initialize(default_image_match_settings = nil)
  @app_output = nil
  @ignored_regions = []
  @floating_regions = []
  @need_convert_ignored_regions_coordinates = false
  @need_convert_floating_regions_coordinates = false
  @need_convert_strict_regions_coordinates = false
  @need_convert_content_regions_coordinates = false
  @need_convert_layout_regions_coordinates = false
  @need_convert_accessibility_regions_coordinates = false
  self.default_image_match_settings = default_image_match_settings.nil? ? Applitools::ImageMatchSettings.new : default_image_match_settings.deep_dup
end

Instance Attribute Details

#app_outputObject

Returns the value of attribute app_output.



60
61
62
# File 'lib/applitools/core/match_window_data.rb', line 60

def app_output
  @app_output
end

#default_image_match_settingsObject

Returns the value of attribute default_image_match_settings.



60
61
62
# File 'lib/applitools/core/match_window_data.rb', line 60

def default_image_match_settings
  @default_image_match_settings
end

#ignore_mismatchObject

Returns the value of attribute ignore_mismatch.



60
61
62
# File 'lib/applitools/core/match_window_data.rb', line 60

def ignore_mismatch
  @ignore_mismatch
end

#optionsObject

Returns the value of attribute options.



60
61
62
# File 'lib/applitools/core/match_window_data.rb', line 60

def options
  @options
end

#tagObject

Returns the value of attribute tag.



60
61
62
# File 'lib/applitools/core/match_window_data.rb', line 60

def tag
  @tag
end

#user_inputsObject

Returns the value of attribute user_inputs.



60
61
62
# File 'lib/applitools/core/match_window_data.rb', line 60

def user_inputs
  @user_inputs
end

Class Method Details

.convert_coordinates(region, screenshot) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/applitools/core/match_window_data.rb', line 6

def convert_coordinates(region, screenshot)
  return region.with_padding.to_hash if region.respond_to?(:converted?) && region.converted?
  screenshot.convert_region_location(
    region.with_padding,
    Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative],
    Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
  ).to_hash
end

.default_dataObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/applitools/core/match_window_data.rb', line 15

def default_data
  {
    'IgnoreMismatch' => false,
    'MismatchWait' => 0,
    'Options' => {
      'Name' => nil,
      'UserInputs' => [],
      'IgnoreExpectedOutputSettings' => false,
      'ForceMatch' => false,
      'ForceMismatch' => false,
      'IgnoreMatch' => false,
      'IgnoreMismatch' => false,
      'ReplaceLast' => false,
      'Trim' => {
        'Enabled' => false
      },
      'RenderId' => ''
    },
    'Id' => nil,
    'UserInputs' => [],
    'AppOutput' => {
      'Screenshot64' => nil,
      'ScreenshotUrl' => nil,
      'Title' => nil,
      'IsPrimary' => false,
      'Elapsed' => 0,
      'Location' => {
        'X' => 0,
        'Y' => 0
      }
    },
    'Tag' => nil,
    'RenderId' => ''
  }
end

.valid_input(_i) ⇒ Object



55
56
57
# File 'lib/applitools/core/match_window_data.rb', line 55

def valid_input(_i)
  true
end

.valid_region(_r) ⇒ Object



51
52
53
# File 'lib/applitools/core/match_window_data.rb', line 51

def valid_region(_r)
  true
end

Instance Method Details

#accessibility_regions=(value) ⇒ Object



137
138
139
140
141
142
# File 'lib/applitools/core/match_window_data.rb', line 137

def accessibility_regions=(value)
  Applitools::ArgumentGuard.is_a? value, 'value', Array
  value.each do |r|
    default_image_match_settings.accessibility << r.to_hash if self.class.valid_region(r)
  end
end

#accessibility_validationObject



342
343
344
# File 'lib/applitools/core/match_window_data.rb', line 342

def accessibility_validation
  default_image_match_settings.accessibility_level
end

#accessibility_validation=(value) ⇒ Object



346
347
348
# File 'lib/applitools/core/match_window_data.rb', line 346

def accessibility_validation=(value)
  default_image_match_settings.accessibility_level = value
end

#content_regions=(value) ⇒ Object



130
131
132
133
134
135
# File 'lib/applitools/core/match_window_data.rb', line 130

def content_regions=(value)
  Applitools::ArgumentGuard.is_a? value, 'value', Array
  value.each do |r|
    default_image_match_settings.content << r.to_hash if self.class.valid_region(r)
  end
end

#convert_accessibility_regions_coordinatesObject



374
375
376
377
378
# File 'lib/applitools/core/match_window_data.rb', line 374

def convert_accessibility_regions_coordinates
  return unless @need_convert_accessibility_regions_coordinates
  self.accessibility_regions = convert_regions_coordinates(@accessibility_regions)
  @need_convert_accessibility_regions_coordinates = false
end

#convert_content_regions_coordinatesObject



368
369
370
371
372
# File 'lib/applitools/core/match_window_data.rb', line 368

def convert_content_regions_coordinates
  return unless @need_convert_content_regions_coordinates
  self.content_regions = convert_regions_coordinates(@content_regions)
  @need_convert_content_regions_coordinates = false
end

#convert_floating_regions_coordinatesObject



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/applitools/core/match_window_data.rb', line 384

def convert_floating_regions_coordinates
  return unless @need_convert_floating_regions_coordinates
  unless app_output.screenshot.nil?
    self.floating_regions = @floating_regions.map do |r|
      updated_region = app_output.screenshot.convert_region_location(
        r,
        Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative],
        Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
      )

      Applitools::FloatingRegion.new(
        updated_region.left,
        updated_region.top,
        updated_region.width,
        updated_region.height,
        r.max_left_offset,
        r.max_top_offset,
        r.max_right_offset,
        r.max_bottom_offset
      ).padding(r.current_padding)
    end
  end
  @need_convert_floating_regions_coordinates = false
end

#convert_ignored_regions_coordinatesObject



350
351
352
353
354
# File 'lib/applitools/core/match_window_data.rb', line 350

def convert_ignored_regions_coordinates
  return unless @need_convert_ignored_regions_coordinates
  self.ignored_regions = convert_regions_coordinates(@ignored_regions)
  @need_convert_ignored_regions_coordinates = false
end

#convert_layout_regions_coordinatesObject



356
357
358
359
360
# File 'lib/applitools/core/match_window_data.rb', line 356

def convert_layout_regions_coordinates
  return unless @need_convert_layout_regions_coordinates
  self.layout_regions = convert_regions_coordinates(@layout_regions)
  @need_convert_layout_regions_coordinates = false
end

#convert_regions_coordinates(regions) ⇒ Object



380
381
382
# File 'lib/applitools/core/match_window_data.rb', line 380

def convert_regions_coordinates(regions)
  regions.dup.map { |r| self.class.convert_coordinates(r, app_output.screenshot) } unless app_output.screenshot.nil?
end

#convert_strict_regions_coordinatesObject



362
363
364
365
366
# File 'lib/applitools/core/match_window_data.rb', line 362

def convert_strict_regions_coordinates
  return unless @need_convert_strict_regions_coordinates
  self.strict_regions = convert_regions_coordinates(@strict_regions)
  @need_convert_strict_regions_coordinates = false
end

#enable_patternsObject



195
196
197
# File 'lib/applitools/core/match_window_data.rb', line 195

def enable_patterns
  default_image_match_settings.enable_patterns
end

#enable_patterns=(value) ⇒ Object



199
200
201
# File 'lib/applitools/core/match_window_data.rb', line 199

def enable_patterns=(value)
  default_image_match_settings.enable_patterns = value
end

#exactObject



183
184
185
# File 'lib/applitools/core/match_window_data.rb', line 183

def exact
  default_image_match_settings.exact
end

#exact=(value) ⇒ Object



220
221
222
223
# File 'lib/applitools/core/match_window_data.rb', line 220

def exact=(value)
  Applitools::ArgumentGuard.is_a?(value, 'value', Applitools::ImageMatchSettings::Exact)
  default_image_match_settings.exact = value
end

#floating_regions=(value) ⇒ Object



109
110
111
112
113
114
# File 'lib/applitools/core/match_window_data.rb', line 109

def floating_regions=(value)
  Applitools::ArgumentGuard.is_a? value, 'value', Array
  value.each do |r|
    default_image_match_settings.floating << r.to_hash
  end
end

#ignore_caret=(value) ⇒ Object



338
339
340
# File 'lib/applitools/core/match_window_data.rb', line 338

def ignore_caret=(value)
  default_image_match_settings.ignore_caret = value
end

#ignore_displacementsObject



203
204
205
# File 'lib/applitools/core/match_window_data.rb', line 203

def ignore_displacements
  default_image_match_settings.ignore_displacements
end

#ignore_displacements=(value) ⇒ Object



207
208
209
# File 'lib/applitools/core/match_window_data.rb', line 207

def ignore_displacements=(value)
  default_image_match_settings.ignore_displacements = value
end

#ignored_regions=(value) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/applitools/core/match_window_data.rb', line 101

def ignored_regions=(value)
  Applitools::ArgumentGuard.is_a? value, 'value', Array
  value.each do |r|
    # current_data['Options']['ImageMatchSettings']['Ignore'] << r.to_hash if self.class.valid_region(r)
    default_image_match_settings.ignore << r.to_hash if self.class.valid_region(r)
  end
end

#layout_regions=(value) ⇒ Object



116
117
118
119
120
121
# File 'lib/applitools/core/match_window_data.rb', line 116

def layout_regions=(value)
  Applitools::ArgumentGuard.is_a? value, 'value', Array
  value.each do |r|
    default_image_match_settings.layout << r.to_hash if self.class.valid_region(r)
  end
end

#match_levelObject



163
164
165
# File 'lib/applitools/core/match_window_data.rb', line 163

def match_level
  default_image_match_settings.match_level
end

#match_level=(value) ⇒ Object



159
160
161
# File 'lib/applitools/core/match_window_data.rb', line 159

def match_level=(value)
  default_image_match_settings.match_level = value
end

#obtain_accessibility_regions_coordinates(regions, driver) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/applitools/core/match_window_data.rb', line 278

def obtain_accessibility_regions_coordinates(regions, driver)
  result = []
  regions.each do |r|
    case r
    when Proc
      region_or_regions = r.call(driver)
      case region_or_regions
      when Array
        result.concat(region_or_regions)
      when Applitools::AccessibilityRegion
        result << region_or_regions
      end
    else
      raise Applitools::EyesError, 'Error getting accessibility_regions coordinates'
    end
  end
  result
end

#obtain_regions_coordinates(regions, driver) ⇒ Object



297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/applitools/core/match_window_data.rb', line 297

def obtain_regions_coordinates(regions, driver)
  result = []
  regions.each do |r|
    case r
    when Proc
      region = r.call(driver)
      result << Applitools::Region.from_location_size(region.location, region.size)
    when Applitools::Region
      result << r
    end
  end
  result
end

#read_target(target, driver) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/applitools/core/match_window_data.rb', line 225

def read_target(target, driver)
  # options
  target_options_to_read.each do |field|
    a_value = target.options[field.to_sym]
    send("#{field}=", a_value) unless a_value.nil?
  end
  # ignored regions
  if target.respond_to? :ignored_regions
    @ignored_regions = obtain_regions_coordinates(target.ignored_regions, driver)
    @need_convert_ignored_regions_coordinates = true unless @ignored_regions.empty?
  end

  # floating regions
  return unless target.respond_to? :floating_regions
  target.floating_regions.each do |r|
    case r
    when Proc
      region = r.call(driver)
      raise Applitools::EyesError.new "Wrong floating region: #{region.class}" unless
          region.is_a? Applitools::FloatingRegion
      @floating_regions << region
      @need_convert_floating_regions_coordinates = true
    when Applitools::FloatingRegion
      @floating_regions << r
      @need_convert_floating_regions_coordinates = true
    end
  end

  # Layout regions
  if target.respond_to? :layout_regions
    @layout_regions = obtain_regions_coordinates(target.layout_regions, driver)
    @need_convert_layout_regions_coordinates = true unless @layout_regions.empty?
  end

  # Strict regions
  if target.respond_to? :strict_regions
    @strict_regions = obtain_regions_coordinates(target.strict_regions, driver)
    @need_convert_strict_regions_coordinates = true unless @strict_regions.empty?
  end

  # Content regions
  if target.respond_to? :content_regions
    @content_regions = obtain_regions_coordinates(target.content_regions, driver)
    @need_convert_content_regions_coordinates = true unless @content_regions.empty?
  end

  if target.respond_to? :accessibility_regions
    @accessibility_regions = obtain_accessibility_regions_coordinates(target.accessibility_regions, driver)
    @need_convert_accessibility_regions_coordinates = true unless @accessibility_regions.empty?
  end
  target
end

#remainderObject



179
180
181
# File 'lib/applitools/core/match_window_data.rb', line 179

def remainder
  default_image_match_settings.remainder
end

#remainder=(value) ⇒ Object



175
176
177
# File 'lib/applitools/core/match_window_data.rb', line 175

def remainder=(value)
  default_image_match_settings.remainder = value
end

#render_idObject



211
212
213
# File 'lib/applitools/core/match_window_data.rb', line 211

def render_id
  current_data['Options']['RenderId']
end

#render_id=(value) ⇒ Object



215
216
217
218
# File 'lib/applitools/core/match_window_data.rb', line 215

def render_id=(value)
  current_data['Options']['RenderId'] = value
  current_data['RenderId'] = value
end

#replace_lastObject



321
322
323
# File 'lib/applitools/core/match_window_data.rb', line 321

def replace_last
  current_data['Options']['ReplaceLast']
end

#replace_last=(value) ⇒ Object



325
326
327
328
# File 'lib/applitools/core/match_window_data.rb', line 325

def replace_last=(value)
  Applitools::ArgumentGuard.one_of?(value, 'value', [TrueClass, FalseClass])
  current_data['Options']['ReplaceLast'] = value
end

#scaleObject



171
172
173
# File 'lib/applitools/core/match_window_data.rb', line 171

def scale
  default_image_match_settings.scale
end

#scale=(value) ⇒ Object



167
168
169
# File 'lib/applitools/core/match_window_data.rb', line 167

def scale=(value)
  default_image_match_settings.scale = value
end

#screenshotObject



75
76
77
78
# File 'lib/applitools/core/match_window_data.rb', line 75

def screenshot
  return '' unless app_output.screenshot.respond_to?(:image)
  app_output.screenshot.image.to_blob
end

#strict_regions=(value) ⇒ Object



123
124
125
126
127
128
# File 'lib/applitools/core/match_window_data.rb', line 123

def strict_regions=(value)
  Applitools::ArgumentGuard.is_a? value, 'value', Array
  value.each do |r|
    default_image_match_settings.strict << r.to_hash if self.class.valid_region(r)
  end
end

#to_hashObject



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/applitools/core/match_window_data.rb', line 409

def to_hash
  if @need_convert_accessibility_regions_coordinates
    raise Applitools::EyesError.new(
      'You should convert coordinates for content_regions!'
    )
  end

  if @need_convert_content_regions_coordinates
    raise Applitools::EyesError.new(
      'You should convert coordinates for content_regions!'
    )
  end

  if @need_convert_strict_regions_coordinates
    raise Applitools::EyesError.new(
      'You should convert coordinates for strict_regions!'
    )
  end

  if @need_convert_layout_regions_coordinates
    raise Applitools::EyesError.new(
      'You should convert coordinates for layout_regions!'
    )
  end

  if @need_convert_ignored_regions_coordinates
    raise Applitools::EyesError.new(
      'You should convert coordinates for ignored_regions!'
    )
  end

  if @need_convert_floating_regions_coordinates
    raise Applitools::EyesError.new(
      'You should convert coordinates for floating_regions!'
    )
  end
  result = current_data.dup
  result['Options']['ImageMatchSettings'] = default_image_match_settings.json_data
  result
end

#to_sObject



450
451
452
# File 'lib/applitools/core/match_window_data.rb', line 450

def to_s
  to_hash
end

#trim=(value) ⇒ Object



334
335
336
# File 'lib/applitools/core/match_window_data.rb', line 334

def trim=(value)
  current_data['Options']['Trim']['Enabled'] = value ? true : false
end

#use_domObject



187
188
189
# File 'lib/applitools/core/match_window_data.rb', line 187

def use_dom
  default_image_match_settings.use_dom
end

#use_dom=(value) ⇒ Object



191
192
193
# File 'lib/applitools/core/match_window_data.rb', line 191

def use_dom=(value)
  default_image_match_settings.use_dom = value
end

#variation_group_id=(value) ⇒ Object



90
91
92
# File 'lib/applitools/core/match_window_data.rb', line 90

def variation_group_id=(value)
  current_data['Options']['variantId'] = value
end