Dduvall has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/201492

Change subject: Browser proxy support for Firefox/Chrome/Phantomjs
......................................................................

Browser proxy support for Firefox/Chrome/Phantomjs

Implemented configuration bindings for `:browser_http_proxy` in the
browser factories for Firefox, Chrome, and Phantomjs.

Bug: T71725
Change-Id: If1053d1e49715519287687839a0879e13f6e4785
---
M lib/mediawiki_selenium/browser_factory/chrome.rb
M lib/mediawiki_selenium/browser_factory/firefox.rb
M lib/mediawiki_selenium/browser_factory/phantomjs.rb
M spec/browser_factory/chrome_spec.rb
M spec/browser_factory/firefox_spec.rb
M spec/browser_factory/phantomjs_spec.rb
6 files changed, 55 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/selenium 
refs/changes/92/201492/1

diff --git a/lib/mediawiki_selenium/browser_factory/chrome.rb 
b/lib/mediawiki_selenium/browser_factory/chrome.rb
index c92a0e3..7b0113d 100644
--- a/lib/mediawiki_selenium/browser_factory/chrome.rb
+++ b/lib/mediawiki_selenium/browser_factory/chrome.rb
@@ -3,12 +3,17 @@
     # Constructs new Chrome browser instances. The following configuration is
     # supported.
     #
+    #  - browser_http_proxy
     #  - browser_language
     #  - browser_user_agent
     #
     # @see Base
     #
     class Chrome < Base
+      bind(:browser_http_proxy) do |http_proxy, options|
+        options[:args] << "--proxy-server=#{http_proxy}"
+      end
+
       bind(:browser_language) do |language, options|
         options[:prefs]['intl.accept_languages'] = language
       end
diff --git a/lib/mediawiki_selenium/browser_factory/firefox.rb 
b/lib/mediawiki_selenium/browser_factory/firefox.rb
index e84f56b..c9e827b 100644
--- a/lib/mediawiki_selenium/browser_factory/firefox.rb
+++ b/lib/mediawiki_selenium/browser_factory/firefox.rb
@@ -3,6 +3,7 @@
     # Constructs new Firefox browser instances. The following configuration is
     # supported.
     #
+    #  - browser_http_proxy
     #  - browser_language
     #  - browser_timeout
     #  - browser_user_agent
@@ -10,6 +11,10 @@
     # @see Base
     #
     class Firefox < Base
+      bind(:browser_http_proxy) do |http_proxy, options|
+        options[:profile].proxy = Selenium::WebDriver::Proxy.new(http: 
http_proxy, ssl: http_proxy)
+      end
+
       bind(:browser_timeout) do |timeout, options|
         timeout = timeout.to_i
         options[:profile]['dom.max_script_run_time'] = timeout
diff --git a/lib/mediawiki_selenium/browser_factory/phantomjs.rb 
b/lib/mediawiki_selenium/browser_factory/phantomjs.rb
index c3119c6..87b63be 100644
--- a/lib/mediawiki_selenium/browser_factory/phantomjs.rb
+++ b/lib/mediawiki_selenium/browser_factory/phantomjs.rb
@@ -3,12 +3,17 @@
     # Constructs new Phantomjs browser instances. The following configuration 
is
     # supported.
     #
+    #  - browser_http_proxy
     #  - browser_language
     #  - browser_user_agent
     #
     # @see Base
     #
     class Phantomjs < Base
+      bind(:browser_http_proxy) do |http_proxy, options|
+        options[:desired_capabilities]['phantomjs.cli.args'] << 
"--proxy=#{http_proxy}"
+      end
+
       bind(:browser_language) do |language, options|
         
options[:desired_capabilities]['phantomjs.page.customHeaders.Accept-Language'] 
= language
       end
@@ -16,6 +21,14 @@
       bind(:browser_user_agent) do |user_agent, options|
         options[:desired_capabilities]['phantomjs.page.settings.userAgent'] = 
user_agent
       end
+
+      protected
+
+      def default_browser_options
+        super.tap do |options|
+          options[:desired_capabilities]['phantomjs.cli.args'] = []
+        end
+      end
     end
   end
 end
diff --git a/spec/browser_factory/chrome_spec.rb 
b/spec/browser_factory/chrome_spec.rb
index f00d869..232b1c4 100644
--- a/spec/browser_factory/chrome_spec.rb
+++ b/spec/browser_factory/chrome_spec.rb
@@ -16,6 +16,14 @@
     describe '#browser_options' do
       subject { factory.browser_options(config) }
 
+      context 'given a browser proxy' do
+        let(:config) { { browser_http_proxy: 'proxy.example:8080' } }
+
+        it 'includes it as --proxy-server in the chrome arguments' do
+          expect(subject[:args]).to 
include('--proxy-server=proxy.example:8080')
+        end
+      end
+
       context 'given a custom browser_language' do
         let(:config) { { browser_language: 'eo' } }
 
diff --git a/spec/browser_factory/firefox_spec.rb 
b/spec/browser_factory/firefox_spec.rb
index bc14521..6cc21f8 100644
--- a/spec/browser_factory/firefox_spec.rb
+++ b/spec/browser_factory/firefox_spec.rb
@@ -22,6 +22,21 @@
         expect(Selenium::WebDriver::Firefox::Profile).to 
receive(:new).and_return(profile)
       end
 
+      context 'given a browser proxy' do
+        let(:config) { { browser_http_proxy: 'proxy.example:8080' } }
+
+        it 'sets up the profile to use a proxy for both http and https' do
+          selenium_proxy = double('Selenium::WebDriver::Proxy')
+
+          expect(Selenium::WebDriver::Proxy).to receive(:new).
+            with(http: 'proxy.example:8080', ssl: 'proxy.example:8080').
+            and_return(selenium_proxy)
+          expect(profile).to receive(:proxy=).with(selenium_proxy)
+
+          subject
+        end
+      end
+
       context 'given a custom browser_timeout' do
         let(:config) { { browser_timeout: '30' } }
 
diff --git a/spec/browser_factory/phantomjs_spec.rb 
b/spec/browser_factory/phantomjs_spec.rb
index b9e8fd1..ecfe47c 100644
--- a/spec/browser_factory/phantomjs_spec.rb
+++ b/spec/browser_factory/phantomjs_spec.rb
@@ -16,6 +16,15 @@
     describe '#browser_options' do
       subject { factory.browser_options(config) }
 
+      context 'given a browser proxy' do
+        let(:config) { { browser_http_proxy: 'proxy.example:8080' } }
+
+        it 'includes it as --proxy in the cli arguments' do
+          capabilities = subject[:desired_capabilities]
+          expect(capabilities['phantomjs.cli.args']).to 
include('--proxy=proxy.example:8080')
+        end
+      end
+
       context 'given a custom browser_language' do
         let(:config) { { browser_language: 'eo' } }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If1053d1e49715519287687839a0879e13f6e4785
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/selenium
Gerrit-Branch: master
Gerrit-Owner: Dduvall <[email protected]>

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

Reply via email to