Class: DotDiff::Snapshot
Constant Summary
collapse
- IMAGE_EXT =
'png'
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.
11
12
13
14
15
16
17
18
19
|
# File 'lib/dotdiff/snapshot.rb', line 11
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_file = opts[:fullscreen_file]
@use_custom_screenshot = opts[:use_custom_screenshot]
end
|
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
7
8
9
|
# File 'lib/dotdiff/snapshot.rb', line 7
def page
@page
end
|
#rootdir ⇒ Object
Returns the value of attribute rootdir.
7
8
9
|
# File 'lib/dotdiff/snapshot.rb', line 7
def rootdir
@rootdir
end
|
#subdir ⇒ Object
Returns the value of attribute subdir.
7
8
9
|
# File 'lib/dotdiff/snapshot.rb', line 7
def subdir
@subdir
end
|
#use_custom_screenshot ⇒ Object
Returns the value of attribute use_custom_screenshot.
7
8
9
|
# File 'lib/dotdiff/snapshot.rb', line 7
def use_custom_screenshot
@use_custom_screenshot
end
|
Instance Method Details
#base_filename(with_extension = true) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/dotdiff/snapshot.rb', line 33
def base_filename(with_extension = true)
filename = File.basename(@base_filename)
extension = File.extname(filename)
rtn_file = @base_filename
if with_extension
rtn_file = "#{@base_filename}.#{IMAGE_EXT}" if extension.empty?
else
rtn_file = @base_filename.sub(extension, '') unless extension.empty?
end
rtn_file
end
|
#basefile ⇒ Object
29
30
31
|
# File 'lib/dotdiff/snapshot.rb', line 29
def basefile
File.join(rootdir, subdir.to_s, base_filename)
end
|
#capture_from_browser(hide_and_show) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/dotdiff/snapshot.rb', line 59
def capture_from_browser(hide_and_show)
return fullscreen_file if use_custom_screenshot
if hide_and_show
element_handler = ElementHandler.new(page)
element_handler.hide
page.save_screenshot(fullscreen_file)
element_handler.show
else
page.save_screenshot(fullscreen_file)
end
end
|
#cropped_file ⇒ Object
25
26
27
|
# File 'lib/dotdiff/snapshot.rb', line 25
def cropped_file
@cropped_file ||= File.join(Dir.tmpdir, subdir, "#{base_filename(false)}_cropped.#{IMAGE_EXT}")
end
|
#diff_file ⇒ Object
55
56
57
|
# File 'lib/dotdiff/snapshot.rb', line 55
def diff_file
File.join(failure_path, "#{base_filename(false)}.diff.#{IMAGE_EXT}")
end
|
#fullscreen_file ⇒ Object
21
22
23
|
# File 'lib/dotdiff/snapshot.rb', line 21
def fullscreen_file
@fullscreen_file ||= File.join(Dir.tmpdir, subdir, base_filename)
end
|
#new_file ⇒ Object
51
52
53
|
# File 'lib/dotdiff/snapshot.rb', line 51
def new_file
File.join(failure_path, "#{base_filename(false)}.new.#{IMAGE_EXT}")
end
|
#resave_cropped_file ⇒ Object
73
74
75
|
# File 'lib/dotdiff/snapshot.rb', line 73
def resave_cropped_file
resave_base_file(:cropped)
end
|
#resave_fullscreen_file ⇒ Object
77
78
79
|
# File 'lib/dotdiff/snapshot.rb', line 77
def resave_fullscreen_file
resave_base_file(:fullscreen)
end
|