Class: Watirmark::Screenshot::Current

Inherits:
Object
  • Object
show all
Defined in:
lib/watirmark/screenshot.rb

Direct Known Subclasses

Master

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snapshotwidth = Watirmark::Configuration.instance.snapshotwidth) ⇒ Current

Returns a new instance of Current.



75
76
77
78
79
80
# File 'lib/watirmark/screenshot.rb', line 75

def initialize(snapshotwidth=Watirmark::Configuration.instance.snapshotwidth)
  get_screen_size
  FileUtils.mkdir_p('reports/screenshots')
  take_screen_shot(snapshotwidth)
  revert_window_size
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



73
74
75
# File 'lib/watirmark/screenshot.rb', line 73

def filename
  @filename
end

#screenheightObject

Returns the value of attribute screenheight.



73
74
75
# File 'lib/watirmark/screenshot.rb', line 73

def screenheight
  @screenheight
end

#screenwidthObject

Returns the value of attribute screenwidth.



73
74
75
# File 'lib/watirmark/screenshot.rb', line 73

def screenwidth
  @screenwidth
end

Instance Method Details

#get_screen_sizeObject



96
97
98
99
100
# File 'lib/watirmark/screenshot.rb', line 96

def get_screen_size
  size = Page.browser.window.size
  @screenwidth = size.width
  @screenheight = size.height
end

#md5Object



88
89
90
# File 'lib/watirmark/screenshot.rb', line 88

def md5
  Digest::MD5.hexdigest(File.read(@filename))
end

#revert_window_sizeObject



102
103
104
# File 'lib/watirmark/screenshot.rb', line 102

def revert_window_size
  Page.browser.window.resize_to(@screenwidth, @screenheight)
end

#take_screen_shot(snapshotwidth) ⇒ Object



82
83
84
85
86
# File 'lib/watirmark/screenshot.rb', line 82

def take_screen_shot(snapshotwidth)
  update_window_size(snapshotwidth)
  @filename = "reports/screenshots/#{UUID.new.generate(:compact)}.png"
  Page.browser.screenshot.save @filename
end

#update_window_size(width) ⇒ Object



92
93
94
# File 'lib/watirmark/screenshot.rb', line 92

def update_window_size(width)
  Page.browser.window.resize_to(width, Watirmark::Configuration.instance.snapshotheight)
end