Created
May 18, 2011 02:06
-
-
Save tommeier/977863 to your computer and use it in GitHub Desktop.
Save screenshots when using Selenium, Capybara and Ubuntu server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#WIP | |
#spec/spec_helper.rb | |
RSpec.configure do |config| | |
#Only for selenium based tested filtered with :js => true on tests | |
#eg: describe "Some test", :js => true do | |
# end | |
config.around(:each, :js => true) do |example| | |
Capybara.current_driver = :selenium | |
result = example.run | |
unless result.blank? || result == true | |
require 'selenium-webdriver' #>= 0.2 | |
#Example failed | |
images_root = File.join(Rails.root, 'tmp') | |
FileUtils.mkdir_p(images_root) unless File.exists?(images_root) | |
file_name = "#{File.basename(example.metadata[:example_group][:file_path]).to_s.underscore.gsub('.','_')}" | |
file_name += "_line_#{example.metadata[:example_group][:line_number]}.png" | |
page.driver.browser.save_screenshot(File.join(images_root, file_name)) | |
end | |
Capybara.use_default_driver | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also - If anyone else gets caught out by the recent issue with shared connections on Active Record (eg. missing data, only when you load on the selenium example) : Add this to your your spec helper (thanks José)
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
Forces all threads to share the same connection. This works on
Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection