After do |scenario|
take_screenshot(@browser, scenario)
enddef take_screenshot(browser, scenario)
time = Time.now.strftime("%Y-%m-%d_%H%M")
if scenario.failed?
scenario_name = scenario.name.gsub(/[^\w\-]/, ' ')
screenshot_path = "#{scenario_name}" + "_failure_" + time
@browser.screenshot.save("./screenshots/#{screenshot_path}.png")
end
end
By the way my before hooks looks like this.Before do|scenario|
ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
@browser.goto "https://www.sandbox.paypal.com"
@browser.cookies.clear
@browser.goto "https://portal-sandbox.afterpay.com"
@browser.cookies.clear
@browser.goto "https://i-pay.co.za"
@browser.cookies.clear
@browser.goto("ci.XXX.com/")
@browser.window.maximize
@browser.driver.manage.timeouts.implicit_wait = 0
@browser.cookies.clear
@browser.driver.manage.window.maximize
PageObject.default_element_wait=(10)
PageObject.javascript_framework = :jquery
end #before scenario
Use gem https://github.com/samnissen/watir-screenshot-stitch
gem 'watir-screenshot-stitch'
gem "mini_magick"
The host machine should have "ImageMagick" intsalled
The windows exe can be downloaded from https://www.imagemagick.org/download/binaries/
Recommeneded:- ImageMagick-6.9.10-11-Q8-x64-dll
Select “Command Prompt” from the Windows Start menu. Within the window type
convert logo: logo.miff
imdisplay logo.miff
and the ImageMagick logo should be displayed in a window.
browser = Watir::Browser.new :chrome, options: {args: args}
opts = {:page_height_limit => 5000}
screenshot_path = "#{scenario_name}" + "_failure_" + time
@browser.screenshot.save_stitch(screenshot_path, browser, opts)
2018-09-21 20:32:17 WARN Watir Screenshot Stitch [DEPRECATION] Passing the browser is deprecated and will no longer work in version 0.7.0 /lib/watir-screenshot-stitch.rb:31
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
In short: search before you ask, be nice.
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/Cp8TbjnWpn8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[31m features/Loyalty_Memberships-AU.feature:189:in `And the perks overlay popup closes' [0m 2018-09-24 16:11:50 WARN Watir Screenshot Stitch [DEPRECATION] Passing the browser is deprecated and will no longer work in version 0.7.0 /lib/watir-screenshot-stitch.rb:31 [31m `convert -size 1920x1957 xc:white ./screenshots/Button Function Checkout with an email address without a website account without PERKS membership hit Continue As Guest _failure_2018-09-24_1611.png` failed with error: [0m [31m Invalid Parameter - 1920x1957 [0m [31m (MiniMagick::Error) [0m [31m ./features/support/hooks.rb:86:in `take_screenshot' [0m [31m ./features/support/hooks.rb:71:in `After' [0m [36mScenario Failed ! [0m
`convert -size 1920x1957 xc:white ./screenshots/Button Function Checkout with an email address without a website account without PERKS membership hit Continue As Guest _failure_2018-09-24_1712.png` failed with error: Invalid Parameter - 1920x1957 (MiniMagick::Error) ./features/support/hooks.rb:86:in `take_screenshot' ./features/support/hooks.rb:71:in `After'
SET "PATH=C:\Program Files\ImageMagick-6.9.10-Q8;%PATH%;C:\Ruby24-x64\bin"