Permalink
Browse files

Merge pull request #30876 from y-yagi/selenium_chrome_headless

Add headless chrome driver to System Tests
  • Loading branch information...
eileencodes committed Oct 17, 2017
2 parents 262dc91 + ada0585 commit 683ec1012fe9d8616e035b5f581e7c8c1bb781c6
View
@@ -1,3 +1,7 @@
* 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

0 comments on commit 683ec10

Please sign in to comment.