Class: DotDiff::Snapshot

Inherits:
Object
  • Object
show all
Includes:
Image::Cropper
Defined in:
lib/dotdiff/snapshot.rb

Constant Summary collapse

IMAGE_EXT =
'png'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Image::Cropper

#crop_and_resave, #height, #load_image, #width

Constructor Details

#initialize(options = {}) ⇒ Snapshot

Returns a new instance of Snapshot.



9
10
11
12
13
14
15
16
17
# File 'lib/dotdiff/snapshot.rb', line 9

def initialize(options = {})
  opts = { rootdir: DotDiff.image_store_path }.merge(Hash(options))
  @base_filename = opts[:filename]
  @subdir = opts[:subdir].to_s
  @rootdir = opts[:rootdir].to_s
  @page = opts[:page]
  @fullscreen = opts[:fullscreen_file]
  @use_custom_screenshot = opts[:use_custom_screenshot]
end

Instance Attribute Details

#base_filename(with_extension = true) ⇒ Object (readonly)

Returns the value of attribute base_filename.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def base_filename
  @base_filename
end

#pageObject (readonly)

Returns the value of attribute page.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def page
  @page
end

#rootdirObject (readonly)

Returns the value of attribute rootdir.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def rootdir
  @rootdir
end

#subdirObject (readonly)

Returns the value of attribute subdir.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def subdir
  @subdir
end

#use_custom_screenshotObject (readonly)

Returns the value of attribute use_custom_screenshot.



5
6
7
# File 'lib/dotdiff/snapshot.rb', line 5

def use_custom_screenshot
  @use_custom_screenshot
end

Instance Method Details

#basefileObject



27
28
29
# File 'lib/dotdiff/snapshot.rb', line 27

def basefile
  File.join(rootdir, subdir.to_s, base_filename)
end

#capture_from_browser(hide_and_show = true, element_handler = ElementHandler.new(page)) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dotdiff/snapshot.rb', line 57

def capture_from_browser(hide_and_show = true, element_handler = ElementHandler.new(page))
  return fullscreen_file if use_custom_screenshot

  if hide_and_show
    element_handler.hide
    page.save_screenshot(fullscreen_file)
    element_handler.show
  else
    page.save_screenshot(fullscreen_file)
  end
end

#cropped_fileObject



23
24
25
# File 'lib/dotdiff/snapshot.rb', line 23

def cropped_file
  @cropped ||= File.join(Dir.tmpdir, subdir, "#{base_filename(false)}_cropped.#{IMAGE_EXT}")
end

#diff_fileObject



53
54
55
# File 'lib/dotdiff/snapshot.rb', line 53

def diff_file
  File.join(failure_path, "#{base_filename(false)}.diff.#{IMAGE_EXT}")
end

#failure_pathObject



45
46
47
# File 'lib/dotdiff/snapshot.rb', line 45

def failure_path
  File.join(DotDiff.failure_image_path.to_s, subdir)
end

#fullscreen_fileObject



19
20
21
# File 'lib/dotdiff/snapshot.rb', line 19

def fullscreen_file
  @fullscreen ||= File.join(Dir.tmpdir, subdir, base_filename)
end

#new_fileObject



49
50
51
# File 'lib/dotdiff/snapshot.rb', line 49

def new_file
  File.join(failure_path, "#{base_filename(false)}.new.#{IMAGE_EXT}" )
end

#resave_cropped_fileObject



69
70
71
# File 'lib/dotdiff/snapshot.rb', line 69

def resave_cropped_file
  resave_base_file(:cropped)
end

#resave_fullscreen_fileObject



73
74
75
# File 'lib/dotdiff/snapshot.rb', line 73

def resave_fullscreen_file
  resave_base_file(:fullscreen)
end