提交 683ec101 编写于 作者: E Eileen M. Uchitelle 提交者: GitHub

Merge pull request #30876 from y-yagi/selenium_chrome_headless

Add headless chrome driver to System Tests
* Add headless chrome support to System Tests.
*Yuji Yaginuma*
* Add ability to enable Early Hints for HTTP/2
If supported by the server, and enabled in Puma this allows H2 Early Hints to be used.
......
......@@ -121,6 +121,8 @@ def self.start_application # :nodoc:
#
# driven_by :selenium, using: :firefox
#
# driven_by :selenium, using: :headless_chrome
#
# driven_by :selenium, screen_size: [800, 800]
def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400], options: {})
self.driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size, options: options)
......
......@@ -31,8 +31,24 @@ def register
end
end
def browser_options
if @browser == :headless_chrome
browser_options = Selenium::WebDriver::Chrome::Options.new
browser_options.args << "--headless"
browser_options.args << "--disable-gpu"
@options.merge(options: browser_options)
else
@options
end
end
def browser
@browser == :headless_chrome ? :chrome : @browser
end
def register_selenium(app)
Capybara::Selenium::Driver.new(app, { browser: @browser }.merge(@options)).tap do |driver|
Capybara::Selenium::Driver.new(app, { browser: browser }.merge(browser_options)).tap do |driver|
driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
end
end
......
......@@ -449,3 +449,7 @@ class DrivenByRackTest < ActionDispatch::SystemTestCase
class DrivenBySeleniumWithChrome < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome
end
class DrivenBySeleniumWithHeadlessChrome < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome
end
......@@ -17,6 +17,14 @@ class DriverTest < ActiveSupport::TestCase
assert_equal ({ url: "http://example.com/wd/hub" }), driver.instance_variable_get(:@options)
end
test "initializing the driver with a headless chrome" do
driver = ActionDispatch::SystemTesting::Driver.new(:selenium, using: :headless_chrome, screen_size: [1400, 1400], options: { url: "http://example.com/wd/hub" })
assert_equal :selenium, driver.instance_variable_get(:@name)
assert_equal :headless_chrome, driver.instance_variable_get(:@browser)
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
assert_equal ({ url: "http://example.com/wd/hub" }), driver.instance_variable_get(:@options)
end
test "initializing the driver with a poltergeist" do
driver = ActionDispatch::SystemTesting::Driver.new(:poltergeist, screen_size: [1400, 1400], options: { js_errors: false })
assert_equal :poltergeist, driver.instance_variable_get(:@name)
......
......@@ -22,6 +22,12 @@ class SetDriverToSeleniumTest < DrivenBySeleniumWithChrome
end
end
class SetDriverToSeleniumHeadlessChromeTest < DrivenBySeleniumWithHeadlessChrome
test "uses selenium headless chrome" do
assert_equal :selenium, Capybara.current_driver
end
end
class SetHostTest < DrivenByRackTest
test "sets default host" do
assert_equal "http://127.0.0.1", Capybara.app_host
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册