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.



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

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

Instance Attribute Details

#app_outputObject

Returns the value of attribute app_output.



63
64
65
# File 'lib/applitools/core/match_window_data.rb', line 63

def app_output
  @app_output
end

#ignore_mismatchObject

Returns the value of attribute ignore_mismatch.



63
64
65
# File 'lib/applitools/core/match_window_data.rb', line 63

def ignore_mismatch
  @ignore_mismatch
end

#optionsObject

Returns the value of attribute options.



63
64
65
# File 'lib/applitools/core/match_window_data.rb', line 63

def options
  @options
end

#tagObject

Returns the value of attribute tag.



63
64
65
# File 'lib/applitools/core/match_window_data.rb', line 63

def tag
  @tag
end

#user_inputsObject

Returns the value of attribute user_inputs.



63
64
65
# File 'lib/applitools/core/match_window_data.rb', line 63

def user_inputs
  @user_inputs
end

Class Method Details

.convert_coordinates(region, screenshot) ⇒ Object



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

def convert_coordinates(region, screenshot)
  screenshot.convert_region_location(
    Applitools::Region.from_location_size(region.location, region.size),
    Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative],
    Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is]
  ).to_hash
end

.default_dataObject



12
13
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
# File 'lib/applitools/core/match_window_data.rb', line 12

def default_data
  {
    'IgnoreMismatch' => false,
    'MismatchWait' => 0,
    'Options' => {
      'Name' => nil,
      'UserInputs' => [],
      'ImageMatchSettings' => {
        'MatchLevel' => 'None',
        'SplitTopHeight' => 0,
        'SplitBottomHeight' => 0,
        'IgnoreCaret' => false,
        'Ignore' => [],
        'Exact' => {
          'MinDiffIntensity' => 0,
          'MinDiffWidth' => 0,
          'MinDiffHeight' => 0,
          'MatchThreshold' => 0
        }
      },
      '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
    },
    'Tag' => nil
  }
end

.valid_input(_i) ⇒ Object



58
59
60
# File 'lib/applitools/core/match_window_data.rb', line 58

def valid_input(_i)
  true
end

.valid_region(_r) ⇒ Object



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

def valid_region(_r)
  true
end

Instance Method Details

#convert_ignored_regions_coordinatesObject



148
149
150
151
152
153
154
# File 'lib/applitools/core/match_window_data.rb', line 148

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
  @need_convert_ignored_regions_coordinates = false
end

#ignored_regions=(value) ⇒ Object



93
94
95
96
97
98
# File 'lib/applitools/core/match_window_data.rb', line 93

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



113
114
115
# File 'lib/applitools/core/match_window_data.rb', line 113

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

#match_level=(value) ⇒ Object



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

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

#read_target(target, driver) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/applitools/core/match_window_data.rb', line 117

def read_target(target, driver)
  # options
  %w(trim).each do |field|
    send("#{field}=", target.options[field.to_sym])
  end
  # ignored regions
  target.ignored_regions.each do |r|
    case r
    when Proc
      region = r.call(driver)
      @ignored_regions << Applitools::Region.from_location_size(region.location, region.size)
      @need_convert_ignored_regions_coordinates = true
    when Applitools::Region
      @ignored_regions << r
      @need_convert_ignored_regions_coordinates = true
    end
  end
end

#screenshotObject



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

def screenshot
  app_output.screenshot.image.to_blob
end

#to_hashObject

Raises:

  • (Applitools::EyesError)


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

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

#to_sObject



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

def to_s
  to_hash
end

#trim=(value) ⇒ Object



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

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