Class: Applitools::MatchWindowData
- Inherits:
-
Object
- Object
- Applitools::MatchWindowData
- Defined in:
- lib/applitools/core/match_window_data.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#app_output ⇒ Object
Returns the value of attribute app_output.
-
#ignore_mismatch ⇒ Object
Returns the value of attribute ignore_mismatch.
-
#options ⇒ Object
Returns the value of attribute options.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#user_inputs ⇒ Object
Returns the value of attribute user_inputs.
Class Method Summary collapse
- .convert_coordinates(region, screenshot) ⇒ Object
- .default_data ⇒ Object
- .valid_input(_i) ⇒ Object
- .valid_region(_r) ⇒ Object
Instance Method Summary collapse
- #accessibility_regions=(value) ⇒ Object
- #accessibility_validation ⇒ Object
- #accessibility_validation=(value) ⇒ Object
- #content_regions=(value) ⇒ Object
- #convert_accessibility_regions_coordinates ⇒ Object
- #convert_content_regions_coordinates ⇒ Object
- #convert_floating_regions_coordinates ⇒ Object
- #convert_ignored_regions_coordinates ⇒ Object
- #convert_layout_regions_coordinates ⇒ Object
- #convert_regions_coordinates(regions) ⇒ Object
- #convert_strict_regions_coordinates ⇒ Object
- #enable_patterns ⇒ Object
- #enable_patterns=(value) ⇒ Object
- #exact ⇒ Object
- #exact=(value) ⇒ Object
- #floating_regions=(value) ⇒ Object
- #ignore_caret=(value) ⇒ Object
- #ignore_displacements ⇒ Object
- #ignore_displacements=(value) ⇒ Object
- #ignored_regions=(value) ⇒ Object
-
#initialize ⇒ MatchWindowData
constructor
A new instance of MatchWindowData.
- #layout_regions=(value) ⇒ Object
- #match_level ⇒ Object
- #match_level=(value) ⇒ Object
- #obtain_accessibility_regions_coordinates(regions, driver) ⇒ Object
- #obtain_regions_coordinates(regions, driver) ⇒ Object
- #read_target(target, driver) ⇒ Object
- #remainder ⇒ Object
- #remainder=(value) ⇒ Object
- #render_id ⇒ Object
- #render_id=(value) ⇒ Object
- #scale ⇒ Object
- #scale=(value) ⇒ Object
- #screenshot ⇒ Object
- #strict_regions=(value) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #trim=(value) ⇒ Object
- #use_dom ⇒ Object
- #use_dom=(value) ⇒ Object
Constructor Details
#initialize ⇒ MatchWindowData
Returns a new instance of MatchWindowData.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/applitools/core/match_window_data.rb', line 84 def initialize @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 end |
Instance Attribute Details
#app_output ⇒ Object
Returns the value of attribute app_output.
82 83 84 |
# File 'lib/applitools/core/match_window_data.rb', line 82 def app_output @app_output end |
#ignore_mismatch ⇒ Object
Returns the value of attribute ignore_mismatch.
82 83 84 |
# File 'lib/applitools/core/match_window_data.rb', line 82 def ignore_mismatch @ignore_mismatch end |
#options ⇒ Object
Returns the value of attribute options.
82 83 84 |
# File 'lib/applitools/core/match_window_data.rb', line 82 def @options end |
#tag ⇒ Object
Returns the value of attribute tag.
82 83 84 |
# File 'lib/applitools/core/match_window_data.rb', line 82 def tag @tag end |
#user_inputs ⇒ Object
Returns the value of attribute user_inputs.
82 83 84 |
# File 'lib/applitools/core/match_window_data.rb', line 82 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_data ⇒ Object
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 65 66 67 68 69 70 71 |
# File 'lib/applitools/core/match_window_data.rb', line 14 def default_data { 'IgnoreMismatch' => false, 'MismatchWait' => 0, 'Options' => { 'Name' => nil, 'UserInputs' => [], 'ImageMatchSettings' => { 'accessibilityLevel' => 'None', 'MatchLevel' => 'Strict', 'SplitTopHeight' => 0, 'SplitBottomHeight' => 0, 'IgnoreCaret' => true, 'IgnoreDisplacements' => false, 'Accessibility' => [], 'Ignore' => [], 'Floating' => [], 'Layout' => [], 'Strict' => [], 'Content' => [], '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 }, '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
77 78 79 |
# File 'lib/applitools/core/match_window_data.rb', line 77 def valid_input(_i) true end |
.valid_region(_r) ⇒ Object
73 74 75 |
# File 'lib/applitools/core/match_window_data.rb', line 73 def valid_region(_r) true end |
Instance Method Details
#accessibility_regions=(value) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/applitools/core/match_window_data.rb', line 153 def accessibility_regions=(value) Applitools::ArgumentGuard.is_a? value, 'value', Array value.each do |r| current_data['Options']['ImageMatchSettings']['Accessibility'] << r.to_hash if self.class.valid_region(r) end end |
#accessibility_validation ⇒ Object
354 355 356 |
# File 'lib/applitools/core/match_window_data.rb', line 354 def accessibility_validation current_data['Options']['ImageMatchSettings']['AccessibilityLevel'] end |
#accessibility_validation=(value) ⇒ Object
358 359 360 |
# File 'lib/applitools/core/match_window_data.rb', line 358 def accessibility_validation=(value) current_data['Options']['ImageMatchSettings']['AccessibilityLevel'] = value end |
#content_regions=(value) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/applitools/core/match_window_data.rb', line 146 def content_regions=(value) Applitools::ArgumentGuard.is_a? value, 'value', Array value.each do |r| current_data['Options']['ImageMatchSettings']['Content'] << r.to_hash if self.class.valid_region(r) end end |
#convert_accessibility_regions_coordinates ⇒ Object
389 390 391 392 393 |
# File 'lib/applitools/core/match_window_data.rb', line 389 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_coordinates ⇒ Object
383 384 385 386 387 |
# File 'lib/applitools/core/match_window_data.rb', line 383 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_coordinates ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/applitools/core/match_window_data.rb', line 399 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] ) 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 end @need_convert_floating_regions_coordinates = false end |
#convert_ignored_regions_coordinates ⇒ Object
362 363 364 365 366 367 368 369 |
# File 'lib/applitools/core/match_window_data.rb', line 362 def convert_ignored_regions_coordinates return unless @need_convert_ignored_regions_coordinates self.ignored_regions = convert_regions_coordinates(@ignored_regions) # 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 |
#convert_layout_regions_coordinates ⇒ Object
371 372 373 374 375 |
# File 'lib/applitools/core/match_window_data.rb', line 371 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
395 396 397 |
# File 'lib/applitools/core/match_window_data.rb', line 395 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_coordinates ⇒ Object
377 378 379 380 381 |
# File 'lib/applitools/core/match_window_data.rb', line 377 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_patterns ⇒ Object
211 212 213 |
# File 'lib/applitools/core/match_window_data.rb', line 211 def enable_patterns current_data['Options']['ImageMatchSettings']['EnablePatterns'] end |
#enable_patterns=(value) ⇒ Object
215 216 217 |
# File 'lib/applitools/core/match_window_data.rb', line 215 def enable_patterns=(value) current_data['Options']['ImageMatchSettings']['EnablePatterns'] = value end |
#exact ⇒ Object
199 200 201 |
# File 'lib/applitools/core/match_window_data.rb', line 199 def exact current_data['Options']['ImageMatchSettings']['Exact'] end |
#exact=(value) ⇒ Object
236 237 238 239 240 241 242 243 244 |
# File 'lib/applitools/core/match_window_data.rb', line 236 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
125 126 127 128 129 130 |
# File 'lib/applitools/core/match_window_data.rb', line 125 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
350 351 352 |
# File 'lib/applitools/core/match_window_data.rb', line 350 def ignore_caret=(value) current_data['Options']['ImageMatchSettings']['IgnoreCaret'] = value end |
#ignore_displacements ⇒ Object
219 220 221 |
# File 'lib/applitools/core/match_window_data.rb', line 219 def ignore_displacements current_data['Options']['ImageMatchSettings']['IgnoreDisplacements'] end |
#ignore_displacements=(value) ⇒ Object
223 224 225 |
# File 'lib/applitools/core/match_window_data.rb', line 223 def ignore_displacements=(value) current_data['Options']['ImageMatchSettings']['IgnoreDisplacements'] = value end |
#ignored_regions=(value) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/applitools/core/match_window_data.rb', line 118 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 |
#layout_regions=(value) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/applitools/core/match_window_data.rb', line 132 def layout_regions=(value) Applitools::ArgumentGuard.is_a? value, 'value', Array value.each do |r| current_data['Options']['ImageMatchSettings']['Layout'] << r.to_hash if self.class.valid_region(r) end end |
#match_level ⇒ Object
179 180 181 |
# File 'lib/applitools/core/match_window_data.rb', line 179 def match_level current_data['Options']['ImageMatchSettings']['MatchLevel'] end |
#match_level=(value) ⇒ Object
175 176 177 |
# File 'lib/applitools/core/match_window_data.rb', line 175 def match_level=(value) current_data['Options']['ImageMatchSettings']['MatchLevel'] = value end |
#obtain_accessibility_regions_coordinates(regions, driver) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/applitools/core/match_window_data.rb', line 299 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
318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/applitools/core/match_window_data.rb', line 318 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
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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/applitools/core/match_window_data.rb', line 246 def read_target(target, driver) # options .each do |field| a_value = target.[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 |
#remainder ⇒ Object
195 196 197 |
# File 'lib/applitools/core/match_window_data.rb', line 195 def remainder current_data['Options']['ImageMatchSettings']['remainder'] end |
#remainder=(value) ⇒ Object
191 192 193 |
# File 'lib/applitools/core/match_window_data.rb', line 191 def remainder=(value) current_data['Options']['ImageMatchSettings']['remainder'] = value end |
#render_id ⇒ Object
227 228 229 |
# File 'lib/applitools/core/match_window_data.rb', line 227 def render_id current_data['Options']['RenderId'] end |
#render_id=(value) ⇒ Object
231 232 233 234 |
# File 'lib/applitools/core/match_window_data.rb', line 231 def render_id=(value) current_data['Options']['RenderId'] = value current_data['RenderId'] = value end |
#scale ⇒ Object
187 188 189 |
# File 'lib/applitools/core/match_window_data.rb', line 187 def scale current_data['Options']['ImageMatchSettings']['scale'] end |
#scale=(value) ⇒ Object
183 184 185 |
# File 'lib/applitools/core/match_window_data.rb', line 183 def scale=(value) current_data['Options']['ImageMatchSettings']['scale'] = value end |
#screenshot ⇒ Object
96 97 98 99 |
# File 'lib/applitools/core/match_window_data.rb', line 96 def screenshot return '' unless app_output.screenshot.respond_to?(:image) app_output.screenshot.image.to_blob end |
#strict_regions=(value) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/applitools/core/match_window_data.rb', line 139 def strict_regions=(value) Applitools::ArgumentGuard.is_a? value, 'value', Array value.each do |r| current_data['Options']['ImageMatchSettings']['Strict'] << r.to_hash if self.class.valid_region(r) end end |
#to_hash ⇒ Object
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 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/applitools/core/match_window_data.rb', line 424 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 current_data.dup end |
#to_s ⇒ Object
463 464 465 |
# File 'lib/applitools/core/match_window_data.rb', line 463 def to_s to_hash end |
#trim=(value) ⇒ Object
346 347 348 |
# File 'lib/applitools/core/match_window_data.rb', line 346 def trim=(value) current_data['Options']['Trim']['Enabled'] = value ? true : false end |
#use_dom ⇒ Object
203 204 205 |
# File 'lib/applitools/core/match_window_data.rb', line 203 def use_dom current_data['Options']['ImageMatchSettings']['UseDom'] end |
#use_dom=(value) ⇒ Object
207 208 209 |
# File 'lib/applitools/core/match_window_data.rb', line 207 def use_dom=(value) current_data['Options']['ImageMatchSettings']['UseDom'] = value end |