Module: MediawikiSelenium::ScreenshotHelper
- Defined in:
- lib/mediawiki_selenium/helpers/screenshot_helper.rb
Overview
Adds support to Environment for taking screenshots of the current
browser window. If screenshot_failures
is set to true
for the current
environment, one is automatically taken at the end of each failed
test case.
Instance Method Summary collapse
-
#screenshot(browser, name) ⇒ String
Takes a screenshot of the given browser window and returns the path to the saved image.
-
#teardown(info = {}) ⇒ Object
Takes screenshots for failed tests.
Instance Method Details
#screenshot(browser, name) ⇒ String
Takes a screenshot of the given browser window and returns the path to the saved image.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mediawiki_selenium/helpers/screenshot_helper.rb', line 18 def screenshot(browser, name) dir = screenshot_failures_path FileUtils.mkdir_p dir name = name.tr("#{File::SEPARATOR}\000", '-') path = File.join(dir, "#{name}.png") browser.screenshot.save(path) path end |
#teardown(info = {}) ⇒ Object
Takes screenshots for failed tests.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mediawiki_selenium/helpers/screenshot_helper.rb', line 34 def teardown(info = {}) screenshots = [] artifacts = super(info) do |browser| if info[:status] == :failed && screenshot_failures? screenshots << screenshot(browser, info[:name] || 'scenario') end yield browser if block_given? end artifacts.merge(screenshots.each.with_object({}) { |img, arts| arts[img] = 'image/png' }) end |