[RUBY] [WATIR] Screenshots with Cucumber/Watir on Windows 7 with IE9

298 views
Skip to first unread message

Ryan Crossan

unread,
Nov 9, 2012, 10:22:47 PM11/9/12
to cu...@googlegroups.com
I am trying to set up ability to take screen shots. I'm not concerned if they embed or are saved to a directory.

I have googled several suggestions, but none have worked.

Right now I am trying to use example from http://watirmelon.com/tag/cucumber/

I am using Ruby 1.9, Watir 4.0.2, and Cucumber 1.2.1

Windows 7 with IE 9

I have a hooks.rb file with the following

After do |scenario|
  if scenario.failed?
    Dir::mkdir('screenshots') if not File.directory?('screenshots')
    screenshot = "./screenshots/FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
    Browser::BROWSER.driver.save_screenshot(screenshot)
    embed screenshot, 'image/png'
  end
end

start of my ruby file is

require 'watir'
include Watir

ie = Watir::Browser.new

any suggestions to making this work?

Or if better suggestion to including other gems in my script and using something I am totally open. I just would like to get screenshots to work, specifically on failed features.

Thanks in advance

Matt Wynne

unread,
Nov 10, 2012, 2:55:05 AM11/10/12
to cu...@googlegroups.com
On 10 Nov 2012, at 03:22, Ryan Crossan wrote:

I am trying to set up ability to take screen shots. I'm not concerned if they embed or are saved to a directory.

I have googled several suggestions, but none have worked.

Right now I am trying to use example from http://watirmelon.com/tag/cucumber/

I am using Ruby 1.9, Watir 4.0.2, and Cucumber 1.2.1

Windows 7 with IE 9

I have a hooks.rb file with the following

After do |scenario|
  if scenario.failed?
    Dir::mkdir('screenshots') if not File.directory?('screenshots')
    screenshot = "./screenshots/FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
    Browser::BROWSER.driver.save_screenshot(screenshot)
    embed screenshot, 'image/png'
  end
end

start of my ruby file is

require 'watir'
include Watir

ie = Watir::Browser.new

any suggestions to making this work?

Can you explain what doesn't work? Do you see an error message?


Or if better suggestion to including other gems in my script and using something I am totally open. I just would like to get screenshots to work, specifically on failed features.

Thanks in advance


--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
 
 


Ryan Crossan

unread,
Nov 10, 2012, 3:52:15 PM11/10/12
to cu...@googlegroups.com
Yes,

The script finishes and when I check my html log, I see this after the failed feature.

uninitialized constant Watir::Browser::BROWSER (NameError)

C:/Users/Darkhudson/Desktop/DEMO/watirDemo/workspace/features/support/hooks.rb:5:in `After'

3    Dir::mkdir('screenshots') if not File.directory?('screenshots')
4    screenshot = "./screenshots/FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
5    Browser::BROWSER.driver.save_screenshot(screenshot)
6    embed screenshot, 'image/png'
7  end

Matt Wynne

unread,
Nov 10, 2012, 4:57:20 PM11/10/12
to cu...@googlegroups.com
On 10 Nov 2012, at 20:52, Ryan Crossan wrote:

Yes,

The script finishes and when I check my html log, I see this after the failed feature.

uninitialized constant Watir::Browser::BROWSER (NameError)

C:/Users/Darkhudson/Desktop/DEMO/watirDemo/workspace/features/support/hooks.rb:5:in `After'

3    Dir::mkdir('screenshots') if not File.directory?('screenshots')
4    screenshot = "./screenshots/FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
5    Browser::BROWSER.driver.save_screenshot(screenshot)
6    embed screenshot, 'image/png'
7  end

Sorry, I don't know Watir well enough to be able to tell what you need to do here. I'd try asking on the Watir support forums, unless anyone else can help?



On Friday, November 9, 2012 7:22:47 PM UTC-8, Ryan Crossan wrote:
I am trying to set up ability to take screen shots. I'm not concerned if they embed or are saved to a directory.

I have googled several suggestions, but none have worked.

Right now I am trying to use example from http://watirmelon.com/tag/cucumber/

I am using Ruby 1.9, Watir 4.0.2, and Cucumber 1.2.1

Windows 7 with IE 9

I have a hooks.rb file with the following

After do |scenario|
  if scenario.failed?
    Dir::mkdir('screenshots') if not File.directory?('screenshots')
    screenshot = "./screenshots/FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
    Browser::BROWSER.driver.save_screenshot(screenshot)
    embed screenshot, 'image/png'
  end
end

start of my ruby file is

require 'watir'
include Watir

ie = Watir::Browser.new

any suggestions to making this work?

Or if better suggestion to including other gems in my script and using something I am totally open. I just would like to get screenshots to work, specifically on failed features.

Thanks in advance


--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
 
 

Chuck van der Linden

unread,
Nov 11, 2012, 3:50:11 PM11/11/12
to cu...@googlegroups.com


On Saturday, November 10, 2012 12:52:16 PM UTC-8, Ryan Crossan wrote:
Yes,

The script finishes and when I check my html log, I see this after the failed feature.

uninitialized constant Watir::Browser::BROWSER (NameError)

C:/Users/Darkhudson/Desktop/DEMO/watirDemo/workspace/features/support/hooks.rb:5:in `After'

3    Dir::mkdir('screenshots') if not File.directory?('screenshots')
4    screenshot = "./screenshots/FAILED_#{scenario.name.gsub(' ','_').gsub(/[^0-9A-Za-z_]/, '')}.png"
5    Browser::BROWSER.driver.save_screenshot(screenshot)
6    embed screenshot, 'image/png'
7  end

I think you are trying to use an approach that is out of date.  If you are using Watir-webdriver it has a .screenshot method.

You can look at the watirspec tests https://github.com/watir/watirspec/blob/master/screenshot_spec.rb for examples of how to use the method.

If you need more help than that, you're best off asking in the "Watir General" google group, or (especially if we get into showing code samples etc) on StackOverflow and just using the 'watir' or 'watir-webdriver' tag on your SO question.
Reply all
Reply to author
Forward
0 new messages