cucumber-screenshot 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Joel Chippindale
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ = Cucumber Screenshot
2
+
3
+ Cucumber Screenshot makes it easy to capture screenshots of the pages generated
4
+ by your Rails application as it runs your Cucumber/Webrat features.
5
+
6
+ It uses WebKit to generate the screenshots and so is only available for OS X.
7
+
8
+ If you want to take screenshots on any other platform then take a look at
9
+ [this example]http://github.com/aslakhellesoy/cucumber/blob/master/examples/watir/features/support/screenshots.rb
10
+ from Cucumber.
11
+
12
+ == Requirements
13
+
14
+ A Rails application with some features written in Cucumber/Webrat.
15
+
16
+ == Install
17
+
18
+ To install the latest release as a gem
19
+
20
+ sudo gem install cucumber-screenshot
21
+
22
+ == Use
23
+
24
+ Create a cucumber_screenshot_env.rb file in the ./features/support/ directory
25
+ in your Rails project and put the following in it.
26
+
27
+ begin
28
+ require 'cucumber_screenshot'
29
+ World(CucumberScreenshot::World)
30
+
31
+ After do |scenario|
32
+ if scenario.failed?
33
+ screenshot
34
+ end
35
+ end
36
+
37
+ AfterStep('@screenshot') do |scenario|
38
+ if screenshot_due?
39
+ screenshot
40
+ end
41
+ end
42
+ rescue Exception => e
43
+ puts "Snapshots not available for this environment. Try installing
44
+ cucumber-screenshot with\n\n gem install cucumber-screenshot\n"
45
+ end
46
+
47
+ Then use the 'rake cucumber' and 'rake cucumber:wip' tasks as per usual.
48
+
49
+ Screenshots will be captured for every step failure and for every step in
50
+ scenarios tagged @screenshot. The screenshots will be saved to a
51
+ ./features/screenshots/ directory in your project.
52
+
53
+ === Capturing a single screenshot
54
+
55
+ If you want to capture a single screenshot rather than every page then add the
56
+ following step to one of your Rails application's step files
57
+
58
+ Then "screenshot" do
59
+ screenshot
60
+ end
61
+
62
+ and then add
63
+
64
+ Then screenshot
65
+
66
+ to your feature file in the place where you want to capture a screenshot of the
67
+ page that your application generated.
68
+
69
+ == TODO
70
+
71
+ - Clean out existing snapshots before each run
72
+ - Add support for tables
73
+ - Add a Rails generator to add the env and step code to a project
74
+
75
+ == License
76
+
77
+ Copyright (c) 2009 Joel Chippindale.
78
+ See MIT-LICENSE.txt in this directory.
@@ -0,0 +1,94 @@
1
+ begin
2
+ require 'spec'
3
+ require 'spec/rake/spectask'
4
+ desc 'Run the cucumber-screenshot specs'
5
+ Spec::Rake::SpecTask.new('spec') do |t|
6
+ t.spec_files = FileList['spec/**/*_spec.rb']
7
+ t.spec_opts = ['--options', 'spec/spec.opts']
8
+ end
9
+ rescue LoadError
10
+ puts 'Rspec not available, install it with: gem install rspec'
11
+ end
12
+
13
+
14
+ require 'rubygems'
15
+ require 'rake/gempackagetask'
16
+ require 'rake/rdoctask'
17
+
18
+ task :default => ['spec']
19
+
20
+ # This builds the actual gem. For details of what all these options
21
+ # mean, and other ones you can add, check the documentation here:
22
+ #
23
+ # http://rubygems.org/read/chapter/20
24
+ #
25
+ spec = Gem::Specification.new do |s|
26
+ # Change these as appropriate
27
+ s.name = 'cucumber-screenshot'
28
+ s.version = '0.3.0'
29
+ s.summary = 'Extension for Cucumber to capture PNG screenshots of your app'
30
+
31
+ s.description = 'Extension for Cucumber (http://cukes.info/) that makes it easy to use Webkit to capture PNG screenshots of your web application during tests'
32
+ s.author = 'Joel Chippindale'
33
+ s.email = 'joel.chippindale@gmail.com'
34
+ s.homepage = 'http://github.com/mocoso/cucumber-screenshot'
35
+
36
+ s.has_rdoc = true
37
+ s.extra_rdoc_files = %w(README.rdoc)
38
+ s.rdoc_options = %w(--main README.rdoc)
39
+
40
+ # Add any extra files to include in the gem
41
+ s.files = %w(cucumber-screenshot.gemspec cucumber-screenshot.tmproj MIT-LICENSE Rakefile README.rdoc) + Dir.glob("{spec,lib/**/*}")
42
+ s.require_paths = ["lib"]
43
+
44
+ # If you want to depend on other gems, add them here, along with any
45
+ # relevant versions
46
+ # s.add_dependency("some_other_gem", "~> 0.1.0")
47
+
48
+ s.add_dependency('cucumber', '>= 0.6.2')
49
+ s.add_dependency('webrat', '>= 0.7.0')
50
+
51
+ # If your tests use any gems, include them here
52
+ s.add_development_dependency('rspec')
53
+
54
+ s.post_install_message = 'To take actual screenshots rather than just snapshots of the HTML returned you will need Mac OS X 10.5 or later with RubyCocoa.
55
+
56
+ You will also need to install the snapurl gem
57
+
58
+ gem install snapurl --version=0.3.0
59
+
60
+ '
61
+
62
+ s.requirements = ['Mac OS X 10.5 or later', 'RubyCocoa']
63
+ end
64
+
65
+ # This task actually builds the gem. We also regenerate a static
66
+ # .gemspec file, which is useful if something (i.e. GitHub) will
67
+ # be automatically building a gem for this project. If you're not
68
+ # using GitHub, edit as appropriate.
69
+ #
70
+ # To publish your gem online, install the 'gemcutter' gem; Read more
71
+ # about that here: http://gemcutter.org/pages/gem_docs
72
+ Rake::GemPackageTask.new(spec) do |pkg|
73
+ pkg.gem_spec = spec
74
+ end
75
+
76
+ desc "Build the gemspec file #{spec.name}.gemspec"
77
+ task :gemspec do
78
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
79
+ File.open(file, "w") {|f| f << spec.to_ruby }
80
+ end
81
+
82
+ task :package => :gemspec
83
+
84
+ # Generate documentation
85
+ Rake::RDocTask.new do |rd|
86
+ rd.main = "README.rdoc"
87
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
88
+ rd.rdoc_dir = "rdoc"
89
+ end
90
+
91
+ desc 'Clear out RDoc and generated packages'
92
+ task :clean => [:clobber_rdoc, :clobber_package] do
93
+ rm "#{spec.name}.gemspec"
94
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{cucumber-screenshot}
5
+ s.version = "0.3.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Joel Chippindale"]
9
+ s.date = %q{2010-04-01}
10
+ s.description = %q{Extension for Cucumber (http://cukes.info/) that makes it easy to use Webkit to capture PNG screenshots of your web application during tests}
11
+ s.email = %q{joel.chippindale@gmail.com}
12
+ s.extra_rdoc_files = ["README.rdoc"]
13
+ s.files = ["cucumber-screenshot.gemspec", "cucumber-screenshot.tmproj", "MIT-LICENSE", "Rakefile", "README.rdoc", "spec", "lib/cucumber_screenshot", "lib/cucumber_screenshot/world.rb", "lib/cucumber_screenshot.rb"]
14
+ s.homepage = %q{http://github.com/mocoso/cucumber-screenshot}
15
+ s.post_install_message = %q{To take actual screenshots rather than just snapshots of the HTML returned you will need Mac OS X 10.5 or later with RubyCocoa.
16
+
17
+ You will also need to install the snapurl gem
18
+
19
+ gem install snapurl --version=0.3.0
20
+
21
+ }
22
+ s.rdoc_options = ["--main", "README.rdoc"]
23
+ s.require_paths = ["lib"]
24
+ s.requirements = ["Mac OS X 10.5 or later", "RubyCocoa"]
25
+ s.rubygems_version = %q{1.3.6}
26
+ s.summary = %q{Extension for Cucumber to capture PNG screenshots of your app}
27
+
28
+ if s.respond_to? :specification_version then
29
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
30
+ s.specification_version = 3
31
+
32
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
33
+ s.add_runtime_dependency(%q<cucumber>, [">= 0.6.2"])
34
+ s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
35
+ s.add_development_dependency(%q<rspec>, [">= 0"])
36
+ else
37
+ s.add_dependency(%q<cucumber>, [">= 0.6.2"])
38
+ s.add_dependency(%q<webrat>, [">= 0.7.0"])
39
+ s.add_dependency(%q<rspec>, [">= 0"])
40
+ end
41
+ else
42
+ s.add_dependency(%q<cucumber>, [">= 0.6.2"])
43
+ s.add_dependency(%q<webrat>, [">= 0.7.0"])
44
+ s.add_dependency(%q<rspec>, [">= 0"])
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>documents</key>
6
+ <array>
7
+ <dict>
8
+ <key>expanded</key>
9
+ <true/>
10
+ <key>name</key>
11
+ <string>cucumber-screenshot</string>
12
+ <key>regexFolderFilter</key>
13
+ <string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
14
+ <key>sourceDirectory</key>
15
+ <string></string>
16
+ </dict>
17
+ </array>
18
+ <key>fileHierarchyDrawerWidth</key>
19
+ <integer>334</integer>
20
+ <key>metaData</key>
21
+ <dict/>
22
+ <key>showFileHierarchyDrawer</key>
23
+ <false/>
24
+ <key>windowFrame</key>
25
+ <string>{{294, 105}, {1519, 1028}}</string>
26
+ </dict>
27
+ </plist>
@@ -0,0 +1,20 @@
1
+ require 'cucumber'
2
+ require 'cucumber/formatter/html'
3
+ require 'webrat'
4
+
5
+ require 'cucumber_screenshot/world'
6
+
7
+ module CucumberScreenshot
8
+ VERSION = '0.3.0'
9
+
10
+ begin
11
+ require 'snapurl'
12
+ SNAPURL_PRESENT = true
13
+ rescue LoadError
14
+ SNAPURL_PRESENT = false
15
+ end
16
+
17
+ def self.snap_url_present?
18
+ SNAPURL_PRESENT
19
+ end
20
+ end
@@ -0,0 +1,63 @@
1
+ module CucumberScreenshot
2
+ module World
3
+
4
+ attr_accessor :response_body_for_last_screenshot, :screenshot_index, :screenshot_directory, :current_feature_segment, :current_scenario_segment
5
+
6
+ def base_screenshot_directory_name
7
+ # TODO: Make this configurable
8
+ # TODO: Make this work for other frameworks e.g. sinatra
9
+ "#{RAILS_ROOT}/features/screenshots"
10
+ end
11
+
12
+ def screenshot(directory_name = base_screenshot_directory_name, file_name = "screenshot-#{(Time.now.to_f * 100).to_i}")
13
+ if current_response_body
14
+ FileUtils.mkdir_p("#{directory_name}/html")
15
+
16
+ html_file_name = "#{directory_name}/html/#{file_name}.html"
17
+ File.open(html_file_name, "w") do |f|
18
+ f.write rewrite_javascript_and_css_and_image_references(current_response_body)
19
+ end
20
+
21
+ if CucumberScreenshot.snap_url_present?
22
+ command = "snapurl file://#{html_file_name} --no-thumbnail --no-clip --filename #{file_name} --output-dir #{directory_name}"
23
+ `#{command}`
24
+ if $? == 0
25
+ embed "#{directory_name}/#{file_name}.png", 'image/png'
26
+ self.response_body_for_last_screenshot = current_response_body
27
+ true
28
+ else
29
+ report_error_running_screenshot_command(command)
30
+ false
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def screenshot_due?
37
+ current_response_body && current_response_body != response_body_for_last_screenshot && !webrat_session.redirect?
38
+ end
39
+
40
+ protected
41
+ def current_response_body
42
+ webrat_session.send(:response) && webrat_session.response_body
43
+ end
44
+
45
+ def rewrite_javascript_and_css_and_image_references(response_html) # :nodoc:
46
+ return response_html unless doc_root
47
+ response_html.gsub(/"\/(javascripts|stylesheets|images)\//, '"' + doc_root + '/\1/')
48
+ end
49
+
50
+ def report_error_running_screenshot_command(command)
51
+ STDERR.puts "
52
+ Unable to make screenshot, to find out what went wrong try the following from the command line
53
+
54
+ #{command}
55
+
56
+ "
57
+ end
58
+
59
+ def doc_root
60
+ File.expand_path(File.join(RAILS_ROOT, 'public'))
61
+ end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-screenshot
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Joel Chippindale
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-01 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: cucumber
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 6
30
+ - 2
31
+ version: 0.6.2
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: webrat
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 7
44
+ - 0
45
+ version: 0.7.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id003
60
+ description: Extension for Cucumber (http://cukes.info/) that makes it easy to use Webkit to capture PNG screenshots of your web application during tests
61
+ email: joel.chippindale@gmail.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - README.rdoc
68
+ files:
69
+ - cucumber-screenshot.gemspec
70
+ - cucumber-screenshot.tmproj
71
+ - MIT-LICENSE
72
+ - Rakefile
73
+ - README.rdoc
74
+ - lib/cucumber_screenshot/world.rb
75
+ - lib/cucumber_screenshot.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/mocoso/cucumber-screenshot
78
+ licenses: []
79
+
80
+ post_install_message: |+
81
+ To take actual screenshots rather than just snapshots of the HTML returned you will need Mac OS X 10.5 or later with RubyCocoa.
82
+
83
+ You will also need to install the snapurl gem
84
+
85
+ gem install snapurl --version=0.3.0
86
+
87
+ rdoc_options:
88
+ - --main
89
+ - README.rdoc
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements:
107
+ - Mac OS X 10.5 or later
108
+ - RubyCocoa
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.6
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Extension for Cucumber to capture PNG screenshots of your app
114
+ test_files: []
115
+