capybara-screenshot 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,15 @@
1
+ 24 November 2011
2
+ ----------------
3
+
4
+ Added support for:
5
+
6
+ * More platforms (Poltergeist)
7
+ * Removed Rails dependencies (bug)
8
+ * Added screenshot capability for Selenium
9
+ * Added support for embed for HTML reports
10
+
11
+ Thanks to [https://github.com/rb2k](https://github.com/rb2k) for 2 [great commits](https://github.com/mattheworiordan/capybara-screenshot/pull/4)
12
+
1
13
  16 November 2011
2
14
  ----------------
3
15
 
@@ -1,17 +1,20 @@
1
1
  # do nothing if Cucumber is not being used
2
2
  if defined?(Cucumber::RbSupport::RbDsl)
3
3
  require 'capybara/cucumber'
4
- require 'capybara-screenshot/world'
5
-
6
- module Capybara
7
- module Screenshot
8
- end
9
- end
10
-
11
- World(Capybara::Screenshot::World)
4
+ require 'capybara-screenshot/cucumber'
12
5
 
13
6
  After do |scenario|
14
- screen_shot_and_save_page if scenario.failed?
7
+ if scenario.failed?
8
+ screenshot_path = Capybara::Screenshot::Cucumber.screen_shot_and_save_page[:image]
9
+ # Trying to embed the screenshot into our output."
10
+ if File.exist?(screenshot_path)
11
+ require "base64"
12
+ #encode the image into it's base64 representation
13
+ encoded_img = Base64.encode64(IO.read(screenshot_path))
14
+ #this will embed the image in the HTML report, embed() is defined in cucumber
15
+ embed("data:image/png;base64,#{encoded_img}", 'image/png', "Screenshot of the error")
16
+ end
17
+ end
15
18
  end
16
19
  end
17
20
 
@@ -30,6 +33,6 @@ end
30
33
  begin
31
34
  require 'minitest/unit'
32
35
  require 'capybara-screenshot/minitest'
33
- rescue
36
+ rescue LoadError
34
37
  # mini test not available
35
38
  end
@@ -2,8 +2,8 @@ require 'capybara-screenshot/saver'
2
2
 
3
3
  module Capybara
4
4
  module Screenshot
5
- module World
6
- def screen_shot_and_save_page
5
+ module Cucumber
6
+ def self.screen_shot_and_save_page
7
7
  Capybara::Screenshot::Saver.screen_shot_and_save_page Capybara, Capybara.body
8
8
  end
9
9
  end
@@ -1,22 +1,49 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- class Saver
3
+ module Saver
4
4
  def self.screen_shot_and_save_page(capybara, body)
5
- unless capybara.current_path.blank?
5
+ #Our default return values
6
+ html_path = nil
7
+ image_path = nil
8
+
9
+ if capybara.current_path.to_s.empty?
10
+ puts "Current path is empty, can't take a screenshot"
11
+ else
6
12
  require 'capybara/util/save_and_open_page'
7
- path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
8
- capybara.save_page body, "#{path}.html"
9
- if capybara.page.driver.respond_to?(:render)
10
- path = if defined?(Rails)
11
- Rails.root.join "#{capybara.save_and_open_page_path}#{path}.png"
12
- else
13
- # Sinatra support, untested
14
- File.join settings.root "#{capybara.save_and_open_page_path}#{path}.png"
13
+ file_base_name = "#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
14
+ #will save to the capybara.save_and_open_page_path
15
+ html_path = "{capybara.save_and_open_page_path}#{file_base_name}.html"
16
+ capybara.save_page(body, "#{file_base_name}.html")
17
+
18
+ #where should we save the screenshot to
19
+ if defined?(Rails)
20
+ screenshot_path = Rails.root.join "#{capybara.save_and_open_page_path}/#{file_base_name}.png"
21
+ elsif defined?(Sinatra)
22
+ # Sinatra support, untested
23
+ screenshot_path = File.join(settings.root, "#{capybara.save_and_open_page_path}/#{file_base_name}.png")
24
+ else
25
+ #screenshot_path = File.join(capybara.save_and_open_page_path.to_s, "#{file_base_name}.png")
26
+ screenshot_path = "#{file_base_name}.png"
27
+ end
28
+
29
+ #We try to figure out how to call the screenshot method on the current driver
30
+ case capybara.current_driver
31
+ when :poltergeist
32
+ capybara.page.driver.render(screenshot_path, :full => true)
33
+ when :selenium
34
+ capybara.page.driver.browser.save_screenshot(screenshot_path)
35
+ else
36
+ #For other drivers that support a plain .render call and only expect the path as a parameter
37
+ #This includes e.g. capybara-webkit
38
+ if capybara.page.driver.respond_to?(:render)
39
+ capybara.page.driver.render(screenshot_path)
15
40
  end
16
- capybara.page.driver.render path
17
41
  end
18
42
  end
43
+ #we return the path to the html and the screenshot
44
+ {:html => html_path, :image => screenshot_path}
19
45
  end
20
46
  end
21
47
  end
22
- end
48
+ end
49
+
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-screenshot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew O'Riordan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-21 00:00:00 +00:00
18
+ date: 2011-11-24 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -81,11 +81,11 @@ files:
81
81
  - Rakefile
82
82
  - capybara-screenshot.gemspec
83
83
  - lib/capybara-screenshot.rb
84
+ - lib/capybara-screenshot/cucumber.rb
84
85
  - lib/capybara-screenshot/minitest.rb
85
86
  - lib/capybara-screenshot/rspec.rb
86
87
  - lib/capybara-screenshot/saver.rb
87
88
  - lib/capybara-screenshot/version.rb
88
- - lib/capybara-screenshot/world.rb
89
89
  has_rdoc: true
90
90
  homepage: http://github.com/mattheworiordan/capybara-screenshot
91
91
  licenses: []