aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2017-12-07 14:44:05 -0500
committerGitHub <noreply@github.com>2017-12-07 14:44:05 -0500
commite8c3b58cb6e1dd204dd586f1cf6c3e482fb80abe (patch)
tree67bd58d296bb59a9fa8d8cf285a753bf9c066589
parent6a8ce7416d6615a13ee5c4b9f6bcd91cc5adef4d (diff)
parent82b974813b28748e5affcff1d8c4ad60ab2971be (diff)
downloadrails-e8c3b58cb6e1dd204dd586f1cf6c3e482fb80abe.tar.gz
rails-e8c3b58cb6e1dd204dd586f1cf6c3e482fb80abe.tar.bz2
rails-e8c3b58cb6e1dd204dd586f1cf6c3e482fb80abe.zip
Merge pull request #31365 from bogdanvlviv/add-headless_firefox-driver-to-system_tests
Add headless firefox driver to System Tests
-rw-r--r--actionpack/CHANGELOG.md4
-rw-r--r--actionpack/lib/action_dispatch/system_test_case.rb8
-rw-r--r--actionpack/lib/action_dispatch/system_testing/driver.rb13
-rw-r--r--actionpack/test/abstract_unit.rb4
-rw-r--r--actionpack/test/dispatch/system_testing/driver_test.rb8
-rw-r--r--actionpack/test/dispatch/system_testing/system_test_case_test.rb6
-rw-r--r--guides/source/testing.md3
7 files changed, 42 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index d120d15770..753dd8589a 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Add headless firefox support to System Tests.
+
+ *bogdanvlviv*
+
* Changed the default system test screenshot output from `inline` to `simple`.
`inline` works well for iTerm2 but not everyone uses iTerm2. Some terminals like
diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb
index 7246e01cff..99d0c06751 100644
--- a/actionpack/lib/action_dispatch/system_test_case.rb
+++ b/actionpack/lib/action_dispatch/system_test_case.rb
@@ -121,11 +121,15 @@ module ActionDispatch
#
# driven_by :poltergeist
#
- # driven_by :selenium, using: :firefox
+ # driven_by :selenium, screen_size: [800, 800]
+ #
+ # driven_by :selenium, using: :chrome
#
# driven_by :selenium, using: :headless_chrome
#
- # driven_by :selenium, screen_size: [800, 800]
+ # driven_by :selenium, using: :firefox
+ #
+ # driven_by :selenium, using: :headless_firefox
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)
end
diff --git a/actionpack/lib/action_dispatch/system_testing/driver.rb b/actionpack/lib/action_dispatch/system_testing/driver.rb
index 2687772b4b..280989a146 100644
--- a/actionpack/lib/action_dispatch/system_testing/driver.rb
+++ b/actionpack/lib/action_dispatch/system_testing/driver.rb
@@ -38,13 +38,24 @@ module ActionDispatch
browser_options.args << "--disable-gpu"
@options.merge(options: browser_options)
+ elsif @browser == :headless_firefox
+ browser_options = Selenium::WebDriver::Firefox::Options.new
+ browser_options.args << "-headless"
+
+ @options.merge(options: browser_options)
else
@options
end
end
def browser
- @browser == :headless_chrome ? :chrome : @browser
+ if @browser == :headless_chrome
+ :chrome
+ elsif @browser == :headless_firefox
+ :firefox
+ else
+ @browser
+ end
end
def register_selenium(app)
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 5262e85a28..55ad9c245e 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -453,3 +453,7 @@ end
class DrivenBySeleniumWithHeadlessChrome < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome
end
+
+class DrivenBySeleniumWithHeadlessFirefox < ActionDispatch::SystemTestCase
+ driven_by :selenium, using: :headless_firefox
+end
diff --git a/actionpack/test/dispatch/system_testing/driver_test.rb b/actionpack/test/dispatch/system_testing/driver_test.rb
index 75feae6fe0..fcdaf7fb4c 100644
--- a/actionpack/test/dispatch/system_testing/driver_test.rb
+++ b/actionpack/test/dispatch/system_testing/driver_test.rb
@@ -25,6 +25,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 firefox" do
+ driver = ActionDispatch::SystemTesting::Driver.new(:selenium, using: :headless_firefox, screen_size: [1400, 1400], options: { url: "http://example.com/wd/hub" })
+ assert_equal :selenium, driver.instance_variable_get(:@name)
+ assert_equal :headless_firefox, 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)
diff --git a/actionpack/test/dispatch/system_testing/system_test_case_test.rb b/actionpack/test/dispatch/system_testing/system_test_case_test.rb
index c6a6aef92b..b078a5abc5 100644
--- a/actionpack/test/dispatch/system_testing/system_test_case_test.rb
+++ b/actionpack/test/dispatch/system_testing/system_test_case_test.rb
@@ -28,6 +28,12 @@ class SetDriverToSeleniumHeadlessChromeTest < DrivenBySeleniumWithHeadlessChrome
end
end
+class SetDriverToSeleniumHeadlessFirefoxTest < DrivenBySeleniumWithHeadlessFirefox
+ test "uses selenium headless firefox" 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
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 9692f50b6e..f28c4c224a 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -673,7 +673,8 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
end
```
-If you want to use a headless browser, you could use Headless Chrome by adding `headless_chrome` in the `:using` argument.
+If you want to use a headless browser, you could use Headless Chrome or Headless Firefox by adding
+`headless_chrome` or `headless_firefox` in the `:using` argument.
```ruby
require "test_helper"