-
-
Save kkganesan/1490793 to your computer and use it in GitHub Desktop.
Save screenshots when using Selenium, Capybara and Ubuntu server
This file contains hidden or 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