How to take full screen, screenshots after test fails

124 views
Skip to first unread message

NaviHan

unread,
Sep 20, 2018, 7:14:17 AM9/20/18
to Watir General
Hi

I have put this code in the hooks which takes scresnshot when a test fails. The issue is that Im not getting the full browser screen. Its chops off at the bottom

After do |scenario|
 take_screenshot
(@browser, scenario)
end


def 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


Justin Ko

unread,
Sep 20, 2018, 9:23:57 AM9/20/18
to Watir General
Hi Navi,

Selenium only screenshots the content in the viewport. If you want the whole browser, you would need to take multiple screenshots.

There was a gem recently released to do this - https://github.com/samnissen/watir-screenshot-stitch

Though I haven't tried it myself.

Justin

NaviHan

unread,
Sep 20, 2018, 9:33:00 AM9/20/18
to Watir General
Thanks Justin, Let me give it a go..

Sam Nissen

unread,
Sep 20, 2018, 11:20:16 AM9/20/18
to Watir General
Hi Navi -- I created that gem, help maintain it, and would be happy to help you if you run across any issues.

NaviHan

unread,
Sep 20, 2018, 11:24:46 AM9/20/18
to Watir General
Hi Sam

Thanks for reaching out. I will try that out tomorrow from office. Will let you know the outcome :-)


On Thursday, 20 September 2018 21:14:17 UTC+10, NaviHan wrote:

Titus Fortner

unread,
Sep 20, 2018, 12:01:42 PM9/20/18
to Watir General
Hey Sam. Is now a good time to release the update and publish a blog post about it? :)

NaviHan

unread,
Sep 21, 2018, 2:58:53 AM9/21/18
to Watir General
Hi Titus and Sam

This worked like a charm. Such a very usefull gem. Thanks a ton.
I just prepared a wiki for my project. Pasting here in case if this helps.

For capturing full screen images

Use gem https://github.com/samnissen/watir-screenshot-stitch

Include in Gemfile

gem 'watir-screenshot-stitch'
gem "mini_magick"

Run bundle install
Install "ImageMagick" exe on host machine

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

Verify Installation

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. 

Usage
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)

On Thursday, 20 September 2018 21:14:17 UTC+10, NaviHan wrote:

NaviHan

unread,
Sep 21, 2018, 6:37:48 AM9/21/18
to Watir General
Hi Sam

Just found this warning
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


In fact I did try using version 0.7.0 of ImageMagick, but found this issue mentioned in this thread (issue with convert command) --> https://stackoverflow.com/questions/38163849/imagemagick-issue-with-windows-and-convert-function

So I reverted to 6.9

But aren't we supposed to pass browser as mentioned in the previous reply?

Cheers
Navi


On Thursday, 20 September 2018 21:14:17 UTC+10, NaviHan wrote:

Sam Nissen

unread,
Sep 21, 2018, 6:45:12 AM9/21/18
to watir-...@googlegroups.com
Hi Navi — the version there refers to Watir Screenshot Stitch. When we publish version 0.7.0, we will no longer allow you to pass the browser in. This was a hack that we needed, but thanks to the changes Titus has made to Watir, the Screenshot class now knows the browser it was created for.

Sorry that wasn’t clear!
-Sam

--
--
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.

signature.asc

NaviHan

unread,
Sep 24, 2018, 2:13:33 AM9/24/18
to Watir General
Hi Sam

Im getting this weird error when running the script on Jenkins box. Its a machine of AWS. Any clue?
 [
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



On Thursday, 20 September 2018 21:14:17 UTC+10, NaviHan wrote:

NaviHan

unread,
Sep 24, 2018, 4:19:33 AM9/24/18
to Watir General
A more readable format of the error


`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'

On Thursday, 20 September 2018 21:14:17 UTC+10, NaviHan wrote:

NaviHan

unread,
Sep 24, 2018, 11:04:16 AM9/24/18
to Watir General
Hi Sam

Issue resolved. It was basically the issue with PATH variable for Jenkins job.

"convert.exe" is also the name of a windows executable which converts FAT filesystem to NTFS. When you do not specify the full path of an executable

the system first searches the current working directory and then searches the path environment variable, examining each directory from left to right, looking for an executable filename that matches the command name given.

"C:\Windows\System32" is generally present in the beginning of %PATH% variable, causing the Windows convert utility to launch, which fails with "Invalid Parameter" error as expected.

As a workaround, I just modified the order of PATH variable as


SET
"PATH=C:\Program Files\ImageMagick-6.9.10-Q8;%PATH%;C:\Ruby24-x64\bin"


Good God!!!


On Thursday, 20 September 2018 21:14:17 UTC+10, NaviHan wrote:
Reply all
Reply to author
Forward
0 new messages