Sha256: dfbba15694347b0361e3db0480500f00651b6c8a59060e783e35c6e96d05096d

Contents?: true

Size: 1.31 KB

Versions: 23

Compression:

Stored size: 1.31 KB

Contents

module Daddy
  module Cucumber
    module Capture
      REPORT_DIR = File.join('features', '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

23 entries across 23 versions & 1 rubygems

Version Path
daddy-0.3.23 lib/daddy/cucumber/capture.rb
daddy-0.3.22 lib/daddy/cucumber/capture.rb
daddy-0.3.21 lib/daddy/cucumber/capture.rb
daddy-0.3.20 lib/daddy/cucumber/capture.rb
daddy-0.3.19 lib/daddy/cucumber/capture.rb
daddy-0.3.18 lib/daddy/cucumber/capture.rb
daddy-0.3.17 lib/daddy/cucumber/capture.rb
daddy-0.3.16 lib/daddy/cucumber/capture.rb
daddy-0.3.15 lib/daddy/cucumber/capture.rb
daddy-0.3.14 lib/daddy/cucumber/capture.rb
daddy-0.3.13 lib/daddy/cucumber/capture.rb
daddy-0.3.12 lib/daddy/cucumber/capture.rb
daddy-0.3.11 lib/daddy/cucumber/capture.rb
daddy-0.3.10 lib/daddy/cucumber/capture.rb
daddy-0.3.9 lib/daddy/cucumber/capture.rb
daddy-0.3.8 lib/daddy/cucumber/capture.rb
daddy-0.3.7 lib/daddy/cucumber/capture.rb
daddy-0.3.6 lib/daddy/cucumber/capture.rb
daddy-0.3.4 lib/daddy/cucumber/capture.rb
daddy-0.3.3 lib/daddy/cucumber/capture.rb