Skip to content

Instantly share code, notes, and snippets.

@tetsuyainfra
Last active December 31, 2017 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tetsuyainfra/49c7ea6928a5ada7ab52f8c4347e250f to your computer and use it in GitHub Desktop.
Save tetsuyainfra/49c7ea6928a5ada7ab52f8c4347e250f to your computer and use it in GitHub Desktop.
Rails5.1 SystemTest with Chromium Headless mode ref: https://qiita.com/tetsuyainfra/items/b504510ea9110765e07c
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: %w(no-sandbox headless disable-gpu window-size=1280x800)
}
)
driven_by :selenium, using: :chrome,
options: { desired_capabilities: capabilities }
end
sudo apt install chromedriver
sudo apt install fonts-ipafont-gothic fonts-ipafont-mincho
# コアダンプ
$ chromium --screenshot http://google.com/
$ chromium --headles --screenshot http://google.com/
$ chromium --headles --disable-gpu --screenshot http://google.com/
# 結局これでおk
$ chromium --no-sandbox --headless --disable-gpu --screenshot http://google.com/
# コアダンプ
$ chromium --screenshot http://google.com/
$ chromium --headles --screenshot http://google.com/
$ chromium --headles --disable-gpu --screenshot http://google.com/
# 結局これでおk
$ chromium --no-sandbox --headless --disable-gpu --screenshot http://google.com/
puts Rails.env
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
# binary: "/usr/bin/chromium", # 必要なし
args: %w(no-sandbox headless disable-gpu window-size=1280x800)
}
)
driver = Selenium::WebDriver.for :chrome,
desired_capabilities: capabilities
driver.navigate.to "http://google.com"
element = driver.find_element(name: 'q')
element.send_keys "Hello WebDriver!"
element.submit
puts driver.title
driver.quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment