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

#initializeMatchWindowData

Returns a new instance of MatchWindowData.



77
78
79
80
81
82
83
# File 'lib/applitools/core/match_window_data.rb', line 77

def initialize
  @app_output = nil
  @ignored_regions = []
  @floating_regions = []
  @need_convert_ignored_regions_coordinates = false
  @need_convert_floating_regions_coordinates = false
end

Instance Attribute Details

#app_outputObject

Returns the value of attribute app_output.



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

def app_output
  @app_output
end

#ignore_mismatchObject

Returns the value of attribute ignore_mismatch.



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

def ignore_mismatch
  @ignore_mismatch
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#tagObject

Returns the value of attribute tag.



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

def tag
  @tag
end

#user_inputsObject

Returns the value of attribute user_inputs.



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

def user_inputs
  @user_inputs
end

Class Method Details

.convert_coordinates(region, screenshot) ⇒ Object



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

def convert_coordinates(region, screenshot)
  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



14
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/applitools/core/match_window_data.rb', line 14

def default_data
  {
    'IgnoreMismatch' => false,
    'MismatchWait' => 0,
    'Options' => {
      'Name' => nil,
      'UserInputs' => [],
      'ImageMatchSettings' => {
        'MatchLevel' => 'Strict',
        'SplitTopHeight' => 0,
        'SplitBottomHeight' => 0,
        'IgnoreCaret' => true,
        'IgnoreDisplacements' => false,
        'Ignore' => [],
        'Floating' => [],
        'Exact' => {
          'MinDiffIntensity' => 0,
          'MinDiffWidth' => 0,
          'MinDiffHeight' => 0,
          'MatchThreshold' => 0
        },
        'scale' => 0,
        'remainder' => 0,
        'EnablePatterns' => false,
        'UseDom' => false
      },
      'IgnoreExpectedOutputSettings' => false,
      'ForceMatch' => false,
      'ForceMismatch' => false,
      'IgnoreMatch' => false,
      'IgnoreMismatch' => false,
      'Trim' => {
        'Enabled' => false
      }
    },
    'Id' => nil,
    'UserInputs' => [],
    'AppOutput' => {
      'Screenshot64' => nil,
      'ScreenshotUrl' => nil,
      'Title' => nil,
      'IsPrimary' => false,
      'Elapsed' => 0,
      'Location' => {
        'X' => 0,
        'Y' => 0
      }
    },
    'Tag' => nil
  }
end

.valid_input(_i) ⇒ Object



70
71
72
# File 'lib/applitools/core/match_window_data.rb', line 70

def valid_input(_i)
  true
end

.valid_region(_r) ⇒ Object



66
67
68
# File 'lib/applitools/core/match_window_data.rb', line 66

def valid_region(_r)
  true
end

Instance Method Details

#convert_floating_regions_coordinatesObject



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/applitools/core/match_window_data.rb', line 265

def convert_floating_regions_coordinates
  return unless @need_convert_floating_regions_coordinates
  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]
    )
    updated_region.to_hash
    Applitools::FloatingRegion.new(
      updated_region.left,
      updated_region.top,
      r.width,
      r.height,
      r.max_left_offset,
      r.max_top_offset,
      r.max_right_offset,
      r.max_bottom_offset
    ).padding(r.current_padding)
  end  unless app_output.screenshot.nil?
  @need_convert_floating_regions_coordinates = false
end

#convert_ignored_regions_coordinatesObject



257
258
259
260
261
262
263
# File 'lib/applitools/core/match_window_data.rb', line 257

def convert_ignored_regions_coordinates
  return unless @need_convert_ignored_regions_coordinates
  self.ignored_regions = @ignored_regions.map do |r|
    self.class.convert_coordinates(r, app_output.screenshot)
  end unless app_output.screenshot.nil?
  @need_convert_ignored_regions_coordinates = false
end

#enable_patternsObject



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

def enable_patterns
  current_data['Options']['ImageMatchSettings']['EnablePatterns']
end

#enable_patterns=(value) ⇒ Object



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

def enable_patterns=(value)
  current_data['Options']['ImageMatchSettings']['EnablePatterns'] = value
end

#exactObject



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

def exact
  current_data['Options']['ImageMatchSettings']['Exact']
end

#exact=(value) ⇒ Object

Raises:

  • (Applitools::EyesError)


188
189
190
191
192
193
194
195
196
# File 'lib/applitools/core/match_window_data.rb', line 188

def exact=(value)
  raise Applitools::EyesError.new('You should pass a hash as a value!') unless value.nil? || value.is_a?(Hash)
  return current_data['Options']['ImageMatchSettings']['Exact'] = nil if value.nil?
  current_value = exact || {}
  %w(MinDiffIntensity MinDiffWidth MinDiffHeight MatchThreshold).each do |k|
    current_value[k] = value[k]
  end
  current_data['Options']['ImageMatchSettings']['Exact'] = current_value
end

#floating_regions=(value) ⇒ Object



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

def floating_regions=(value)
  Applitools::ArgumentGuard.is_a? value, 'value', Array
  value.each do |r|
    current_data['Options']['ImageMatchSettings']['Floating'] << r.to_hash
  end
end

#ignore_caret=(value) ⇒ Object



253
254
255
# File 'lib/applitools/core/match_window_data.rb', line 253

def ignore_caret=(value)
  current_data['Options']['ImageMatchSettings']['IgnoreCaret'] = value
end

#ignore_displacementsObject



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

def ignore_displacements
  current_data['Options']['ImageMatchSettings']['IgnoreDisplacements']
end

#ignore_displacements=(value) ⇒ Object



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

def ignore_displacements=(value)
  current_data['Options']['ImageMatchSettings']['IgnoreDisplacements'] = value
end

#ignored_regions=(value) ⇒ Object



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

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)
  end
end

#match_levelObject



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

def match_level
  current_data['Options']['ImageMatchSettings']['MatchLevel']
end

#match_level=(value) ⇒ Object



136
137
138
# File 'lib/applitools/core/match_window_data.rb', line 136

def match_level=(value)
  current_data['Options']['ImageMatchSettings']['MatchLevel'] = value
end

#read_target(target, driver) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/applitools/core/match_window_data.rb', line 198

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
    target.ignored_regions.each do |r|
      case r
      when Proc
        @ignored_regions << r.call(driver)
        @need_convert_ignored_regions_coordinates = true
      when Applitools::Region
        @ignored_regions << r
        @need_convert_ignored_regions_coordinates = true
      end
    end
  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
end

#remainderObject



156
157
158
# File 'lib/applitools/core/match_window_data.rb', line 156

def remainder
  current_data['Options']['ImageMatchSettings']['remainder']
end

#remainder=(value) ⇒ Object



152
153
154
# File 'lib/applitools/core/match_window_data.rb', line 152

def remainder=(value)
  current_data['Options']['ImageMatchSettings']['remainder'] = value
end

#scaleObject



148
149
150
# File 'lib/applitools/core/match_window_data.rb', line 148

def scale
  current_data['Options']['ImageMatchSettings']['scale']
end

#scale=(value) ⇒ Object



144
145
146
# File 'lib/applitools/core/match_window_data.rb', line 144

def scale=(value)
  current_data['Options']['ImageMatchSettings']['scale'] = value
end

#screenshotObject



85
86
87
88
# File 'lib/applitools/core/match_window_data.rb', line 85

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

#to_hashObject



288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/applitools/core/match_window_data.rb', line 288

def to_hash
  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
  current_data.dup
end

#to_sObject



303
304
305
# File 'lib/applitools/core/match_window_data.rb', line 303

def to_s
  to_hash
end

#trim=(value) ⇒ Object



249
250
251
# File 'lib/applitools/core/match_window_data.rb', line 249

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

#use_domObject



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

def use_dom
  current_data['Options']['ImageMatchSettings']['UseDom']
end

#use_dom=(value) ⇒ Object



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

def use_dom=(value)
  current_data['Options']['ImageMatchSettings']['UseDom'] = value
end