jenkins-bot has submitted this change and it was merged.

Change subject: Allow explicit configuration overrides at runtime
......................................................................


Allow explicit configuration overrides at runtime

It's sometimes necessary to set up specific browser configuration at
runtime. While this kind of configuration override can be achieved via
`BrowserFactory::Base#configure`, this is a much simplier method that
requires no knowledge of the underlying WebDriver capabilities.

Bug: T73531
Change-Id: Ia9d4f5dc487785732a837000d02e80b9ac6bfe32
---
M lib/mediawiki_selenium/browser_factory/base.rb
M spec/browser_factory/base_spec.rb
2 files changed, 36 insertions(+), 0 deletions(-)

Approvals:
  Hashar: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/mediawiki_selenium/browser_factory/base.rb 
b/lib/mediawiki_selenium/browser_factory/base.rb
index 784ab20..6946d0f 100644
--- a/lib/mediawiki_selenium/browser_factory/base.rb
+++ b/lib/mediawiki_selenium/browser_factory/base.rb
@@ -71,6 +71,7 @@
         @browser_name = browser_name
         @bindings = {}
         @browser_cache = {}
+        @overrides = {}
       end
 
       # Returns a unique set of all the binding keys.
@@ -146,6 +147,8 @@
       # @return [Hash]
       #
       def browser_options(config)
+        config = config.merge(@overrides)
+
         options = default_browser_options.tap do |default_options|
           bindings.each do |(names, bindings_for_option)|
             bindings_for_option.each do |binding|
@@ -183,6 +186,15 @@
         new_browser(browser_options(config))
       end
 
+      # Always use the given configuration when setting up a new browser,
+      # regardless of what has been previously configured.
+      #
+      # @param config [Hash] Configuration overrides.
+      #
+      def override(config)
+        @overrides.merge!(config)
+      end
+
       # Executes additional teardown tasks.
       #
       # @param env [Environment] Environment.
diff --git a/spec/browser_factory/base_spec.rb 
b/spec/browser_factory/base_spec.rb
index 53e5ca9..18d4308 100644
--- a/spec/browser_factory/base_spec.rb
+++ b/spec/browser_factory/base_spec.rb
@@ -211,5 +211,29 @@
         end
       end
     end
+
+    describe '#override' do
+      subject { factory.override(overrides) }
+
+      before do
+        allow(Selenium::WebDriver::Remote::Capabilities).to 
receive(browser_name)
+      end
+
+      it 'always uses the given configuration when setting up a new browser' do
+        # Set up a binding that will accept :foo configuration
+        @foo = nil
+        factory.configure(:foo) { |foo| @foo = foo }
+
+        # Override with config { foo: 'y' }
+        factory.override(foo: 'y')
+
+        # Invoke the binding with `browser_options` and config { foo: 'x' }
+        factory.browser_options(foo: 'x')
+
+        # The configuration hook should have been invoked with the overriden
+        # value
+        expect(@foo).to eq('y')
+      end
+    end
   end
 end

-- 
To view, visit https://gerrit.wikimedia.org/r/216866
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia9d4f5dc487785732a837000d02e80b9ac6bfe32
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/selenium
Gerrit-Branch: master
Gerrit-Owner: Dduvall <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Zfilipin <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to