LoginSignup
16
17

More than 5 years have passed since last update.

テストがコケた時にスクリーンショットを取る

Posted at

前置き

お仕事先のPJで大量にスクリーンショットを撮っているテストを見て、本当にこれ必要なのかな?
スクリーンショットってテストがコケた時だけ必要なんじゃね?と思い、RSpecのテストがコケた時にスクリーンショットを撮るようやってみました。

やったこと

specフォルダ直下にあるspec_helper.rbに対して、以下の様に書いてみます。

spec_helper.rb
RSpec.configure do |config|
  config.after do |example|
    if example.metadata[:type] == :feature and example.exception
        page.save_screenshot 'screenshot/テスト失敗時スクリーンショット.png'
    end 
  end 
end

簡単!
1つのfeatureを回し終わった後にエラーがあればCapybaraでスクリーンショットを撮る感じですね。

16
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17