From cc753a10fd4aaa792b9e033ec10cc8335517f36c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 15 Mar 2012 14:20:07 -0400 Subject: [PATCH] keep browser windows open between runs, good for guard --- bin/flowerbox | 4 +++- lib/flowerbox.rb | 9 +++++++++ lib/flowerbox/runner/chrome.rb | 3 +-- lib/flowerbox/runner/selenium.rb | 1 - 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/flowerbox b/bin/flowerbox index 50fb3c7..1ffc87b 100755 --- a/bin/flowerbox +++ b/bin/flowerbox @@ -8,7 +8,9 @@ class Flowerbox::CLI < Thor method_options :pwd => :string, :env_options => nil, :runners => :string, :runner => :string, :verbose_server => false def test(dir = "spec/javascripts", *files) Dir.chdir(pwd) do - exit Flowerbox.run(dir, options.dup.merge(:files => files)) + result = Flowerbox.run(dir, options.dup.merge(:files => files)) + Flowerbox.cleanup! + exit result end end diff --git a/lib/flowerbox.rb b/lib/flowerbox.rb index 071139c..b83ec6a 100644 --- a/lib/flowerbox.rb +++ b/lib/flowerbox.rb @@ -110,6 +110,15 @@ module Flowerbox def run(dir, options = {}) Flowerbox::Run::Test.execute(dir, options) end + + def browsers + @browsers ||= {} + end + + def cleanup! + browsers.values.each(&:close) + @browsers = {} + end end end diff --git a/lib/flowerbox/runner/chrome.rb b/lib/flowerbox/runner/chrome.rb index a39c002..e681f64 100644 --- a/lib/flowerbox/runner/chrome.rb +++ b/lib/flowerbox/runner/chrome.rb @@ -13,8 +13,7 @@ class Flowerbox::Runner::Chrome < Flowerbox::Runner::Selenium end def browser - @browser ||= ::Selenium::WebDriver.for(:chrome) + Flowerbox.browsers[:chrome] ||= ::Selenium::WebDriver.for(:chrome) end end - diff --git a/lib/flowerbox/runner/selenium.rb b/lib/flowerbox/runner/selenium.rb index 4a8c01e..6d67203 100644 --- a/lib/flowerbox/runner/selenium.rb +++ b/lib/flowerbox/runner/selenium.rb @@ -12,7 +12,6 @@ module Flowerbox end def cleanup - @browser.close if @browser end def browser