Class: Applitools::DebugScreenshotProvider

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { screenshot_dir: 'debug_screenshots' }) ⇒ DebugScreenshotProvider

Returns a new instance of DebugScreenshotProvider.



9
10
11
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 9

def initialize(options = { screenshot_dir: 'debug_screenshots' })
  @screenshot_dir = options[:screenshot_dir]
end

Instance Attribute Details

#debug_flag_getterObject (readonly)

Returns the value of attribute debug_flag_getter.



7
8
9
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 7

def debug_flag_getter
  @debug_flag_getter
end

#debug_tag_getterObject (readonly)

Returns the value of attribute debug_tag_getter.



7
8
9
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 7

def debug_tag_getter
  @debug_tag_getter
end

#screenshot_dirObject

Returns the value of attribute screenshot_dir.



8
9
10
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 8

def screenshot_dir
  @screenshot_dir
end

Instance Method Details

#debugObject



49
50
51
52
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 49

def debug
  return debug_flag_getter.call if debug_flag_getter.is_a? Proc
  false
end

#debug_flag_access(&b) ⇒ Object



44
45
46
47
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 44

def debug_flag_access(&b)
  @debug_flag_getter = b
  self
end

#save(image, suffix = '') ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 13

def save(image, suffix = '')
  return unless debug
  case image
  when Applitools::Screenshot
    image.save(file_name_to_save(suffix)) if image.area > 0
  # EyesScreenshot class has been removed
  # when responding to :image method, try to save the image
  when -> (img) { img.respond_to?(:image) && img.image.respond_to?(:area) && img.image.respond_to?(:save) }
    image.image.save(file_name_to_save(suffix)) if image.image.area > 0
  # when String
  #   ::ChunkyPNG::Image.from_string(image).save(file_name_to_save(suffix))
  else
    return
  end
end

#save_subscreenshot(image, region) ⇒ Object



29
30
31
32
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 29

def save_subscreenshot(image, region)
  suffix = region.to_s + '__cropped'
  save(image, suffix)
end

#tag_access(&b) ⇒ Object



34
35
36
37
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 34

def tag_access(&b)
  @debug_tag_getter = b
  self
end

#tag_for_debugObject



39
40
41
42
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 39

def tag_for_debug
  return debug_tag_getter.call || '' if debug_tag_getter.is_a? Proc
  :''
end