Class: DotDiff::Snapshot
Constant Summary
collapse
- IMAGE_EXT =
'png'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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
Returns the value of attribute base_filename.
5
6
7
|
# File 'lib/dotdiff/snapshot.rb', line 5
def base_filename
@base_filename
end
|
#page ⇒ Object
Returns the value of attribute page.
5
6
7
|
# File 'lib/dotdiff/snapshot.rb', line 5
def page
@page
end
|
#rootdir ⇒ Object
Returns the value of attribute rootdir.
5
6
7
|
# File 'lib/dotdiff/snapshot.rb', line 5
def rootdir
@rootdir
end
|
#subdir ⇒ Object
Returns the value of attribute subdir.
5
6
7
|
# File 'lib/dotdiff/snapshot.rb', line 5
def subdir
@subdir
end
|
#use_custom_screenshot ⇒ Object
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
#basefile ⇒ Object
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_file ⇒ Object
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_file ⇒ Object
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_path ⇒ Object
45
46
47
|
# File 'lib/dotdiff/snapshot.rb', line 45
def failure_path
File.join(DotDiff.failure_image_path.to_s, subdir)
end
|
#fullscreen_file ⇒ Object
19
20
21
|
# File 'lib/dotdiff/snapshot.rb', line 19
def fullscreen_file
@fullscreen ||= File.join(Dir.tmpdir, subdir, base_filename)
end
|
#new_file ⇒ Object
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_file ⇒ Object
69
70
71
|
# File 'lib/dotdiff/snapshot.rb', line 69
def resave_cropped_file
resave_base_file(:cropped)
end
|
#resave_fullscreen_file ⇒ Object
73
74
75
|
# File 'lib/dotdiff/snapshot.rb', line 73
def resave_fullscreen_file
resave_base_file(:fullscreen)
end
|