Sha256: 99c12e622db136d15a9d18f3aef331c7e78700b0f82e4a305b3efe9399d7e534

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

module Daddy
  module Cucumber
    module Capture
      feature_dir = 'feature'
      ARGV.each_with_index do |arg, i|
        if arg == '-r'
          feature_dir = ARGV[i + 1]
          break
        end
      end
      REPORT_DIR = File.join(feature_dir, 'reports')
      IMAGE_DIR = 'images'
      FileUtils.mkdir_p("#{REPORT_DIR}/#{IMAGE_DIR}")
    
      @@_screen_count = 0
      @@_images = []
    
      def capture(options = {})
        pause
        return if ENV['FORMAT'] == 'junit'

        url = Rack::Utils.unescape(current_url)
    
        @@_screen_count += 1

        image = "#{IMAGE_DIR}/#{@@_screen_count}.png"
        page.driver.save_screenshot("#{REPORT_DIR}/#{image}", :full => true)

        if options[:flash]
          puts "<img class=\"screenshot\" src=\"#{image}\" alt=\"#{url}\"/>"
        else
          @@_images << "<img class=\"screenshot\" src=\"#{image}\" alt=\"#{url}\"/>"
        end
      end

      def resize_window(width, height)
        case Capybara.current_driver
        when :poltergeist
          Capybara.current_session.driver.resize(width, height)
        when :selenium
          Capybara.current_session.driver.browser.manage.window.resize_to(width, height)
        when :webkit
          # TODO
        end
      end

      def flash_image_tags
        if @@_images.size > 0
          puts @@_images.join("\n")
          @@_images.clear
        end
      end

    end
  end
end

World(Daddy::Cucumber::Capture)

AfterStep do |step|
  flash_image_tags
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
daddy-0.3.26 lib/daddy/cucumber/helpers/capture.rb
daddy-0.3.25 lib/daddy/cucumber/helpers/capture.rb
daddy-0.3.24 lib/daddy/cucumber/helpers/capture.rb