Module: Howdoc::Screenshot
- Defined in:
- lib/howdoc/screenshot.rb
Overview
Guides are illustrated, and an illustration is only useful if every picture in the set has the same proportions. The browser window is therefore sized deliberately before each capture rather than left wherever the test put it.
Class Method Summary collapse
-
.capture(page, path:, height:, full_page: false, marker: nil, marker_mode: :pointer) ⇒ Object
The marker is drawn after the window has been sized and not before: a resize lays the page out again, and an arrow placed by the old layout would point at where the button used to be.
- .full_page_height(page) ⇒ Object
Class Method Details
.capture(page, path:, height:, full_page: false, marker: nil, marker_mode: :pointer) ⇒ Object
The marker is drawn after the window has been sized and not before: a resize lays the page out again, and an arrow placed by the old layout would point at where the button used to be.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/howdoc/screenshot.rb', line 13 def capture(page, path:, height:, full_page: false, marker: nil, marker_mode: :pointer) FileUtils.mkdir_p(File.dirname(path)) width, current_height = page.current_window.size target = full_page ? full_page_height(page) : height page.current_window.resize_to(width, target) unless target == current_height Marker.around(page, marker, mode: marker_mode) do page.save_screenshot(path, full: true) end path end |
.full_page_height(page) ⇒ Object
28 29 30 |
# File 'lib/howdoc/screenshot.rb', line 28 def full_page_height(page) page.execute_script('return document.body.scrollHeight;').to_i + 30 end |