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



47
48
49
50
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 47

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

#debug_flag_access(&b) ⇒ Object



42
43
44
45
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 42

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

def save(image, suffix = '')
  return unless debug
  case image
  when ::ChunkyPNG::Image, Applitools::Screenshot
    image.save(file_name_to_save(suffix)) if image.area > 0
  when Applitools::EyesScreenshot
    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



27
28
29
30
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 27

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

#tag_access(&b) ⇒ Object



32
33
34
35
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 32

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

#tag_for_debugObject



37
38
39
40
# File 'lib/applitools/core/debug_screenshot_provider.rb', line 37

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