LoginSignup
18
18

More than 5 years have passed since last update.

Capybara(selenium)でスクリーンショットを取る

Posted at

Capybara(selenium-webdriver)でスクリーンショットを取る

page.driver.browser.save_screenshot "tmp/capybara/screenshot#{Time.now.strftime("%Y%m%d%H%M%S")}.png"

普段はhtmlを出力する
save_and_open_page
で十分な気もする

Capybara 2.0 ではpage.save_screenshot 'screenshot.png'という書き方ができるらしい

参考:Screenshots with Capybara

前からできることは分かっていたが、あまり使いどころがなく使っていなかった。
使ったきっかけはJenkins(on Ubuntu)でseleniumを動かす際に、ブラウザを画面なしで動かすheadless(xvfb)の環境でデバッグが必要になったため。

18
18
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
18
18