From 01a26e581f977b08de072ce3c40b9adee2ba1c10 Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Tue, 3 Apr 2018 21:58:39 -0400 Subject: Implement a way to add browser capabilities: * There is currently no way to define specific browser capabilities since our SystemTest driver override the `option` key [Ref](https://github.com/rails/rails/blob/a07d0680787ced3c04b362fa7a238c918211ac70/actionpack/lib/action_dispatch/system_testing/driver.rb#L35) This option key is used internally by selenium to add custom capabilities on the browser. Depending on the Browser, some option are allowed to be passed inside a hash, the driver takes care of setting whatever you passed on the driver option. An example [here](https://github.com/rails/rails/blob/a07d0680787ced3c04b362fa7a238c918211ac70/actionpack/lib/action_dispatch/system_testing/driver.rb#L35) where you are allowed to pass args such as `--no-sandbox` etc However this behavior was only meant for backward compatibility and as you can see it's deprecated. The non-deprecated behavior is to create a `::Option` object containing all the capabilities we want. This is what we [currently do](https://github.com/rails/rails/blob/a07d0680787ced3c04b362fa7a238c918211ac70/actionpack/lib/action_dispatch/system_testing/browser.rb#L34-L36) when chrome or firefox are in headless mode. This PR allows to pass a block when calling `driven_by`, the block will be pased a `::Option` instance. You can modify this object the way you want by adding any capabilities. The option object will be then passed to selenium. ```ruby driven_by :selenium, using: :chrome do |driver_option| driver_option.add_argument('--no-sandbox') driver_option.add_emulation(device: 'iphone 4') end ``` --- .../lib/action_dispatch/system_testing/browser.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_dispatch/system_testing/browser.rb') diff --git a/actionpack/lib/action_dispatch/system_testing/browser.rb b/actionpack/lib/action_dispatch/system_testing/browser.rb index 1b0bce6b9e..9361b165ff 100644 --- a/actionpack/lib/action_dispatch/system_testing/browser.rb +++ b/actionpack/lib/action_dispatch/system_testing/browser.rb @@ -29,20 +29,27 @@ module ActionDispatch end end + def driver_option + @option ||= case type + when :chrome + Selenium::WebDriver::Chrome::Options.new + when :firefox + Selenium::WebDriver::Firefox::Options.new + end + end + private def headless_chrome_browser_options - options = Selenium::WebDriver::Chrome::Options.new - options.args << "--headless" - options.args << "--disable-gpu" if Gem.win_platform? + driver_option.args << "--headless" + driver_option.args << "--disable-gpu" if Gem.win_platform? - options + driver_option end def headless_firefox_browser_options - options = Selenium::WebDriver::Firefox::Options.new - options.args << "-headless" + driver_option.args << "-headless" - options + driver_option end end end -- cgit v1.2.3 From 5936bd9a201a2c1a3730d9c857f0908959505d2b Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Wed, 4 Apr 2018 13:29:50 -0400 Subject: driver_option -> driver_options --- actionpack/lib/action_dispatch/system_testing/browser.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_dispatch/system_testing/browser.rb') diff --git a/actionpack/lib/action_dispatch/system_testing/browser.rb b/actionpack/lib/action_dispatch/system_testing/browser.rb index 9361b165ff..74585062aa 100644 --- a/actionpack/lib/action_dispatch/system_testing/browser.rb +++ b/actionpack/lib/action_dispatch/system_testing/browser.rb @@ -29,7 +29,7 @@ module ActionDispatch end end - def driver_option + def driver_options @option ||= case type when :chrome Selenium::WebDriver::Chrome::Options.new @@ -43,13 +43,13 @@ module ActionDispatch driver_option.args << "--headless" driver_option.args << "--disable-gpu" if Gem.win_platform? - driver_option + driver_options end def headless_firefox_browser_options - driver_option.args << "-headless" + driver_options.args << "-headless" - driver_option + driver_options end end end -- cgit v1.2.3 From 1a4f61307286702205fd32b3aa62c26c21c9cce3 Mon Sep 17 00:00:00 2001 From: Eileen Uchitelle Date: Tue, 29 Jan 2019 09:01:58 -0500 Subject: Rename methods and update docs This is a minor update to the named methods for the following: - s/desired_capabilities/capabilities - s/driver_options/capabilities Since they are all the same thing we should keep the name the same throughout the feature. Updated docs to match / be a little bit clearer Also updated the Gemfile for selenium-webdriver. --- actionpack/lib/action_dispatch/system_testing/browser.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_dispatch/system_testing/browser.rb') diff --git a/actionpack/lib/action_dispatch/system_testing/browser.rb b/actionpack/lib/action_dispatch/system_testing/browser.rb index 74585062aa..f691bd5fe5 100644 --- a/actionpack/lib/action_dispatch/system_testing/browser.rb +++ b/actionpack/lib/action_dispatch/system_testing/browser.rb @@ -29,7 +29,7 @@ module ActionDispatch end end - def driver_options + def capabilities @option ||= case type when :chrome Selenium::WebDriver::Chrome::Options.new @@ -40,16 +40,16 @@ module ActionDispatch private def headless_chrome_browser_options - driver_option.args << "--headless" - driver_option.args << "--disable-gpu" if Gem.win_platform? + capability.args << "--headless" + capability.args << "--disable-gpu" if Gem.win_platform? - driver_options + capabilities end def headless_firefox_browser_options - driver_options.args << "-headless" + capabilities.args << "-headless" - driver_options + capabilities end end end -- cgit v1.2.3