LoginSignup
1
0

More than 5 years have passed since last update.

Rails5のsystem testでheadless chromeを使っているときにJavaScriptのログを見る方法

Posted at

以下のように追加のオプションを与えると見ることができます。

test/application_system_test_case.rb
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  caps = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs: { browser: 'ALL' })
  driven_by :selenium, using: :headless_chrome, screen_size: [1920, 1080], options: { desired_capabilities: caps }
end
test/system/something_test.rb
require "application_system_test_case.rb"

class SomethingTest < ApplicationSystemTestCase
  test "display javascript logging" do
    visit("/")
    click_button("Submit")
    pp page.driver.browser.manage.logs.get(:browser)
  end
end

ログを出力するようにすると、テストが少し遅くなるっぽいので必要なときだけ出すようにするのがよさそうです。

参考

1
0
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
1
0