On 8/2/11 9:17 AM, Jarmo Pertman wrote:
#send_keys accepts now only strings. It accepted accidentally array of
VK_ codes in some previous version of RAutomation. Use better
solutions to capture screenshots. win32screenshot gem can help you
there https://rubygems.org/gems/win32screenshot and
https://github.com/jarmo/win32screenshot

Just `gem install win32screenshot` and start hacking :)

Jarmo
Thanks, Jarmo, I switched, and it helped to shrink code quite a bit.

One non-critical annoyance was mini-magick chocking on every space in the filename. Nobody likes spaces in filenames, of course :)
It was not critical; screenshots were still taken:

Magick: unable to open image `C:/Users/DK/AppData/Local/Temp/Scenario\': No such file or directory @ error/blob.c/OpenBlob
/2584.
Magick: no decode delegate for this image format `C:/Users/DK/AppData/Local/Temp/Scenario\' @ error/constitute.c/ReadImage
/532.
Magick: unable to open image `'Delete\': Invalid argument @ error/blob.c/OpenBlob/2584. Magick: no decode delegate for this image format `'Delete\' @ error/constitute.c/ReadImage/532. Magick: unable to open image `cart'\': Invalid argument @ error/blob.c/OpenBlob/2584. Magick: no decode delegate for this image format `cart'\' @ error/constitute.c/ReadImage/532. Magick: unable to open image `failed\': Invalid argument @ error/blob.c/OpenBlob/2584. Magick: no decode delegate for this image format `failed\' @ error/constitute.c/ReadImage/532. Magick: unable to open image `@\': Invalid argument @ error/blob.c/OpenBlob/2584. Magick: no decode delegate for this image format `@\' @ error/constitute.c/ReadImage/532. Magick: unable to open image `2011-08-02\': Invalid argument @ error/blob.c/OpenBlob/2584. Magick: no decode delegate for this image format `2011-08-02\' @ error/constitute.c/ReadImage/532. Magick: unable to open image `121909.png': No such file or directory @ error/blob.c/OpenBlob/2584. Magick: unable to open file `121909.png' @ error/png.c/ReadPNGImage/3084.
       (MiniMagick::Invalid)
C:/Ruby/lib/ruby/gems/1.9.1/gems/mini_magick-3.2.1/lib/mini_magick.rb:388:in `run' C:/Ruby/lib/ruby/gems/1.9.1/gems/mini_magick-3.2.1/lib/mini_magick.rb:374:in `run_command' C:/Ruby/lib/ruby/gems/1.9.1/gems/mini_magick-3.2.1/lib/mini_magick.rb:293:in `write' C:/Ruby/lib/ruby/gems/1.9.1/gems/win32screenshot-1.0.4/lib/win32/screenshot/image.rb:38:in `write' M:/Users/DK/Projects/RAP/WorkingCopy/features/support/env.rb:158:in `After'

After I got rid of all spaces, it worked great.

The code of Cucumber hook if anybody needs it is the following. This works for both watir-webdriver and watir:

require 'tmpdir'

# run after the last step of each scenario, even when there are failing, undefined, pending or skipped steps.
After do |scenario|
  if scenario.failed?
    # Take screenshot
screenshot_filename = File.join(Dir.tmpdir, "Scenario_'" + scenario.name.gsub(/[\/\\?*:|<> ]/, "_") +
        "'_failed_@_" + Time.now.strftime("%Y-%m-%d_%H%M%S")) + ".png"
    if defined?(browser.driver)
      browser.driver.save_screenshot(screenshot_filename)
      #embed("screenshot.png", "image/png")
    elsif ENV["BROWSER"] == 'IE'
      require 'win32/screenshot'
      browser.maximize
      # Take a screenshot of the window with the specified handle
Win32::Screenshot::Take.of(:window, :hwnd => browser.hwnd).write(screenshot_filename)
    end
 end
end

--
DK
AIM: DKroot1, Skype: DKroot

--
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

Reply via email to