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

Change subject: Ignore HEADLESS and KEEP_BROWSER_OPEN for phantomjs
......................................................................


Ignore HEADLESS and KEEP_BROWSER_OPEN for phantomjs

The former will make tests fail, the latter will spawn a lot of
phantomjs processes killing your machine. That's probably a bug in the
phantomjs driver, since it should kill the phantomjs processes itself if
it does not intend to reuse them.

Includes test cases for `Environment#teardown`.

Change-Id: I9861a29525684ba9a984a15dd1c14643c7a41e67
---
M lib/mediawiki_selenium/environment.rb
M lib/mediawiki_selenium/support/hooks.rb
M spec/environment_spec.rb
3 files changed, 38 insertions(+), 3 deletions(-)

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



diff --git a/lib/mediawiki_selenium/environment.rb 
b/lib/mediawiki_selenium/environment.rb
index a70ee84..75f64b3 100644
--- a/lib/mediawiki_selenium/environment.rb
+++ b/lib/mediawiki_selenium/environment.rb
@@ -334,10 +334,10 @@
     # @yieldparam browser [Watir::Browser] Browser object, before it's closed.
     #
     def teardown(status = :passed)
-      @_factory_cache.each do |_, factory|
+      @_factory_cache.each do |(_, browser_name), factory|
         factory.each do |browser|
           yield browser if block_given?
-          browser.close unless keep_browser_open?
+          browser.close unless keep_browser_open? && browser_name != :phantomjs
         end
 
         factory.teardown(self, status)
diff --git a/lib/mediawiki_selenium/support/hooks.rb 
b/lib/mediawiki_selenium/support/hooks.rb
index 8b6056c..4328ee1 100644
--- a/lib/mediawiki_selenium/support/hooks.rb
+++ b/lib/mediawiki_selenium/support/hooks.rb
@@ -8,7 +8,7 @@
   config.formats << ['MediawikiSelenium::WarningsFormatter', io] if 
pretty_format
 
   # Initiate headless mode
-  if ENV['HEADLESS'] == 'true'
+  if ENV['HEADLESS'] == 'true' && ENV['BROWSER'] != 'phantomjs'
     require 'headless'
 
     headless_options = {}.tap do |options|
diff --git a/spec/environment_spec.rb b/spec/environment_spec.rb
index a2ab2c6..a04caa1 100644
--- a/spec/environment_spec.rb
+++ b/spec/environment_spec.rb
@@ -332,6 +332,41 @@
       end
     end
 
+    describe '#teardown' do
+      subject { env.teardown(status) }
+
+      let(:status) { :passed }
+      let(:browser_instance) { double(Watir::Browser) }
+
+      before do
+        expect(env.browser_factory).to receive(:each) { |&blk| 
[browser_instance].each(&blk) }
+        expect(env.browser_factory).to receive(:teardown).with(env, status)
+      end
+
+      it 'yields the given block and closes the browser' do
+        expect(browser_instance).to receive(:close)
+        expect { |blk| env.teardown(status, &blk) }.to 
yield_with_args(browser_instance)
+      end
+
+      context 'when keep_browser_open is set to "true"' do
+        let(:config) { { keep_browser_open: 'true' } }
+
+        it 'does not close the browser' do
+          expect(browser_instance).not_to receive(:close)
+          subject
+        end
+
+        context 'but browser is "phantomjs"' do
+          let(:config) { { browser: 'phantomjs', keep_browser_open: 'true' } }
+
+          it 'closes the browser anyway' do
+            expect(browser_instance).to receive(:close)
+            subject
+          end
+        end
+      end
+    end
+
     describe '#user' do
       subject { env.user(id) }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9861a29525684ba9a984a15dd1c14643c7a41e67
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/selenium
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Dduvall <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[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