系統測試的螢幕擷取畫面輔助器。
方法
實例公開方法
take_failed_screenshot() 連結
如果測試失敗,將擷取瀏覽器中目前頁面的螢幕擷取畫面。
take_failed_screenshot
會在系統測試中斷期間被呼叫。
原始碼:顯示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb, line 53 def take_failed_screenshot return unless failed? && supports_screenshot? && Capybara::Session.instance_created? take_screenshot metadata[:failure_screenshot_path] = relative_image_path if Minitest::Runnable.method_defined?(:metadata) end
take_screenshot(html: false, screenshot: nil) 連結
擷取瀏覽器中目前頁面的螢幕擷取畫面。
take_screenshot
可用於系統測試中的任何點,以截取目前的狀態螢幕畫面。這對於除錯或自動化視覺測試會很有幫助。您可以在每個測試中擷取多個螢幕擷取畫面,以偵查測試期間不同時間點的變更。它們將會以連續字首命名(或對於失敗測試命名為 ‘failed’)
螢幕擷取畫面的預設目錄是 tmp/screenshots
,但您可以使用 Capybara.save_path
設定不同的目錄
您可以使用 html
參數或設定 RAILS_SYSTEM_TESTING_SCREENSHOT_HTML
環境變數,以儲存正在截取螢幕擷取畫面的頁面的 HTML,以便您在截取螢幕擷取畫面時偵測頁面上的元件
您可以使用 screenshot
參數或設定 RAILS_SYSTEM_TESTING_SCREENSHOT
環境變數控制輸出。可能的數值包括:
`inline`
: 使用 iTerm 影像通訊協定顯示終端機中的螢幕擷取畫面 (iterm2.com/documentation-images.html).
`artifact`
: 使用終端機成品格式於終端機中顯示螢幕擷取畫面 (buildkite.github.io/terminal-to-html/inline-images/).
原始碼:顯示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb, line 41 def take_screenshot(html: false, screenshot: nil) showing_html = html || html_from_env? increment_unique save_html if showing_html save_image show display_image(html: showing_html, screenshot_output: screenshot) end