module Selenium
  module WebDriver

    #
    # @private
    #

    module DriverExtensions
      module TakesScreenshot

        def save_screenshot(png_path)
          File.open(png_path, 'w') { |f| f << screenshot_as(:png) }
        end

        def screenshot_as(format)
          case format
          when :base64
            bridge.getScreenshot
          when :png
            bridge.getScreenshot.unpack("m")[0]
          else
            raise Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
          end
        end

      end # TakesScreenshot
    end # DriverExtensions
  end # WebDriver
end # Selenium
module Selenium
  module WebDriver

    #
    # @private
    #

    module DriverExtensions
      module TakesScreenshot

        def save_screenshot(png_path)
          File.open(png_path, 'wb') { |f| f << screenshot_as(:png) }
        end

        def screenshot_as(format)
          case format
          when :base64
            bridge.getScreenshot
          when :png
            bridge.getScreenshot.unpack("m")[0]
          else
            raise Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
          end
        end

      end # TakesScreenshot
    end # DriverExtensions
  end # WebDriver
end # Selenium

Use "wb" mode string when saving screenshots (needed on Windows).
JariBakken: Use "wb" mode string when saving screenshots (needed on Windows).

git-svn-id: aa1aa1384423cb28c2b1e29129bb3a91de1d9196@9686 07704840-8298-11de-bf8c-fd130f914ac9
